[wp-hackers] RE: simple method to hide admin menus

Viper007Bond viper at viper007bond.com
Sat Sep 8 06:34:15 GMT 2007


Seems rather complicated when Patrick's code would get the job easily done.
:/

Oh, and for reference, open up /wp-admin/menu.php

On 9/7/07, Mindshare Studios <info at mindsharestudios.com> wrote:
>
> Hi - I still haven't figured out an elegant way to hide menu items but
> perhaps some could take a look at what I am trying to do and offer a
> suggestion:
>
> --------------
>
> $default_items = array('index.php', 'post-new.php', 'edit.php',
> 'edit-comments.php', 'link-manager.php', 'themes.php', 'plugins.php',
> 'users.php', 'options-general.php' );
>
> function mindshare_admin_menu() {
>         global $submenu, $menu, $default_items;
>
>         for  ($i = 0; $i < count($default_items); $i++) {
>                 if (locateInMenu($default_items[$i], $menu)) {
>                         // item was found
>                         if(!current_user_can('level_10')) {
>                                 unset($menu[0]); // hide the item, not
> sure
> how to target the item
>                         }
>                 }
>         }
> }
>
> function locateInMenu($needle, $haystack) {
>         $inMenu = false;
>         $x = 0;
>         foreach($haystack as $temp) {
>                 $search = array_search($needle, $temp);
>                 if (strlen($search) > 0 && $search >= 0) {
>                         $value[0] = $x;
>                         $value[1] = $search;
>                 }
>                 $x++;
>         }
>         return $inMenu;
> }
>
> add_action('admin_head','mindshare_admin_menu');
>
> --------------
>
> Thank you,
> Damian
>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>



-- 
Viper007Bond | http://www.viper007bond.com/


More information about the wp-hackers mailing list