Reduce reliance on global variables in the list tables. Allow passing a screen ID to the list tables so that ajax handlers can set the needed screen.

Props nacin
fixes #21871


git-svn-id: https://develop.svn.wordpress.org/trunk@21914 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren
2012-09-19 12:43:31 +00:00
parent b4350a0424
commit 7c52a19a5a
12 changed files with 137 additions and 174 deletions
@@ -9,9 +9,14 @@
*/
class WP_Plugins_List_Table extends WP_List_Table {
function __construct() {
function __construct( $args = array() ) {
global $status, $page;
parent::__construct( array(
'plural' => 'plugins',
'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
) );
$status = 'all';
if ( isset( $_REQUEST['plugin_status'] ) && in_array( $_REQUEST['plugin_status'], array( 'active', 'inactive', 'recently_activated', 'upgrade', 'mustuse', 'dropins', 'search' ) ) )
$status = $_REQUEST['plugin_status'];
@@ -20,10 +25,6 @@ class WP_Plugins_List_Table extends WP_List_Table {
$_SERVER['REQUEST_URI'] = add_query_arg('s', stripslashes($_REQUEST['s']) );
$page = $this->get_pagenum();
parent::__construct( array(
'plural' => 'plugins',
) );
}
function get_table_classes() {
@@ -50,7 +51,7 @@ class WP_Plugins_List_Table extends WP_List_Table {
'dropins' => array()
);
$screen = get_current_screen();
$screen = $this->screen;
if ( ! is_multisite() || ( $screen->is_network && current_user_can('manage_network_plugins') ) ) {
if ( apply_filters( 'show_advanced_plugins', true, 'mustuse' ) )
@@ -91,7 +92,7 @@ class WP_Plugins_List_Table extends WP_List_Table {
|| ( $screen->is_network && is_plugin_active_for_network( $plugin_file ) ) ) {
$plugins['active'][ $plugin_file ] = $plugin_data;
} else {
if ( !$screen->is_network && isset( $recently_activated[ $plugin_file ] ) ) // Was the plugin recently activated?
if ( ! $screen->is_network && isset( $recently_activated[ $plugin_file ] ) ) // Was the plugin recently activated?
$plugins['recently_activated'][ $plugin_file ] = $plugin_data;
$plugins['inactive'][ $plugin_file ] = $plugin_data;
}
@@ -236,15 +237,13 @@ class WP_Plugins_List_Table extends WP_List_Table {
$actions = array();
$screen = get_current_screen();
if ( 'active' != $status )
$actions['activate-selected'] = $screen->is_network ? __( 'Network Activate' ) : __( 'Activate' );
$actions['activate-selected'] = $this->screen->is_network ? __( 'Network Activate' ) : __( 'Activate' );
if ( 'inactive' != $status && 'recent' != $status )
$actions['deactivate-selected'] = $screen->is_network ? __( 'Network Deactivate' ) : __( 'Deactivate' );
$actions['deactivate-selected'] = $this->screen->is_network ? __( 'Network Deactivate' ) : __( 'Deactivate' );
if ( !is_multisite() || $screen->is_network ) {
if ( !is_multisite() || $this->screen->is_network ) {
if ( current_user_can( 'update_plugins' ) )
$actions['update-selected'] = __( 'Update' );
if ( current_user_can( 'delete_plugins' ) && ( 'active' != $status ) )
@@ -271,9 +270,7 @@ class WP_Plugins_List_Table extends WP_List_Table {
echo '<div class="alignleft actions">';
$screen = get_current_screen();
if ( ! $screen->is_network && 'recently_activated' == $status )
if ( ! $this->screen->is_network && 'recently_activated' == $status )
submit_button( __( 'Clear List' ), 'small', 'clear-recent-list', false );
elseif ( 'top' == $which && 'mustuse' == $status )
echo '<p>' . sprintf( __( 'Files in the <code>%s</code> directory are executed automatically.' ), str_replace( ABSPATH, '/', WPMU_PLUGIN_DIR ) ) . '</p>';
@@ -293,9 +290,7 @@ class WP_Plugins_List_Table extends WP_List_Table {
function display_rows() {
global $status;
$screen = get_current_screen();
if ( is_multisite() && !$screen->is_network && in_array( $status, array( 'mustuse', 'dropins' ) ) )
if ( is_multisite() && ! $this->screen->is_network && in_array( $status, array( 'mustuse', 'dropins' ) ) )
return;
foreach ( $this->items as $plugin_file => $plugin_data )
@@ -306,8 +301,7 @@ class WP_Plugins_List_Table extends WP_List_Table {
global $status, $page, $s, $totals;
$context = $status;
$screen = get_current_screen();
$screen = $this->screen;
// preorder
$actions = array(