The MU forums have moved to WordPress.org

PATCH: Dsader's Toggle Admin Menus Plugin (6 posts)

  1. mdgross
    Member
    Posted 15 years ago #

    The header bar at /wp-admin/includes/template.php creates a new drop down menu known as "Favorite Actions." If you're using version 2.5.1 of Toggle Admin Menus (wpmudev.org) to hide functionality it seems to miss this drop-down. I used the following code to remove "New Page" and "Upload" from the drop-down.

    <?php
    /*
    Plugin Name: Reduce Favorite Actions
    Author: Michael D. gross
    Author URI: http://www.michaeldgross.com/
    */
    
    add_filter('favorite_actions', 'reduce_favorite_actions');
    
    function reduce_favorite_actions ($actions)
    {
    	if(!is_site_admin())
    	{
    		$remove_menu_items = array('page-new.php', 'media-new.php');
    		foreach($remove_menu_items as $menu_item)
    		{
    			if(array_key_exists($menu_item, $actions))
    			{
    				unset($actions[$menu_item]);
    			}
    		}
    	}
    	return $actions;
    }
    
    /*
    var_dump of unmodified $actions
    -------------------------------
    array(5) { ["post-new.php"]=> array(2) { [0]=> string(8) "New Post" [1]=> string(10) "edit_posts" } ["edit.php?post_status=draft"]=> array(2) { [0]=> string(6) "Drafts" [1]=> string(10) "edit_posts" } ["page-new.php"]=> array(2) { [0]=> string(8) "New Page" [1]=> string(10) "edit_pages" } ["media-new.php"]=> array(2) { [0]=> string(6) "Upload" [1]=> string(12) "upload_files" } ["edit-comments.php"]=> array(2) { [0]=> string(8) "Comments" [1]=> string(17) "moderate_comments" } }
    */
    ?>
  2. dsader
    Member
    Posted 15 years ago #

    Thanks, never noticed that little menu, really.
    Try this as a companion function and I'll upload a new patch to wpmudev.org

    add_filter('favorite_actions', 'ds_reduce_favorite_actions');
    
    function ds_reduce_favorite_actions ($actions)
    {
    			$menu_perms = get_site_option( "menu_items" );
    
    if((( $menu_perms[ 'Site Administrator Gets Limited Menus?' ] != '1' ) && (is_site_admin())) )
    			return;
    
    		$remove_menu_items = array(''); // start with an empty arrary
    
    			if( $menu_perms[ 'Posts Add New' ] != '1' && current_user_can('edit_posts') ) {
    		$remove_menu_items = array('post-new.php','edit.php?post_status=draft');
    			}
    			if( $menu_perms[ 'Pages Add New' ] != '1' && current_user_can('edit_pages')) {
    		$remove_menu_items = array_merge(array('page-new.php'),$remove_menu_items); // merge the existing or empty arrays and continue
    			}
    			if( $menu_perms[ 'Media Add New' ] != '1' && current_user_can('upload_files')) {
    		$remove_menu_items = array_merge(array('media-new.php'),$remove_menu_items);
    			}
    
    			if( $menu_perms[ 'Comments' ] != '1' && current_user_can('moderate_comments')) {
    		$remove_menu_items = array_merge(array('edit-comments.php'),$remove_menu_items);
    			}
    
    		foreach($remove_menu_items as $menu_item)
    		{
    			if(array_key_exists($menu_item, $actions))
    			{
    				unset($actions[$menu_item]);
    			}
    		}
    
    	return $actions;
    }
  3. dsader
    Member
    Posted 15 years ago #

  4. mdgross
    Member
    Posted 15 years ago #

    Works great, thanks!

  5. mdgross
    Member
    Posted 15 years ago #

    I've discovered another bug in Menus 2.5.2. It appears that if a user logs in as an administrator there is a "Change Theme" button available in Dashboard->Right Now. This button does not appear for users of Editor access or below. Upon clicking the button it brings up the Themes menu and it works, even though it is disabled (unchecked) in the Menus plugin.

  6. dsader
    Member
    Posted 15 years ago #

    About line 322 of the menus plugin I commented that I though redirecting the themes.php url may be more trouble than it is worth, uncomment the redirect and see if it works for you that way you'd like.

    if( strpos($_SERVER['REQUEST_URI'], '/themes.php'))
    	wp_redirect('widgets.php'); // add the slash to keep wpmu-themes.php from redirecting as well

    BTW, I toggle the dashboard metaboxes separately, http://wpmudevorg.wordpress.com/project/meta-boxes , then add back in my own site-related dashboard metaboxes as mu-plugins.

    In my install every theme is widgetized, so widgets.php exists at all times. If you have a theme that is not widgetized, infinite redirects or 404 will occur. When themes.php is removed, widgets.php is promoted to the top of the menu. Theme authors may add submenus that will work fine as "widgets.php?page=theme_options.php" but I found that some didn't and needed fixing.

    In my install I bypass themes.php all together and use my own plugin "ds_replace_themes.php" plugin to switch themes and manage the url redirect.

About this Topic