【问题标题】:Limit wordpress user access to certain post category in admin area限制 wordpress 用户访问管理区域中的某些帖子类别
【发布时间】:2016-05-07 14:56:22
【问题描述】:

我想限制用户在 Wordpress 后端的访问权限,使该用户只能(读、写)访问一个类别的帖子。用户甚至不能在后端阅读其他类别的帖子。

我怎样才能实现这一点(最好是通过向 functions.php 添加一些代码) - 并且没有任何性能影响(例如页面加载)?

我基本上尝试在它过时之前实现这个插件的功能: https://wordpress.org/plugins/restrict-categories/

“限制类别是一个插件,允许您选择用户可以在帖子编辑屏幕中查看、添加和编辑的类别。 此插件允许您根据用户角色和用户名限制访问。”

【问题讨论】:

    标签: php wordpress wordpress-theming


    【解决方案1】:

    如果您不介意使用最新的插件,那么这个插件会满足您的所有要求,并且会定期更新,并且有超过 40,000 次有效安装。

    用户访问管理器

    https://wordpress.org/plugins/user-access-manager/

    【讨论】:

    • 谢谢,杰米。已经找到了这个 - 但是,这会根据需要增加更多的复杂性,并且与我已经使用的其他插件重叠。因此,我的 functions.php 的简单代码 sn-p 将是理想的。
    • 嗨,Alex,看看这个指南3.7designs.co/blog/2014/08/… 这是一个关于创建自定义用户类型和限制对特定帖子类型的访问的基本指南,所有这些都可以从您的 functions.php 文件中完成。
    【解决方案2】:

    2020 年更新,有效的答案,我找到了不同的答案,它们现在都不适用于新的 WordPress。

    function hide_categories_for_specific_user( $exclusions, $args ){
    
    if ( ((defined( 'REST_REQUEST' ) && REST_REQUEST) or $GLOBALS['pagenow'] === 'edit.php' ) && !current_user_can( 'manage_options' ) ) {
    
       // IDs of terms to be excluded
       $exclude_array = array("12","16","17"); // CHANGE THIS TO IDs OF YOUR TERMS
    
    
       // Generation of exclusion SQL code
       $exterms = wp_parse_id_list( $exclude_array );
       foreach ( $exterms as $exterm ) {
               if ( empty($exclusions) )
                   $exclusions = ' AND ( t.term_id <> ' . intval($exterm) . ' ';
           else
                   $exclusions .= ' AND t.term_id <> ' . intval($exterm) . ' ';
       }
    
       // Closing bracket
       if ( !empty($exclusions) )
       $exclusions .= ')';
    
       // Return our SQL statement
    
      }
       return $exclusions;
    }
    
     // Finally hook up our filter
     add_filter( 'list_terms_exclusions', 'hide_categories_for_specific_user', 10, 2 );
    

    回答Hide Some Categories in Post Editor的最终帮助

    【讨论】:

    猜你喜欢
    • 2015-10-14
    • 2020-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-14
    • 1970-01-01
    • 2017-08-16
    • 2012-07-26
    相关资源
    最近更新 更多