当我在POST编辑器中点击‘添加媒体’时,为什么它不会用这个代码加载媒体库?

时间:2015-03-15 作者:Leona grey

add_action( \'admin_init\', \'my_remove_menu_pages\' );
function my_remove_menu_pages() {

    global $user_ID;

    if ( current_user_can( \'contributor\' ) ) {
remove_menu_page(\'tools.php\'); // Tools
remove_menu_page(\'edit-comments.php\'); // Comments
 remove_menu_page(\'edit.php\'); // posts? 
 remove_menu_page( \'profile.php\'); // profile
 remove_menu_page(\'index.php\');  
    remove_menu_page( \'post-new\' ); 
    }
    remove_menu_page(\'users.php\');
    remove_menu_page(\'tools.php\');
    remove_menu_page(\'themes.php\'); //appearance
    remove_menu_page( \'edit.php?post_type=acf-field-group\' ); // advanced custom fields
    remove_menu_page( \'edit-comments.php\' );
}
我不明白为什么当我点击“添加媒体”时,它不会加载媒体库,而上面的代码是函数。php。有人能解释一下吗?

1 个回复
SO网友:cybmeta

在管理区域中添加/删除菜单的正确挂钩是admin_menu. 此外,请注意current_user_can 旨在检查用户功能,而不是用户角色。看见current_user_can documentationnotes.

add_action( \'admin_menu\', \'my_remove_menu_pages\' );
function my_remove_menu_pages() {

    $user = wp_get_current_user();

    if( ! empty( $user ) && in_array( "contributor", (array) $user->roles ) ) {

        remove_menu_page(\'tools.php\'); // Tools
        remove_menu_page(\'edit-comments.php\'); // Comments
        remove_menu_page(\'edit.php\'); // posts? 
        remove_menu_page( \'profile.php\'); // profile
        remove_menu_page(\'index.php\');  
        remove_menu_page( \'post-new\' );

    }

    remove_menu_page(\'users.php\');
    remove_menu_page(\'tools.php\');
    remove_menu_page(\'themes.php\'); //appearance
    remove_menu_page( \'edit-comments.php\' );

}

结束

相关推荐