有没有办法在仪表板中删除插件--在这种情况下,您无法通过插件名称识别插件?

时间:2015-10-07 作者:bestprogrammerintheworld

我正在尝试创建一个通用函数来删除管理仪表板wordpress中的菜单页。这是我的尝试。。。

function remove_menus(){

    //Find admin...
    $admin_url = get_admin_url();

    //Find php-files in admin path
    //and create an array of them
    $admin_files = array();
    foreach (glob("*.php") as $file) {
            if($file == \'.\' || $file == \'..\') continue;
            $admin_files[] = $file;
    }

    //Remove all menupages for all files in wp-admin folder
    foreach($admin_files as $af) {
        remove_menu_page( $af );    
    }

    //Get all registered post types
    // types will be a list of the post type names
    $types = get_post_types();

    //Remove pages for all registered post types as well
    foreach( $types as $type ) {
        remove_menu_page( \'edit.php?post_type=\' . $type);
    }

    //Get plugins and remove them from menu
    $plugins = get_plugins();
    foreach($plugins as $p) { 
        remove_menu_page( strtolower($p[\'Name\'] ) );
    }

}
add_action( \'admin_init\', \'remove_menus\' ,99);
我想知道的是:

 //Get plugins
 $plugins = get_plugins();
 foreach($plugins as $p) { 
     remove_menu_page( strtolower($p[\'Name\'] ) );
 }
这只会删除插件名称设置为admin的插件。页面={插件名称}

Example:remove_menu_page(\'duplicator\'); 将删除复印机插件,因为管理员。第页=duplicate

remove_menu_page(\'Yoast SEO\'); 不会删除Yoast SEO插件,因为实际的slug是admin。php?第页=wpseo_dashboard (而不是admin.php?page=yoastseo)

要手动删除此插件,您必须

remove_menu_page(\'wpseo_dashboard\');

Is there a way to remove plugins in dashboard - where you cannot identify the slug by the plugins name?

1 个回复
最合适的回答,由SO网友:Chris - SevenSpark 整理而成

我想您要做的是迭代$_GLOBALS[\'menu\'] 大堆这将为您提供管理菜单中所有项目的列表,以便您知道需要删除哪些挂钩。

此答案中包含更多详细信息和良好信息:https://wordpress.stackexchange.com/a/136064/9080

根据该答案,可以在带有键2的数组元素中找到相应的钩/段塞。

您可能还会发现本教程很有用Customizing Your WordPress Admin