publishpress / PublishPress-Planner

PublishPress Planner has all the tools you need to manage WordPress content, including an editorial calendar to plan content. You can create custom status and notifications for content updates.
https://publishpress.com/publishpress
Other
47 stars 20 forks source link

Add new filter to abort/prevent notification based on notification or post id/data #1723

Closed olatechpro closed 1 month ago

olatechpro commented 1 month ago

Add new filter to abort/prevent notification based on notification or post id/data.

Sample Usage:

add_action( 'publishpress_notifications_schedule_notification', 'conditionally_abort_pp_notification', 10, 2 );
add_action( 'publishpress_notifications_send_notification', 'conditionally_abort_pp_notification', 10, 2 );
function conditionally_abort_pp_notification($send_notification, $workflow) {
    if ($workflow) {
        //This is is the notification ID. This can be used to limit the check to specific notification
        $workflow_id = $workflow->workflow_post->ID;
        //This is the current post id for which the notification is been sent/scheduled for.
        $post_id = $workflow->event_args['params']['post_id'];

        // check if post has specific meta with specific value
        $post_meta_value = get_post_meta($post_id, 'research', true);

        if ($post_meta_value !== 'AAA') {
            // don't send the notification if research meta key value is not equals AAA
            $send_notification = false;
        }
    }
    return $send_notification;
}