wordpress后台的模块很多,但并不是每个都经常用到。介绍几段代码,可以根据自己的需要屏蔽不常用的模块,借此提升wordpress后台运行效率。将下面的代码根据需要复制到wordpress主题的模版文件functions.PHP中:@H_502_1@
一、屏蔽左侧菜单@H_502_1@
functionremove_menus(){@H_502_1@
global$menu;@H_502_1@
$restricted=array(@H_502_1@
__('Dashboard'),@H_502_1@
__('posts'),@H_502_1@
__('Media'),@H_502_1@
__('links'),@H_502_1@
__('Pages'),@H_502_1@
__('Appearance'),@H_502_1@
__('Tools'),@H_502_1@
__('Users'),@H_502_1@
__('Settings'),@H_502_1@
__('Comments'),@H_502_1@
__('Plugins')@H_502_1@
);@H_502_1@
end($menu);@H_502_1@
while(prev($menu)){@H_502_1@
$value=explode('',$menu[key($menu)][0]);@H_502_1@
if(strpos($value[0],'<')===FALSE){@H_502_1@
if(in_array($value[0]!=NulL?$value[0]:"",$restricted)){@H_502_1@
unset($menu[key($menu)]);@H_502_1@
}@H_502_1@
}else{@H_502_1@
$value2=explode('<',$value[0]);@H_502_1@
if(in_array($value2[0]!=NulL?$value2[0]:"",$restricted)){@H_502_1@
unset($menu[key($menu)]);@H_502_1@
}@H_502_1@
}@H_502_1@
}@H_502_1@
}@H_502_1@
if(is_admin()){@H_502_1@
//屏蔽左侧菜单@H_502_1@
add_action('admin_menu','remove_menus');@H_502_1@
}二、删除子菜单@H_502_1@
functionremove_submenu(){@H_502_1@
//删除”设置”下面的子菜单”隐私”@H_502_1@
remove_submenu_page('options-general.PHP','options-privacy.PHP');@H_502_1@
//删除”外观”下面的子菜单”编辑”@H_502_1@
remove_submenu_page('themes.PHP','theme-editor.PHP');@H_502_1@
}@H_502_1@
if(is_admin()){@H_502_1@
//删除子菜单@H_502_1@
add_action('admin_init','remove_submenu');@H_502_1@
}三、屏蔽后台更新模块@H_502_1@
functionwp_hIDe_nag(){ remove_action('admin_notices','update_nag',3); } add_action('admin_menu','wp_hIDe_nag');四、屏蔽后台“显示选项”和“帮助”选项卡@H_502_1@
functionremove_screen_options(){returnfalse;}@H_502_1@
add_filter('screen_options_show_screen','remove_screen_options');@H_502_1@
add_filter('contextual_help','wpse50723_remove_help',999,3);@H_502_1@
functionwpse50723_remove_help($old_help,$screen_ID,$screen){@H_502_1@
$screen->remove_help_tabs();@H_502_1@
return$old_help;@H_502_1@
}五、屏蔽仪表盘中的无用模块@H_502_1@
functionexample_remove_dashboard_Widgets(){@H_502_1@
//GlobalizethemetaBoxesarray,thisholdsalltheWidgetsforwp-admin@H_502_1@
global$wp_Meta_Boxes;@H_502_1@
//以下这一行代码将删除"快速发布"模块@H_502_1@
unset($wp_Meta_Boxes['dashboard']['sIDe']['core']['dashboard_quick_press']);@H_502_1@
//以下这一行代码将删除"引入链接"模块@H_502_1@
unset($wp_Meta_Boxes['dashboard']['normal']['core']['dashboard_incoming_links']);@H_502_1@
//以下这一行代码将删除"插件"模块@H_502_1@
unset($wp_Meta_Boxes['dashboard']['normal']['core']['dashboard_plugins']);@H_502_1@
//以下这一行代码将删除"近期评论"模块@H_502_1@
unset($wp_Meta_Boxes['dashboard']['normal']['core']['dashboard_recent_comments']);@H_502_1@
//以下这一行代码将删除"近期草稿"模块@H_502_1@
unset($wp_Meta_Boxes['dashboard']['sIDe']['core']['dashboard_recent_drafts']);@H_502_1@
//以下这一行代码将删除"wordpress开发日志"模块@H_502_1@
unset($wp_Meta_Boxes['dashboard']['sIDe']['core']['dashboard_primary']);@H_502_1@
//以下这一行代码将删除"其它wordpress新闻"模块@H_502_1@
unset($wp_Meta_Boxes['dashboard']['sIDe']['core']['dashboard_secondary']);@H_502_1@
//以下这一行代码将删除"概况"模块@H_502_1@
unset($wp_Meta_Boxes['dashboard']['normal']['core']['dashboard_right_Now']);@H_502_1@
}@H_502_1@
add_action('wp_dashboard_setup','example_remove_dashboard_Widgets');六、屏蔽后台页脚版本信息@H_502_1@
functionchange_footer_admin(){return'';}@H_502_1@
add_filter('admin_footer_text','change_footer_admin',9999);@H_502_1@
functionchange_footer_version(){return'';}@H_502_1@
add_filter('update_footer','change_footer_version',9999);七、屏蔽后台左上logo@H_502_1@
functionannointed_admin_bar_remove(){@H_502_1@
global$wp_admin_bar;@H_502_1@
/*Removetheirstuff*/@H_502_1@
$wp_admin_bar->remove_menu('wp-logo');@H_502_1@
}@H_502_1@
add_action('wp_before_admin_bar_render','annointed_admin_bar_remove',0);以上介绍的wordpress技巧,仅是将这些模块暂时隐藏起来,而并非删除。今后需要的时候,只需将相对应的代码从functions.PHP文件中移除,即可恢复被屏蔽的模块。@H_502_1@ 总结
以上是内存溢出为你收集整理的屏蔽wordpress后台无用菜单和模块 提升wordpress运行效率全部内容,希望文章能够帮你解决屏蔽wordpress后台无用菜单和模块 提升wordpress运行效率所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)