Jetpack Publicize: Sharing only on Twitter for a category

こ雲淡風輕ζ 提交于 2019-12-23 03:01:51

问题


On my current project I have three post categories (Column, Pickup and News) and use Jetpack Publicize to share any new post on both Facebook and Twitter.

For the "News" category, I'd like to only publicize on Twitter (so somehow deactivating Facebook sharing for this category exclusively).

I have been looking at the Jetpack documentation and adjusted their recommended code:

add_filter( 'wpas_submit_post?', 'news_twitter_submit_post', 10, 4 );
function news_twitter_submit_post( $ret, $post_id, $name, $connection ) {

    // $categories = get_the_terms( $post_id, 'category' );
    $categories = wp_get_post_categories( $post->slug );
    if ( 'facebook' == $name ) {
        if ( is_array( $categories ) )
            $categories = wp_list_pluck( $categories, 'slug' );
        if ( !empty( $categories ) &&  in_array( 'news', $categories ) ){
            $ret = false;
          }
    }
    return $ret; }

Except, the post still is getting published on Facebook.

I have also been looking at the publicize_should_publicize_published_post hook but can't get it to work.

Any way I could achieve this?


回答1:


So I played a little bit more with Jetpack then decided to switch to another plugin.

Some notes:

  • I played a little bit with publicize_should_publicize_published_post and it's basically a big ON/OFF switch for the whole Publicize plugin. Can't get it to turn off only one channel (Facebook)

  • No matter how I expressed the if-else conditions, Facebook posting still went through, eventhough I did check the output of the function was correct.

Still interested in knowing if anyone has a clean solution for that problem, but let's close the question.



来源:https://stackoverflow.com/questions/48435992/jetpack-publicize-sharing-only-on-twitter-for-a-category

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!