作者:手机用户2502937923 | 来源:互联网 | 2018-03-22 14:49
1.代码
function remove_menus() {
global $menu;
$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], &#39;<&#39;) === FALSE) {
if(in_array($value[0] != NULL ? $value[0]:"" , $restricted)){
unset($menu[key($menu)]);
}
}else {
$value2 = explode(&#39;<&#39;, $value[0]);
if(in_array($value2[0] != NULL ? $value2[0]:"" , $restricted)){
unset($menu[key($menu)]);
}
}
}
}
if (is_admin()){
// 屏蔽左侧菜单
add_action(&#39;admin_menu&#39;, &#39;remove_menus&#39;);
}
2. 删除子菜单
function remove_submenu() {
// 删除”设置”下面的子菜单”隐私”
remove_submenu_page(&#39;options-general.php&#39;, &#39;options-privacy.php&#39;);
// 删除”外观”下面的子菜单”编辑”
remove_submenu_page(&#39;themes.php&#39;, &#39;theme-editor.php&#39;);
}
if (is_admin()){
//删除子菜单
add_action(&#39;admin_init&#39;,&#39;remove_submenu&#39;);
}
3.屏蔽后台更新模块
function wp_hide_nag() {
remove_action( &#39;admin_notices&#39;, &#39;update_nag&#39;, 3 );
}
add_action(&#39;admin_menu&#39;,&#39;wp_hide_nag&#39;);
4. 屏蔽后台导航栏LOGO
function annointed_admin_bar_remove() {
global $wp_admin_bar;
$wp_admin_bar->remove_menu(&#39;wp-logo&#39;);
}
add_action(&#39;wp_before_admin_bar_render&#39;, &#39;annointed_admin_bar_remove&#39;, 0);
5. 删除后台无用模块
function example_remove_dashboard_widgets() {
// Globalize the metaboxes array, this holds all the widgets for wp-admin
global $wp_meta_boxes;
// 以下这一行代码将删除 "快速发布" 模块
unset($wp_meta_boxes[&#39;dashboard&#39;][&#39;side&#39;][&#39;core&#39;][&#39;dashboard_quick_press&#39;]);
// 以下这一行代码将删除 "引入链接" 模块
unset($wp_meta_boxes[&#39;dashboard&#39;][&#39;normal&#39;][&#39;core&#39;][&#39;dashboard_incoming_links&#39;]);
// 以下这一行代码将删除 "插件" 模块
unset($wp_meta_boxes[&#39;dashboard&#39;][&#39;normal&#39;][&#39;core&#39;][&#39;dashboard_plugins&#39;]);
// 以下这一行代码将删除 "近期评论" 模块
unset($wp_meta_boxes[&#39;dashboard&#39;][&#39;normal&#39;][&#39;core&#39;][&#39;dashboard_recent_comments&#39;]);
// 以下这一行代码将删除 "近期草稿" 模块
unset($wp_meta_boxes[&#39;dashboard&#39;][&#39;side&#39;][&#39;core&#39;][&#39;dashboard_recent_drafts&#39;]);
// 以下这一行代码将删除 "WordPress 开发日志" 模块
unset($wp_meta_boxes[&#39;dashboard&#39;][&#39;side&#39;][&#39;core&#39;][&#39;dashboard_primary&#39;]);
// 以下这一行代码将删除 "其它 WordPress 新闻" 模块
unset($wp_meta_boxes[&#39;dashboard&#39;][&#39;side&#39;][&#39;core&#39;][&#39;dashboard_secondary&#39;]);
// 以下这一行代码将删除 "概况" 模块
unset($wp_meta_boxes[&#39;dashboard&#39;][&#39;normal&#39;][&#39;core&#39;][&#39;dashboard_right_now&#39;]);
}
add_action(&#39;wp_dashboard_setup&#39;, &#39;example_remove_dashboard_widgets&#39; );