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

Built from https://develop.svn.wordpress.org/trunk@35151


git-svn-id: http://core.svn.wordpress.org/trunk@35117 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
John Blackbourn 2015-10-13 22:12:25 +00:00
parent 31b40bdbb7
commit 87aa982824
6 changed files with 62 additions and 11 deletions

View File

@ -881,6 +881,11 @@ p.pagenav {
padding: 2px 0 0;
}
.row-actions .network_only,
.row-actions .network_active {
color: #000;
}
tr:hover .row-actions,
.mobile .row-actions,
.row-actions.visible,

View File

@ -881,6 +881,11 @@ p.pagenav {
padding: 2px 0 0;
}
.row-actions .network_only,
.row-actions .network_active {
color: #000;
}
tr:hover .row-actions,
.mobile .row-actions,
.row-actions.visible,

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -127,6 +127,24 @@ class WP_Plugins_List_Table extends WP_List_Table {
}
}
if ( ! $screen->in_admin( 'network' ) ) {
$show = current_user_can( 'manage_network_plugins' );
/**
* Filter whether to display network-active plugins alongside plugins active for the current site.
*
* This also controls the display of inactive network-only plugins (plugins with
* "Network: true" in the plugin header).
*
* Plugins cannot be network-activated or network-deactivated from this screen.
*
* @since 4.4.0
*
* @param bool $show Whether to show network-active plugins. Default is whether the current
* user can manage network plugins (ie. a Super Admin).
*/
$show_network_active = apply_filters( 'show_network_active_plugins', $show );
}
set_transient( 'plugin_slugs', array_keys( $plugins['all'] ), DAY_IN_SECONDS );
if ( $screen->in_admin( 'network' ) ) {
@ -168,11 +186,21 @@ class WP_Plugins_List_Table extends WP_List_Table {
// Filter into individual sections
if ( is_multisite() && ! $screen->in_admin( 'network' ) && is_network_only_plugin( $plugin_file ) && ! is_plugin_active( $plugin_file ) ) {
// On the non-network screen, filter out network-only plugins as long as they're not individually activated
unset( $plugins['all'][ $plugin_file ] );
if ( $show_network_active ) {
// On the non-network screen, show inactive network-only plugins if allowed
$plugins['inactive'][ $plugin_file ] = $plugin_data;
} else {
// On the non-network screen, filter out network-only plugins as long as they're not individually active
unset( $plugins['all'][ $plugin_file ] );
}
} elseif ( ! $screen->in_admin( 'network' ) && is_plugin_active_for_network( $plugin_file ) ) {
// On the non-network screen, filter out network activated plugins
unset( $plugins['all'][ $plugin_file ] );
if ( $show_network_active ) {
// On the non-network screen, show network-active plugins if allowed
$plugins['active'][ $plugin_file ] = $plugin_data;
} else {
// On the non-network screen, filter out network-active plugins
unset( $plugins['all'][ $plugin_file ] );
}
} elseif ( ( ! $screen->in_admin( 'network' ) && is_plugin_active( $plugin_file ) )
|| ( $screen->in_admin( 'network' ) && is_plugin_active_for_network( $plugin_file ) ) ) {
// On the non-network screen, populate the active list with plugins that are individually activated
@ -487,10 +515,15 @@ class WP_Plugins_List_Table extends WP_List_Table {
if ( $plugin_data['Description'] )
$description .= '<p>' . $plugin_data['Description'] . '</p>';
} else {
if ( $screen->in_admin( 'network' ) )
if ( $screen->in_admin( 'network' ) ) {
$is_active = is_plugin_active_for_network( $plugin_file );
else
$restrict_network_active = false;
$restrict_network_only = false;
} else {
$is_active = is_plugin_active( $plugin_file );
$restrict_network_active = ( is_multisite() && is_plugin_active_for_network( $plugin_file ) );
$restrict_network_only = ( is_multisite() && is_network_only_plugin( $plugin_file ) && ! $is_active );
}
if ( $screen->in_admin( 'network' ) ) {
if ( $is_active ) {
@ -509,7 +542,15 @@ class WP_Plugins_List_Table extends WP_List_Table {
}
}
} else {
if ( $is_active ) {
if ( $restrict_network_active ) {
$actions = array(
'network_active' => __( 'Network Active' ),
);
} elseif ( $restrict_network_only ) {
$actions = array(
'network_only' => __( 'Network Only' ),
);
} elseif ( $is_active ) {
/* translators: %s: plugin name */
$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>';
} else {
@ -613,7 +654,7 @@ class WP_Plugins_List_Table extends WP_List_Table {
$class = $is_active ? 'active' : 'inactive';
$checkbox_id = "checkbox_" . md5($plugin_data['Name']);
if ( in_array( $status, array( 'mustuse', 'dropins' ) ) ) {
if ( $restrict_network_active || $restrict_network_only || in_array( $status, array( 'mustuse', 'dropins' ) ) ) {
$checkbox = '';
} else {
$checkbox = "<label class='screen-reader-text' for='" . $checkbox_id . "' >" . sprintf( __( 'Select %s' ), $plugin_data['Name'] ) . "</label>"

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.4-alpha-35150';
$wp_version = '4.4-alpha-35151';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.