【问题标题】:Wordpress: Hide specific categories from User Role on the Add New pageWordpress:在添加新页面上隐藏用户角色的特定类别
【发布时间】:2018-01-06 09:54:54
【问题描述】:

正如标题所说的那样;

如何在“添加新帖子”页面上隐藏 Wordpress 中指定用户角色的特定类别?这样特定角色的用户就看不到隐藏的类别(因此,也不要在其中发帖)。

我曾经通过插件来做到这一点,但它们多年来一直没有更新,我似乎无法找到替代品。因此,我们将不胜感激。

干杯

【问题讨论】:

  • 你能说出你已经在使用什么插件......即使没有更新它没有解决什么目的。
  • 您很可能能够通过操作或过滤器执行某些操作。您是否查看了源代码以了解列表是如何生成的?
  • @Plot64 试试这个。它应该做的工作。 wordpress.stackexchange.com/questions/8197/…

标签: php wordpress categories user-roles


【解决方案1】:

答案转换为评论。

将此代码应用于您自己的代码,应该可以工作。

add_filter('list_terms_exclusions', 'yoursite_list_terms_exclusions', 10, 2);

function yoursite_list_terms_exclusions( $exclusions, $args ) {

    global $pagenow;
    if (in_array($pagenow,array('post.php','post-new.php')) && !current_user_can('see_special_cats')) {
        $exclusions = " {$exclusions} AND t.slug NOT IN ('slug-one','slug-two')";
    }
    return $exclusions;
}

see_special_cats => WordPress 管理员中的用户级别(管理员、作者等...)

More info about users levels in WordPress

【讨论】:

  • 谢谢你 - 我也会试一试。与我在下面链接的插件相比,这种方法有什么好处吗? ps:在上面的成本中,我在哪里指定了用户角色和/或对这些用户角色隐藏的类别?
  • @Plot64 你到底指的是哪个插件?至于第二个问题,你能再澄清一点吗?谢谢。
  • 你能解释一下这里发生了什么吗?为哪些角色隐藏了哪些类别?
猜你喜欢
  • 2019-12-30
  • 2020-04-05
  • 2013-04-01
  • 2014-05-26
  • 1970-01-01
  • 1970-01-01
  • 2014-07-21
  • 1970-01-01
  • 2018-09-06
相关资源
最近更新 更多