• Resolved otti.steinhauer

    (@ottisteinhauer)


    Hello,
    for a custom Dashbaord I want to remove menu-items.Admin may see all menu-items, users only a few.
    There is no problem to remove the items like design, plugins media…, which come from wordpess. But there are three items to remove, they are registered by plugins. My code:

    function remove_menus () {
    	global $menu;
    	global $current_user;
    	//$restricted = array(__('Artikel'), __('Mediathek'), __('Links'), __('Seiten'), __('Kommentare'), __('Design'), __('Plugins'), __('Benutzer'), __('Werkzeuge'), __('Einstellungen'), __('Maintenance'));
    	$restricted = array(  __('Beitr?ge'),__('Werkzeuge'), __('Kommentare'), __('Einstellungen'), __('Maintenance'));
    	end ($menu);
    	while (prev($menu)){
    		$value = explode(' ',$menu[key($menu)][0]);
    		if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){
    			// Einstellungen entfernen für Kunden
    			if ( in_array( 'kunde', $current_user->roles )|| in_array( 'vermittler', $current_user->roles ) ){
    				unset($menu[key($menu)]);
    			}
    		}
    	}
    	if ( in_array( 'kunde', $current_user->roles )|| in_array( 'vermittler', $current_user->roles ) ){
    		//Hauptmenü Mediathek, Untermenüs Medienübersicht:
    		remove_menu_page('upload.php');
    		remove_submenu_page('upload.php', 'upload.php');
    		remove_submenu_page('upload.php', 'media-new.php');
    		// Menüs aus den Plugins
    	}
    }
    add_action('admin_menu', 'remove_menus');

    The plugins have got the links:

    • /wp-admin/admin.php?page=maintenance
    • /wp-admin/admin.php?page=dpMaintenanceLite-settings
    • /wp-admin/admin.php?page=all-in-one-seo-pack/aioseop_class.php

    The last one has got some submenus like /wp-admin/admin.php?page=all-in-one-seo-pack/aioseop_performance.php. What should I do? To remove with remove_menu_page() does’nt work.
    Please excuse my bad English, I hope I could explain the problem.

    Thanks

    Ottilie

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator bcworkz

    (@bcworkz)

    Using remove_menu_page() and remove_submenu_page() is the correct way. However you must ensure your removal functions run after the plugins actually have added their menus. Simply adding a hook to ‘admin_menu’ uses a priority of 10 if not otherwise specified. Which means the run order of all such callbacks is undefined. (It is apparently alphabetical by plugin name)

    You probably just need to specify a later priority like so:
    add_action('admin_menu', 'remove_menus', 50 );

    To be sure that the priority you choose is adequate, review the plugin code for similar action callbacks added to see what priority, if any, they specify, just ensure yours is higher.

    Thread Starter otti.steinhauer

    (@ottisteinhauer)

    Hello bcworkz,
    it works by setting a priority, thanks. Your answer saved me a lot of time.
    Is it possible to like your comment or give you a higher score?

    Ottilie

    Moderator bcworkz

    (@bcworkz)

    No, these forums do not support any kind of rating for members, ratings can only be applied to themes and plugins when writing a review. I appreciate the thought though ??

    @bcworkz: could you tell me how to hide yoast “SEO” in the left menu on wordpress dashboard? thanks

    Moderator bcworkz

    (@bcworkz)

    Hi @gugelgendeng. I wouldn’t know the specifics beyond use remove_menu_page() in an ‘admin_menu’ action callback. Sorry. Somewhere in the Yoast SEO plugin is a call to add_menu_page(). You need the parameters from that to be able to remove it. Like I mentioned, use a larger priority number to ensure your code runs after the plugin’s menu has already been added.

    If you have any other questions, please start a new topic. We frown on tagging on to other’s posts here. Besides preventing confusion on active threads, the Admins here collect statistics, where each person starting their own topic makes for more accurate statistics. Thanks.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Remove plugin-items from dashboard-menu’ is closed to new replies.