【问题标题】:Using add_filter - Based on category and role使用 add_filter - 基于类别和角色
【发布时间】:2014-01-08 09:39:18
【问题描述】:

当帖子发布时,我可以成功使用“add_filter”将帖子状态更改为“待处理”。

function publish_as_pending( $data , $postarr ) {  

  $data['post_status'] = 'pending';   

  return $data;

}

add_filter('wp_insert_post_data' , 'publish_as_pending' , '99', 2); 

如何将其更改为仅在何时过滤;

a) 帖子类别 ID 为 1

b) 发布的用户是角色“贡献者”。

【问题讨论】:

    标签: php wordpress-theming wordpress


    【解决方案1】:
    Add This Function on Function.php
    
    function filter_handler( $data , $postarr ){
        if($postarr['post_category']):
            foreach( $postarr['post_category'] as $category_id ) {
                 if ($category_id ==1 || current_user_can('contributor')){
                     $data['post_status'] = 'pending';   
                     return $data;
                 }
            }
        endif;    
        return $data;
    
    }
    add_filter( 'wp_insert_post_data', 'filter_handler', '99', 2 );
    

    moreinfo to Go.

    【讨论】:

    • 如果我将 OR 换成 AND 那么这应该是完美的。谢谢!
    猜你喜欢
    • 2020-09-24
    • 1970-01-01
    • 2019-11-12
    • 2020-06-22
    • 2013-09-28
    • 2019-08-11
    • 1970-01-01
    • 1970-01-01
    • 2020-12-17
    相关资源
    最近更新 更多