wordpress后台的模块很多,但并不是每个都经常用到。介绍几段代码,可以根据自己的需要屏蔽不常用的模块,借此提升wordpress后台运行效率。
将下面的代码根据需要复制到wordpress主题的模版文件functions.PHP中:
functionremove_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],'<')===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');
}
functionremove_submenu(){
remove_submenu_page('options-general.PHP','options-privacy.PHP');
remove_submenu_page('themes.PHP','theme-editor.PHP');
}
if(is_admin()){
add_action('admin_init','remove_submenu');
}
functionwp_hide_nag(){ remove_action('admin_notices','update_nag',3); } add_action('admin_menu','wp_hide_nag');
functionremove_screen_options(){returnfalse;}
add_filter('screen_options_show_screen','remove_screen_options');
add_filter('contextual_help','wpse50723_remove_help',999,3);
functionwpse50723_remove_help($old_help,$screen_id,$screen){
$screen->remove_help_tabs();
return$old_help;
}
五、屏蔽仪表盘中的无用模块
functionexample_remove_dashboard_widgets(){
//GlobalizetheMetaBoxesarray,thisholdsallthewidgetsforwp-admin
unset($wp_Meta_Boxes['dashboard']['side']['core']['dashboard_quick_press']);
unset($wp_Meta_Boxes['dashboard']['normal']['core']['dashboard_incoming_links']);
unset($wp_Meta_Boxes['dashboard']['normal']['core']['dashboard_plugins']);
unset($wp_Meta_Boxes['dashboard']['normal']['core']['dashboard_recent_comments']);
unset($wp_Meta_Boxes['dashboard']['side']['core']['dashboard_recent_drafts']);
unset($wp_Meta_Boxes['dashboard']['side']['core']['dashboard_primary']);
unset($wp_Meta_Boxes['dashboard']['side']['core']['dashboard_secondary']);
unset($wp_Meta_Boxes['dashboard']['normal']['core']['dashboard_right_Now']);
}
add_action('wp_dashboard_setup','example_remove_dashboard_widgets');
functionchange_footer_admin(){return'';}
add_filter('admin_footer_text','change_footer_admin',9999);
functionchange_footer_version(){return'';}
add_filter('update_footer','change_footer_version',9999);
functionannointed_admin_bar_remove(){
global$wp_admin_bar;
/*Removetheirstuff*/
$wp_admin_bar->remove_menu('wp-logo');
}
add_action('wp_before_admin_bar_render','annointed_admin_bar_remove',0);
以上介绍的wordpress技巧,仅是将这些模块暂时隐藏起来,而并非删除。今后需要的时候,只需将相对应的代码从functions.PHP文件中移除,即可恢复被屏蔽的模块。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。