Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

In my testing environment, I've got one hundred plugins. I'm more interested in seeing first the Active plugins than the complete list (All).

How can I change the default screen for the Plugins menu item?

enter image description here

share|improve this question
    
| Active Elsewhere. –  brasofilo Apr 15 '13 at 11:41

1 Answer 1

up vote 2 down vote accepted

There are two options, modify the menu link href attribute or redirect the main screen.

Modify menu

Alter the global variable $submenu. This method works for Single and Multisite.
Problem: the submenu item Installed Plugins doesn't show in bold.

add_action( 'admin_head', 'b5f_plugins_redirect_to_active' );

function b5f_plugins_redirect_to_active() 
{
    global $submenu;
    $submenu['plugins.php'][5][2] .= "?plugin_status=active";
    return;
}

Redirect page

Hook into load-plugins.php. Multisite detection is needed, but there are no UI problems.

add_action( 'load-plugins.php', 'b5f_ms_plugins_redirect_to_active' );

function b5f_ms_plugins_redirect_to_active() 
{
    // Trick, plugin_status is only false in WP default screen
    // ['action'] prevents us interfering with activation/deactivation 
    if( isset( $_GET['plugin_status'] ) || isset( $_GET['action'] ) )
        return;

    // Check for MS dashboard, redirect accordingly
    if( is_network_admin() )
        wp_redirect( network_admin_url( 'plugins.php?plugin_status=active' ) );
    else
        wp_redirect( admin_url( 'plugins.php?plugin_status=active' ) );

    exit();
}


And a couple of extras:

1) Rename the main link to Active

add_action( 'admin_menu', 'rename_submenu_item', 99 );

function rename_submenu_item() 
{
    global $submenu;
    foreach( $submenu['plugins.php'] as $key => $value )
    {
        if( in_array( 'activate_plugins', $value ) ) 
            $submenu['plugins.php'][$key][0] = __( 'Active' );
    }
}

2) Add a submenu to access All

The submenu link is hacked, as well as some jQuery printed to fix the submenus active state:

add_action( 'admin_menu', 'menu_admin_wpse_44270' );
add_action( 'admin_head-plugins.php', 'highlight_menu_item_wpse_44270' );

function menu_admin_wpse_44270() 
{
    add_submenu_page(
        'plugins.php',
        'Drafts', 
        '<span id="my-all-plugins">All</span>', 
        'edit_pages', 
        'plugins.php?plugin_status=all'
    );
}

function highlight_menu_item_wpse_44270()
{
    if( isset( $_GET['plugin_status'] ) && 'all' == $_GET['plugin_status'] )
    {       
        ?>
        <script type="text/javascript">
            jQuery(document).ready( function($) 
            {
                var reference = $('#my-all-plugins').parent().parent();
                // add highlighting to our custom submenu
                reference.addClass('current');
                //remove higlighting from the default menu
                reference.parent().find('li:nth-child(2)').removeClass('current');             
            });     
        </script>
        <?php
    }
}
share|improve this answer
    
Same technique for themes with load-theme-install.php, $_GET['tab'] and theme-install.php?tab=install. –  brasofilo Jul 13 '13 at 17:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.