Make WordPress Core

Changeset 35151


Ignore:
Timestamp:
10/13/2015 10:11:36 PM (9 years ago)
Author:
johnbillion
Message:

Include network-active plugins and inactive network-only plugins on the Plugins listing screen for individual sites on Multisite.

These plugins are only shown to users with the manage_network_plugins capability, which is Super Admins by default. This new feature lowers the blood pressure of Super Admins who may browse or search the Plugins listing screen of an individual site, having forgotten that a particular plugin is network-active. Showing inactive network-only plugins here also reduces friction when searching the Plugins listing screen on individual sites.

This change introduces a show_network_active_plugins filter which controls whether the network-active plugins and inactive network-only plugins are shown. This can be used to enable this functionality for regular site admininstrators, or, indeed, to disable this functionality for Super Admins.

Fixes #20104

Location:
trunk/src/wp-admin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/css/list-tables.css

    r35009 r35151  
    882882}
    883883
     884.row-actions .network_only,
     885.row-actions .network_active {
     886    color: #000;
     887}
     888
    884889tr:hover .row-actions,
    885890.mobile .row-actions,
  • trunk/src/wp-admin/includes/class-wp-plugins-list-table.php

    r34912 r35151  
    128128        }
    129129
     130        if ( ! $screen->in_admin( 'network' ) ) {
     131            $show = current_user_can( 'manage_network_plugins' );
     132            /**
     133             * Filter whether to display network-active plugins alongside plugins active for the current site.
     134             *
     135             * This also controls the display of inactive network-only plugins (plugins with
     136             * "Network: true" in the plugin header).
     137             *
     138             * Plugins cannot be network-activated or network-deactivated from this screen.
     139             *
     140             * @since 4.4.0
     141             *
     142             * @param bool $show Whether to show network-active plugins. Default is whether the current
     143             *                   user can manage network plugins (ie. a Super Admin).
     144             */
     145            $show_network_active = apply_filters( 'show_network_active_plugins', $show );
     146        }
     147
    130148        set_transient( 'plugin_slugs', array_keys( $plugins['all'] ), DAY_IN_SECONDS );
    131149
     
    169187            // Filter into individual sections
    170188            if ( is_multisite() && ! $screen->in_admin( 'network' ) && is_network_only_plugin( $plugin_file ) && ! is_plugin_active( $plugin_file ) ) {
    171                 // On the non-network screen, filter out network-only plugins as long as they're not individually activated
    172                 unset( $plugins['all'][ $plugin_file ] );
     189                if ( $show_network_active ) {
     190                    // On the non-network screen, show inactive network-only plugins if allowed
     191                    $plugins['inactive'][ $plugin_file ] = $plugin_data;
     192                } else {
     193                    // On the non-network screen, filter out network-only plugins as long as they're not individually active
     194                    unset( $plugins['all'][ $plugin_file ] );
     195                }
    173196            } elseif ( ! $screen->in_admin( 'network' ) && is_plugin_active_for_network( $plugin_file ) ) {
    174                 // On the non-network screen, filter out network activated plugins
    175                 unset( $plugins['all'][ $plugin_file ] );
     197                if ( $show_network_active ) {
     198                    // On the non-network screen, show network-active plugins if allowed
     199                    $plugins['active'][ $plugin_file ] = $plugin_data;
     200                } else {
     201                    // On the non-network screen, filter out network-active plugins
     202                    unset( $plugins['all'][ $plugin_file ] );
     203                }
    176204            } elseif ( ( ! $screen->in_admin( 'network' ) && is_plugin_active( $plugin_file ) )
    177205                || ( $screen->in_admin( 'network' ) && is_plugin_active_for_network( $plugin_file ) ) ) {
     
    488516                $description .= '<p>' . $plugin_data['Description'] . '</p>';
    489517        } else {
    490             if ( $screen->in_admin( 'network' ) )
     518            if ( $screen->in_admin( 'network' ) ) {
    491519                $is_active = is_plugin_active_for_network( $plugin_file );
    492             else
     520                $restrict_network_active = false;
     521                $restrict_network_only = false;
     522            } else {
    493523                $is_active = is_plugin_active( $plugin_file );
     524                $restrict_network_active = ( is_multisite() && is_plugin_active_for_network( $plugin_file ) );
     525                $restrict_network_only = ( is_multisite() && is_network_only_plugin( $plugin_file ) && ! $is_active );
     526            }
    494527
    495528            if ( $screen->in_admin( 'network' ) ) {
     
    510543                }
    511544            } else {
    512                 if ( $is_active ) {
     545                if ( $restrict_network_active ) {
     546                    $actions = array(
     547                        'network_active' => __( 'Network Active' ),
     548                    );
     549                } elseif ( $restrict_network_only ) {
     550                    $actions = array(
     551                        'network_only' => __( 'Network Only' ),
     552                    );
     553                } elseif ( $is_active ) {
    513554                    /* translators: %s: plugin name */
    514555                    $actions['deactivate'] = '<a href="' . wp_nonce_url( 'plugins.php?action=deactivate&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'deactivate-plugin_' . $plugin_file ) . '" aria-label="' . esc_attr( sprintf( __( 'Deactivate %s' ), $plugin_data['Name'] ) ) . '">' . __( 'Deactivate' ) . '</a>';
     
    614655        $class = $is_active ? 'active' : 'inactive';
    615656        $checkbox_id =  "checkbox_" . md5($plugin_data['Name']);
    616         if ( in_array( $status, array( 'mustuse', 'dropins' ) ) ) {
     657        if ( $restrict_network_active || $restrict_network_only || in_array( $status, array( 'mustuse', 'dropins' ) ) ) {
    617658            $checkbox = '';
    618659        } else {
Note: See TracChangeset for help on using the changeset viewer.