WordPress完全删除自定义角色的功能POST、媒体

时间:2016-12-16 作者:bakhtawar

我创建了一个新角色。现在我要删除post ,media, setting 该角色的能力。我怎样才能做到这一点?

2 个回复
SO网友:ehabdevel

删除顶级管理菜单:

    function custom_menu_page_removing() {
    remove_menu_page( $menu_slug );
}
add_action( \'admin_menu\', \'custom_menu_page_removing\' );
要仅删除某些菜单项,请仅包括要隐藏在函数中的菜单项。要仅删除特定用户的菜单,您可能需要使用current\\u user\\u can()。

你可以看看https://codex.wordpress.org/Function_Reference/remove_menu_page

SO网友:prosti

请您尝试一下:

$data = get_userdata( 1 ); // or any other ID where your new role works
if ( !empty( $data) ) {
    $user_caps = $data->allcaps;
    echo \'<pre>\' . print_r( $user_caps, true ) . \'</pre>\';
}
您将了解自己的能力。

Array
(
    [switch_themes] => 1
    [edit_themes] => 1
    [activate_plugins] => 1
    [edit_plugins] => 1
    [edit_users] => 1
    [edit_files] => 1
    [manage_options] => 1
    [moderate_comments] => 1
    [manage_categories] => 1
    [manage_links] => 1
    [upload_files] => 1
    [import] => 1
    [unfiltered_html] => 1
    [edit_posts] => 1
    [edit_others_posts] => 1
    [edit_published_posts] => 1
    [publish_posts] => 1
    [edit_pages] => 1
    [read] => 1
    [level_10] => 1
    [level_9] => 1
    [level_8] => 1
    [level_7] => 1
    [level_6] => 1
    [level_5] => 1
    [level_4] => 1
    [level_3] => 1
    [level_2] => 1
    [level_1] => 1
    [level_0] => 1
    [edit_others_pages] => 1
    [edit_published_pages] => 1
    [publish_pages] => 1
    [delete_pages] => 1
    [delete_others_pages] => 1
    [delete_published_pages] => 1
    [delete_posts] => 1
    [delete_others_posts] => 1
    [delete_published_posts] => 1
    [delete_private_posts] => 1
    [edit_private_posts] => 1
    [read_private_posts] => 1
    [delete_private_pages] => 1
    [edit_private_pages] => 1
    [read_private_pages] => 1
    [delete_users] => 1
    [create_users] => 1
    [unfiltered_upload] => 1
    [edit_dashboard] => 1
    [update_plugins] => 1
    [delete_plugins] => 1
    [install_plugins] => 1
    [update_themes] => 1
    [install_themes] => 1
    [update_core] => 1
    [list_users] => 1
    [remove_users] => 1
    [promote_users] => 1
    [edit_theme_options] => 1
    [delete_themes] => 1
    [export] => 1
    [view_query_monitor] => 1
    [administrator] => 1
)
然后使用以下代码简单地删除它们:

// Remove a capability from a specific user.
$user_id = // The ID of the user to remove the capability from.
$user = new WP_User( $user_id );
$user->remove_cap( \'read_private_posts\' );
发件人ref.

相关推荐

未定义的偏移量:1067行的>[...]/wp-includes/capabilities.php中的0

嘿,我在我的localhost设置中得到了这个错误消息,但只有在启用Genesis框架的情况下;WordPress二十一行。当我想创建一个新帖子时,就会发生这种情况。如果我刷新页面,错误会重复,但帖子本身会被创建,一切似乎都很好。有人知道这是什么原因吗?Notice: Undefined offset: 0 in /var/www/secret/htdocs/wp-includes/capabilities.php on line 1067 Notice: Undefined offset: 0