Do not trigger Publicize if the post uses the do-not-publicize category in Jetpack

Do not trigger Publicize if the post uses the do-not-publicize category in Jetpack on child sites.

Snippet Type

Execute on Child Sites

Snippet

function jeherve_control_publicize_for_categories( $should_publicize, $post ) {
    // Return early if we don't have a post yet (it hasn't been saved as a draft)
    if ( ! $post ) {
        return $should_publicize;
    }
  
    // Get list of categories for our post.
    $categories = get_the_category( $post->ID );
     
    if ( is_array( $categories ) && ! empty( $categories ) ) {
        foreach( $categories as $category ) {
            if ( 'do-not-publicize' === $category->slug ) {
                return false;
            }
        }
    }
  
    return $should_publicize;
}
add_filter( 'publicize_should_publicize_published_post', 'jeherve_control_publicize_for_categories', 10, 2 );
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.