wordpress 判断用户类型 删除不必要后台

//删除不需要选项
function remove_menus() {


  global $menu;

  if(is_super_admin())
  {
  	$restricted = array();
  }
  else
  {
 $current_user = wp_get_current_user();
 $role=$current_user->roles[0];


	if($role=="editor")
	  {
	    $restricted = array(__('Dashboard'),  __('Media'), __('Links'), __('Pages'), __('Appearance'), __('Tools'), __('Users'), __('Settings'), __('Comments'), __('Plugins'));
	  }
	  else
	  {$restricted = array(__('Dashboard'), __('Posts'), __('Media'), __('Links'), __('Pages'), __('Appearance'), __('Tools'), __('Users'), __('Settings'), __('Comments'), __('Plugins'));}
	 

  }

  
  end ($menu);
  while (prev($menu)){
    $value = explode(' ',$menu[key($menu)][0]);
    if(strpos($value[0], '<') === FALSE) {
      if(in_array($value[0] != NULL ? $value[0]:"" , $restricted)){
        unset($menu[key($menu)]);
      }
    }
    else {
      $value2 = explode('<', $value[0]);
      if(in_array($value2[0] != NULL ? $value2[0]:"" , $restricted)){
        unset($menu[key($menu)]);
      }
    }
  }
}
if ( is_admin() ) {
  // 删除左侧菜单
  add_action('admin_menu', 'remove_menus');
}


//删除仪表盘

function disable_dashboard_widgets() {
   global $wp_meta_boxes;
   unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_activity']);
   unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']);
   unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']);
   unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']);
   unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);
   unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
   unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);
   unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);
   unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_recent_drafts']);
}
add_action('wp_dashboard_setup', 'disable_dashboard_widgets', 999);



/* 移除WordPress后台底部左文字 */
add_filter('admin_footer_text', '_admin_footer_left_text');
function _admin_footer_left_text($text) {
    $text = '';
    return $text;
}
 
/* 移除WordPress后台底部右文字 */
add_filter('update_footer', '_admin_footer_right_text', 11);
function _admin_footer_right_text($text) {
    $text = '';
    return $text;
}



/*移除后台左上角logo信息*/
function _admin_bar_remove() {
        global $wp_admin_bar;
        // var_dump($wp_admin_bar);
        $wp_admin_bar->remove_menu('wp-logo');
        $wp_admin_bar->remove_menu('comments');
        $wp_admin_bar->remove_menu('new-page');
}   
add_action('wp_before_admin_bar_render', '_admin_bar_remove', 0);

你可能感兴趣的:(wordpress)