简体   繁体   English

WordPress删除管理员菜单项

[英]WordPress remove admin menu item

Generally it's not a problem to remove wp-admin menu items, eg: 通常,删除wp-admin菜单项不是问题,例如:

add_action( 'admin_init', 'my_remove_menu_pages' );

function my_remove_menu_pages() {               
  remove_submenu_page( 'themes.php', 'theme-editor.php' );                                          
}

However I'm currently struggling with the following page: 但是我目前正在努力处理以下页面:

admin.php?page=wpml-string-translation/menu/string-translation.php

What's the best method to have this one removed? 删除此最佳方法是什么?

I think you're add_action needs a numeric as a 3rd argument (a priority). 我认为您的add_action需要一个数字作为第三个参数(优先级)。

Example

If you have this add_action: 如果您有此add_action:

add_action( 'admin_bar_menu', 'wp_admin_bar_wp_menu', 10 );

To remove it, it needs a higher priority (11): 要删除它,它需要更高的优先级(11):

<?php # -*- coding: utf-8 -*-
/**
 * Plugin Name: Remove WP Menu From Tool Bar
 */
if ( ! function_exists( 't5_remove_wp_menu' ) )
{
    // The action is added with a priority of 10, we take one step later.
    add_action( 'init', 't5_remove_wp_menu', 11 );

    /**
     * Remove the WP menu action.
     */
    function t5_remove_wp_menu()
    {
        is_admin_bar_showing() &&
            remove_action( 'admin_bar_menu', 'wp_admin_bar_wp_menu', 10 );
    }
}

Based on the previous answers, here's the completed solution for both WPML user menus: 根据先前的答案,这是两个WPML用户菜单的完整解决方案:

function remove_menu_items()
{
    //removes the 'String Translation' menu item from editor's admin screen
    if (defined('WPML_ST_FOLDER')){
        remove_menu_page(WPML_ST_FOLDER.'/menu/string-translation.php');
    }
    //removes the 'Translation Interface' menu item from editor's admin screen
    if (defined('WPML_TM_FOLDER')){
        remove_menu_page(WPML_TM_FOLDER . '/menu/translations-queue.php');
    }
}
add_action('admin_menu', 'remove_menu_items', 999);

This should work, 这应该工作,

add_action( 'admin_init', 'my_remove_menu_pages' );

function my_remove_menu_pages() {
    remove_submenu_page( 'admin.php?page=wpml-string-translation/menu/string-translation.php', 'admin.php?page=wpml-string-translation/menu/string-translation.php' );
}

The working solution: 工作解决方案:

function remove_menu_items()
{
    //removes the String Translation menu item from editor's admin screen
    if (defined('WPML_ST_FOLDER'))
        remove_menu_page(WPML_ST_FOLDER.'/menu/string-translation.php');
}
add_action('admin_menu', 'remove_menu_items', 999);

It needs a higher priority from which it was created and to avoid any issues let's use the same WPML constant, which we can find on the file "wpml-string-translation-class.php" at the plugin folder, line 212 as of version 1.6.1 of the WPML String Transtation plugin. 从创建它开始,它需要更高的优先级,并且为避免任何问题,让我们使用相同的WPML常量,我们可以在插件文件夹中的文件“ wpml-string-translation-class.php”(版本为212行)上找到该常量。 WPML字符串转换插件的1.6.1。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM