Wordpress: remove menu Administration

Saturday, November 1, 2008

It may be useful at times to shadow some of the administration menu of WordPress, especially if you developed a website / blog for a client and do not want to allow access to particularly sensitive features. There are already plugins that provide this function, but for a personal check and complete, we see how it works in detail this feature.
As always, we use the very useful Action provided by Wordpress, in this case admin_menu Using the global variable $menu we can access the contextual menu of the administration. We can find the menu to "eliminate" in two ways: through the label or through the link pointed to (Part commented example below). In the example are shadowed menu items Design, Settings, and Plugins:

PHP:
  1. remove_menu_item function () (
  2. ; global $ menu;
  3. / / By label
  4. array ( 'Design' , 'Impostazioni' , 'Plugins' ) ; $ removes = array ( 'Design', 'Settings', 'Plugins');
  5. / / Through links
  6. / / $ Removes = array ( 'themes.php', 'options-general.php', 'plugins.php');
  7. $removes as $todel ) foreach ($ removes as $ todel)
  8. $menu as $key => $sm ) if ( $sm [ 0 ] == $todel ) { unset ( $menu [ $key ] ) ; break ; } foreach ($ menu as $ key => $ sm) if ($ sm [0] == $ todel) (unset ($ menu [$ key]) break;)
  9. / / Through links
  10. / / Foreach ($ menu as $ key => $ sm) if ($ sm [2] == $ todel) (unset ($ menu [$ key]) break;)
  11. )
  12. / /
  13. , 'remove_menu_item' ) ; add_action ( 'admin_menu', 'remove_menu_item');

Use the link as a key for removal $sm[2] in parts surprise and comment in the code here), is useful when you are not sure of the language - localization - with which you installed Wordpress. With this technique, however, the menu is removed only at the interface, so you can still access the site via a direct link.

Related Post

Was this article helpful?: Per nientePocoAbbastanzaMoltoMoltissimo
Loading ... Loading ...

12 comments to "Wordpress: remove menu administration"

  1. getAvatar 1.0
    01 nov, 2008 Wolf:

    Very nice tutorial.
    We often ask on the support forum how to remove the menu 'on board but at the user level.
    If I could add to the control of the user level and if we allow him publish this code in the wiki.
    hello

  2. getAvatar 1.0
  3. getAvatar 1.0
    03 nov, 2008 camu:

    But give him an account, less powerful, no? :)

  4. getAvatar 1.0
    03 nov, 2008 Wolf:

    @ Camu is not a question of power of the account, there are some who would like to see who writes on their blog to write only that part and can not see anything else even the comments.
    And 'their needs, right or wrong, and given that they ask many prefer to give them a solution.
    hello

  5. getAvatar 1.0
    07 nov, 2008 Wolf on "One page" post-new "entry for employees ...":

    [...] The new version of WordPress 2.7 has a page of the genre. The problem will then inhibit the rest but you can try these scripts udolog http://www.undolog.com/2008/11/01/wordpress-rimuovere-i-menu-dellamministrazione/ [...]

  6. getAvatar 1.0
    06 dic, 2008 Alessio:

    good, then if you connect to the Admin tiger furi plugin is also a nice graphics package for customers.

  7. getAvatar 1.0
    08 feb, 2009 Split:

    Sorry but I can not get away with the code ...
    I described this need to limit the intervention on the blog. Being a club everyone wants its share of access but of course I have to include assistance to the blog.
    I thought a plugin but I can not find it appropriate and with the code I realized that it acts at the admin menu ... Recommendations please?

  8. getAvatar 1.0
    November 23, 2009 Peter:

    Sorry, but where to put that code??
    Thank you in advance

  9. getAvatar 1.0
    November 23, 2009 Giovambattista Fazioli:

    @ Peter:

    Sorry, but where to put that code??

    Can put in the file functions.php which is in the folder of your active theme. Alternatively, if you're developing your own plugin, the code of the latter. In practice, the important thing is that this code is executed at least once ... : D

  10. getAvatar 1.0
    November 24, 2009 Peter:

    Thanks, you're putting it into a function, even if existing plugins?
    No, because I am creating a web hosting service where people can request a perosna del propio blog based on WordPress platform (NOT mu) I would hide from the menu button that sends the administrative management of plugins EasyAdsense so that the 'user can not amend the advertisement to his liking.
    Do you know if you can? Or in which file to put that code protein without being erased when you upgrade Wordpress, plugins or templates?
    Thanks again, I await answers

  11. getAvatar 1.0
    November 25, 2009 Giovambattista Fazioli:

    @ Peter:

    Thanks, you're putting it into a function, even if existing plugins?

    Sure, you can enter it - of course - even in a plugin already exists.

    @ Peter:

    Do you know if you can? Or in which file to put that code protein without being erased when you upgrade Wordpress, plugins or templates?

    This procedure is used so as to hide some controls to any users who work in the backend of WordPress. For updates, however, you must find a "place" that surely can not be overwritten by updates. WordPress MU, for example, we simplify the task as it has the ability to "impose" the plugin at all sub-blogs.
    On normal WordPress installation, where you can update your version, update the theme (and then overwrite the file index.php) and update the plugin (and then delete or disable them) do not know where to place the code ... think and let you know.

  12. getAvatar 1.0
    November 25, 2009 Peter:

    Enter a file. Htaccess file in the root will?

Leave a comment

TAG XHTML PERMISSIONS: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> INSERTION CODE:
 <pre></pre>         // blocco generico [code][/code]       // blocco generico [as][/as]           // Actionscript [css][/css]         // CSS Style Sheet [html][/html]       // HTML [js][/js]           // Javascript [objc][/objc]       // Objective-C [php][/php]         // PHP [sql][/sql]         // SQL