我在删除复印机插件添加的菜单项时遇到了一些问题(https://wordpress.org/plugins/duplicator/) 如果用户不是管理员,请从“管理”菜单中选择。
我可以使用以下代码成功删除非插件项目:
function jitb_remove_admin_menu_items() {
if ( !current_user_can( \'manage_options\' ) ) {
$remove_menu_items = array( __( \'Comments\' ), __( \'Links\' ), __( \'Posts\' ), __( \'Media\' ), __( \'Users\' ), __( \'Tools\' ), __( \'Settings\' ), __( \'Profile\' ), __( \'Testimonials\' ), __( \'Appearance\' ), __( \'Portfolio\' ), __( \'Duplicator\' ) );
global $menu;
end ( $menu );
while ( prev( $menu ) ) {
$item = explode( \' \',$menu[key( $menu )][0] );
if( in_array( $item[0] != NULL?$item[0]:"" , $remove_menu_items ) ){
unset( $menu[key( $menu)] );
}
}
}
}
add_action( \'admin_init\', \'jitb_remove_admin_menu_items\' );
但这对“复制器插件”菜单项不起作用。
我还查看了复印机插件代码,它显示了使用此代码设置的菜单项:
function duplicator_menu() {
$wpfront_caps_translator = \'wpfront_user_role_editor_duplicator_translate_capability\';
//Main Menu
$perms = \'export\';
$perms = apply_filters($wpfront_caps_translator, $perms);
$main_menu = add_menu_page(\'Duplicator Plugin\', \'Duplicator\', $perms, \'duplicator\', \'duplicator_get_menu\', plugins_url(\'duplicator/assets/img/create.png\'));
$perms = \'export\';
$perms = apply_filters($wpfront_caps_translator, $perms);
$page_packages = add_submenu_page(\'duplicator\', __(\'Packages\', \'wpduplicator\'), __(\'Packages\', \'wpduplicator\'), $perms, \'duplicator\', \'duplicator_get_menu\');
$perms = \'manage_options\';
$perms = apply_filters($wpfront_caps_translator, $perms);
$page_settings = add_submenu_page(\'duplicator\', __(\'Settings\', \'wpduplicator\'), __(\'Settings\', \'wpduplicator\'), $perms, \'duplicator-settings\', \'duplicator_get_menu\');
$perms = \'manage_options\';
$perms = apply_filters($wpfront_caps_translator, $perms);
$page_tools = add_submenu_page(\'duplicator\', __(\'Tools\', \'wpduplicator\'), __(\'Tools\', \'wpduplicator\'), $perms, \'duplicator-tools\', \'duplicator_get_menu\');
$perms = \'read\';
$perms = apply_filters($wpfront_caps_translator, $perms);
$page_help = add_submenu_page(\'duplicator\', __(\'Help\', \'wpduplicator\'), __(\'Help\', \'wpduplicator\'), $perms, \'duplicator-help\', \'duplicator_get_menu\');
$perms = \'read\';
$perms = apply_filters($wpfront_caps_translator, $perms);
$page_about = add_submenu_page(\'duplicator\', __(\'About\', \'wpduplicator\'), __(\'About\', \'wpduplicator\'), $perms, \'duplicator-about\', \'duplicator_get_menu\');
//Apply Scripts
add_action(\'admin_print_scripts-\' . $page_packages, \'duplicator_scripts\');
add_action(\'admin_print_scripts-\' . $page_settings, \'duplicator_scripts\');
add_action(\'admin_print_scripts-\' . $page_help, \'duplicator_scripts\');
add_action(\'admin_print_scripts-\' . $page_tools, \'duplicator_scripts\');
add_action(\'admin_print_scripts-\' . $page_about, \'duplicator_scripts\');
//Apply Styles
add_action(\'admin_print_styles-\' . $page_packages, \'duplicator_styles\');
add_action(\'admin_print_styles-\' . $page_settings, \'duplicator_styles\');
add_action(\'admin_print_styles-\' . $page_help, \'duplicator_styles\');
add_action(\'admin_print_styles-\' . $page_tools, \'duplicator_styles\');
add_action(\'admin_print_styles-\' . $page_about, \'duplicator_styles\');
}
但是,在我的jitb\\u remove\\u admin\\u menu\\u items函数中添加标题“replicator”不会删除菜单项。
在这种情况下,我做错了什么?
谢谢