关闭电子邮件地址的多个WordPress菜单项

时间:2019-02-21 23:15:56

标签: php wordpress

我具有以下功能,但不知道如何在列表中添加多个电子邮件地址。

// Remove Different Admin Menu Links For A Specific User Profile
add_action('admin_menu', 'remove_admin_menu_links');
function remove_admin_menu_links(){
     $user = wp_get_current_user();
     if( $user && isset($user->user_email) && 'user@email.com' == $user->user_email ) {
         remove_menu_page( 'tools.php' );
         remove_menu_page( 'themes.php' );
         remove_menu_page( 'options-general.php' );
         remove_menu_page( 'plugins.php' );
         remove_menu_page( 'users.php' );
         remove_menu_page( 'edit-comments.php' );
         remove_menu_page( 'page.php' );
         remove_menu_page( 'upload.php' );
         remove_menu_page( 'edit.php?post_type=page' );
         remove_menu_page( 'edit.php?post_type=videos' );
         remove_menu_page( 'edit.php' );
     }
 }
 remove_theme_support( 'genesis-admin-menu' );

1 个答案:

答案 0 :(得分:2)

创建一个电子邮件地址数组,并检查其是否存在:

add_action('admin_menu', 'remove_admin_menu_links');
function remove_admin_menu_links(){

     $restrictedUsers = [
          "someone@somewhere.com",
          "user@email.com"
     ];

     $user = wp_get_current_user();
     if( $user && isset($user->user_email) && in_array($user->user_email, $restrictedUsers )) {
         remove_menu_page( 'tools.php' );
         remove_menu_page( 'themes.php' );
         remove_menu_page( 'options-general.php' );
         remove_menu_page( 'plugins.php' );
         remove_menu_page( 'users.php' );
         remove_menu_page( 'edit-comments.php' );
         remove_menu_page( 'page.php' );
         remove_menu_page( 'upload.php' );
         remove_menu_page( 'edit.php?post_type=page' );
         remove_menu_page( 'edit.php?post_type=videos' );
         remove_menu_page( 'edit.php' );
     }
 }
 remove_theme_support( 'genesis-admin-menu' );