Wordpress - 从管理面板中删除子菜单

时间:2012-11-13 17:18:51

标签: wordpress tags portfolio

我正在尝试从我的投资组合菜单中删除“标签”子菜单,这就是我正在使用的内容:

  add_action( 'admin_menu', 'my_remove_menu_pages' );

        function my_remove_menu_pages() {
        if(!current_user_can('create_users')) {
            remove_submenu_page( 'edit.php', 'tags.php' );
            remove_submenu_page( 'edit.php?post_type=portfolio', 'edit-tags.php?taxonomy=post_tag&post_type=portfolio' );
     }
    }

但它根本不会去。这是var_dump($ submenu)的输出;功能:

Stackoverflow需要更多文本到帖子¬¬文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本正文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本正文本文本文本文本正文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本正文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本

array(12) {
  ["index.php"]=>
  array(1) {
    [0]=>
    array(3) {
      [0]=>
      string(7) "Início"
      [1]=>
      string(4) "read"
      [2]=>
      string(9) "index.php"
    }
  }
  ["edit.php"]=>
  array(4) {
    [5]=>
    array(3) {
      [0]=>
      string(14) "Todos os Posts"
      [1]=>
      string(10) "edit_posts"
      [2]=>
      string(8) "edit.php"
    }
    [10]=>
    array(3) {
      [0]=>
      string(14) "Adicionar Novo"
      [1]=>
      string(10) "edit_posts"
      [2]=>
      string(12) "post-new.php"
    }
    [15]=>
    array(3) {
      [0]=>
      string(10) "Categorias"
      [1]=>
      string(17) "manage_categories"
      [2]=>
      string(31) "edit-tags.php?taxonomy=category"
    }
    [16]=>
    array(3) {
      [0]=>
      string(4) "Tags"
      [1]=>
      string(17) "manage_categories"
      [2]=>
      string(31) "edit-tags.php?taxonomy=post_tag"
    }
  }
  ["upload.php"]=>
  array(1) {
    [5]=>
    array(3) {
      [0]=>
      string(10) "Biblioteca"
      [1]=>
      string(12) "upload_files"
      [2]=>
      string(10) "upload.php"
    }
  }
  ["link-manager.php"]=>
  array(3) {
    [5]=>
    array(3) {
      [0]=>
      string(14) "Todos os Links"
      [1]=>
      string(12) "manage_links"
      [2]=>
      string(16) "link-manager.php"
    }
    [10]=>
    array(3) {
      [0]=>
      string(14) "Adicionar novo"
      [1]=>
      string(12) "manage_links"
      [2]=>
      string(12) "link-add.php"
    }
    [15]=>
    array(3) {
      [0]=>
      string(19) "Categorias de Links"
      [1]=>
      string(17) "manage_categories"
      [2]=>
      string(36) "edit-tags.php?taxonomy=link_category"
    }
  }
  ["edit.php?post_type=page"]=>
  array(2) {
    [5]=>
    array(3) {
      [0]=>
      string(17) "Todas as Páginas"
      [1]=>
      string(10) "edit_pages"
      [2]=>
      string(23) "edit.php?post_type=page"
    }
    [10]=>
    array(3) {
      [0]=>
      string(14) "Adicionar Nova"
      [1]=>
      string(10) "edit_pages"
      [2]=>
      string(27) "post-new.php?post_type=page"
    }
  }
  ["edit-comments.php"]=>
  array(1) {
    [0]=>
    array(3) {
      [0]=>
      string(21) "Todos os Comentários"
      [1]=>
      string(10) "edit_posts"
      [2]=>
      string(17) "edit-comments.php"
    }
  }
  ["edit.php?post_type=portfolio"]=>
  array(4) {
    [5]=>
    array(3) {
      [0]=>
      string(9) "Portfolio"
      [1]=>
      string(10) "edit_posts"
      [2]=>
      string(28) "edit.php?post_type=portfolio"
    }
    [10]=>
    array(3) {
      [0]=>
      string(14) "Adicionar Novo"
      [1]=>
      string(10) "edit_posts"
      [2]=>
      string(32) "post-new.php?post_type=portfolio"
    }
    [15]=>
    array(3) {
      [0]=>
      string(4) "Tags"
      [1]=>
      string(17) "manage_categories"
      [2]=>
      string(55) "edit-tags.php?taxonomy=post_tag&post_type=portfolio"
    }
    [16]=>
    array(3) {
      [0]=>
      string(23) "Categorias de Portfolio"
      [1]=>
      string(17) "manage_categories"
      [2]=>
      string(65) "edit-tags.php?taxonomy=portfolio_category&post_type=portfolio"
    }
  }
  ["edit.php?post_type=slideshow"]=>
  array(2) {
    [5]=>
    array(3) {
      [0]=>
      string(7) "Banners"
      [1]=>
      string(10) "edit_posts"
      [2]=>
      string(28) "edit.php?post_type=slideshow"
    }
    [10]=>
    array(3) {
      [0]=>
      string(14) "Adicionar Novo"
      [1]=>
      string(10) "edit_posts"
      [2]=>
      string(32) "post-new.php?post_type=slideshow"
    }
  }
  ["themes.php"]=>
  array(1) {
    [10]=>
    array(3) {
      [0]=>
      string(5) "Menus"
      [1]=>
      string(18) "edit_theme_options"
      [2]=>
      string(13) "nav-menus.php"
    }
  }
  ["profile.php"]=>
  array(1) {
    [5]=>
    array(3) {
      [0]=>
      string(10) "Seu perfil"
      [1]=>
      string(4) "read"
      [2]=>
      string(11) "profile.php"
    }
  }
  ["tools.php"]=>
  array(1) {
    [5]=>
    array(3) {
      [0]=>
      string(12) "Disponíveis"
      [1]=>
      string(10) "edit_posts"
      [2]=>
      string(9) "tools.php"
    }
  }
  ["options-general.php"]=>
  array(1) {
    [0]=>
    array(4) {
      [0]=>
      string(16) "Support settings"
      [1]=>
      int(1)
      [2]=>
      string(16) "support_settings"
      [3]=>
      string(16) "Support settings"
    }
  }
}

1 个答案:

答案 0 :(得分:1)

Codex page for remove_submenu_page上提出的示例为“{3}}上的可选第3个参数设置了999的”优先级“。

我不确定是否将其添加到您的代码中会使其正常工作,但值得一试。

<?php

add_action( 'admin_menu', 'adjust_the_wp_menu', 999 );
function adjust_the_wp_menu() {
  $page = remove_submenu_page( 'themes.php', 'widgets.php' );
}

?>