【问题标题】:Remove publishing capability from user IDs从用户 ID 中删除发布功能
【发布时间】:2011-09-14 15:48:42
【问题描述】:

我正在尝试删除管理员/超级管理员(ID 号 1)以外的用户添加页面的能力,我知道有一些插件可以编辑 wordpress 角色,但在我的情况下我需要它是每个用户/用户名/用户 ID(我没有可用的插件)..

当前用户号 2 需要是“管理员”,因为我使用的特定插件仅向“管理员”角色显示报告,但我需要删除添加页面功能。我有以下代码:

function modify_capabilities()
{
global $userdata;
get_currentuserinfo();
  $userdata->ID != 1 ->remove_cap('publish_pages');

 }

add_action('admin_init','modify_capabilities');

但它不起作用..错误在这一行:

$userdata->ID != 1 ->remove_cap('publish_pages');

【问题讨论】:

  • $userdata->ID != 1 ->remove_cap('publish_pages'); 行应该做什么?您正在调用哪个对象的 remove_cap() 方法?

标签: php wordpress


【解决方案1】:

您的代码似乎有点不对劲:

function modify_capabilities()
{
global $userdata;
get_currentuserinfo();
    if ($userdata->ID != 1) {
         $role = get_role('author');
         $role->remove_cap('publish_pages');
         $role->remove_cap('publish_posts');
    }
 }

add_action('admin_init','modify_capabilities');

根据您的 cmets 更新并从您链接的博客中获取原始详细信息。不知道为什么你删除了这些部分......

【讨论】:

  • 这是原始代码(我只是修改了它): $editor_role = get_role('editor'); $editor_role->remove_cap('publish_pages');从这里:erisds.co.uk/wordpress/…
  • 我在尝试您的代码时也收到此错误:致命错误:在此行的非对象上调用成员函数 remove_cap():$somevariable->remove_cap('publish_pages');
  • 就像我说的,您需要将$somevariable 更改为正确 变量。从您的其他评论看来,它需要是 $editor_role,但您需要确保已初始化 $editor_role 变量。
  • hmm .. 我没有使用 $editor_role 的原因是因为我想删除该功能不是编辑角色.. 我想为没有 1 的用户删除该功能作为他们的用户 ID.. 我希望我解释得很好......
  • 这就是我将其更改为 author 的原因(请参阅我的编辑)。这显然只适用于创建页面/帖子的人。您链接到的那篇文章还谈到了删除每个用户的菜单项,这也许是更好的方法?
猜你喜欢
  • 2023-03-03
  • 1970-01-01
  • 2014-12-24
  • 1970-01-01
  • 2022-11-26
  • 2020-10-10
  • 2020-03-23
  • 2015-02-06
  • 2023-03-14
相关资源
最近更新 更多