Support » Plugin: Jetpack - WP Security, Backup, Speed, & Growth » I need a proper example for excluding a category with publicize!

  • Aimee

    (@greatdanemaniac)


    Hi!
    I was wondering if somebody could help me solve this thing. I need to exclude a category from being shared with Publicize, and the example below is NOT working. Found this on a french site.

    add_filter( 'wpas_submit_post?', 'vipx_wpas_submit_post', 10, 4 );
    function vipx_wpas_submit_post( $ret, $post_id, $name, $connection ) {
    
        $categories = get_the_terms( $post_id, 'category' );
            if ( is_array( $categories ) )
                $categories = wp_list_pluck( $categories, 'slug' );
    
            if ( ! in_array( 'le-nom-de-votre-categorie-a-exclure', $categories ) )
                $ret = false;
    
        return $ret;
    }

    Is there a simpler way to make this work? I’d like to have something extremely simple like this:

    add_filter ('wpas_submit_post?', 'ame_exclude_category');
    function ame_exclude_category() {
    
    if (in_category('excluded');
    
    return false
    
    }

    I am well aware that my simple example probably has flaws (it did not work either when I tried it). I am not a programmer nor do I know a lot about php. I can understand code, but the more basic code I can use to get things done – the better.

    Thanks in advanced!

    https://wporg.ibadboy.net/plugins/jetpack/

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic πŸš€

    This seems to work for me:

    add_filter( 'wpas_submit_post?', 'vipx_wpas_submit_post', 10, 4 );
    function vipx_wpas_submit_post( $ret, $post_id, $name, $connection ) {
    
    	$categories = get_the_terms( $post_id, 'category' );
    
    	if ( is_array( $categories ) ) {
    		$categories = wp_list_pluck( $categories, 'slug' );
    	}
    
    	if ( empty( $categories ) ) {
    		return;
    	}
    
    	if ( in_array( 'category-slug', $categories ) ) {
    		$ret = false;
    	}
    
    	return $ret;
    }
    Thread Starter Aimee

    (@greatdanemaniac)

    Thanks. I’ll try that and see if it works for me. I’ll get back later to tell you how it went.

    Thread Starter Aimee

    (@greatdanemaniac)

    Nope, did not work for me. All it did was to prevent the checkboxes in the post meta box to be seen and checked. The post was published anyway. Did I do something wrong? Please, give me a more specific example or explanation to the code snippet.

    Here’s the image of what happened: http://i.imgur.com/ANSkPR4.png

    Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic πŸš€

    Does saving your draft before to publish it change anything?

    Thread Starter Aimee

    (@greatdanemaniac)

    No, it does not. Tried that with one of the posts.

    Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic πŸš€

    Alright, thanks for testing. We’ll take another look and run some tests, and I’ll get back to you when we can address the issue.

    Thread Starter Aimee

    (@greatdanemaniac)

    You’re welcome!

    Thread Starter Aimee

    (@greatdanemaniac)

    Any luck with fixing this? I just tried the code again and the posts are still being publicized and sent to social networks.

    Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic πŸš€

    We still haven’t fixed the issue, but I’ll post here as soon as we do!

    I’m also interested in this! πŸ™‚

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘I need a proper example for excluding a category with publicize!’ is closed to new replies.