From baaf0585dd47784f5173c3569ac85f67082f988d Mon Sep 17 00:00:00 2001 From: scribu Date: Mon, 8 Nov 2010 15:43:44 +0000 Subject: [PATCH] Use get_current_screen() in list table classes. Fixes #15338 git-svn-id: https://develop.svn.wordpress.org/trunk@16235 602fd350-edb4-49c9-b593-d223f7449a82 --- .../includes/class-wp-comments-list-table.php | 1 - wp-admin/includes/class-wp-list-table.php | 29 +++++++-------- .../includes/class-wp-plugins-list-table.php | 36 +++++++++++-------- .../includes/class-wp-posts-list-table.php | 4 +-- .../includes/class-wp-terms-list-table.php | 4 ++- wp-admin/includes/deprecated.php | 34 +++++++++++------- 6 files changed, 62 insertions(+), 46 deletions(-) diff --git a/wp-admin/includes/class-wp-comments-list-table.php b/wp-admin/includes/class-wp-comments-list-table.php index d65a4e204b..51e6d61409 100644 --- a/wp-admin/includes/class-wp-comments-list-table.php +++ b/wp-admin/includes/class-wp-comments-list-table.php @@ -30,7 +30,6 @@ class WP_Comments_List_Table extends WP_List_Table { add_filter( 'comment_author', 'floated_admin_avatar' ); parent::WP_List_Table( array( - 'screen' => 'edit-comments', 'plural' => 'comments' ) ); } diff --git a/wp-admin/includes/class-wp-list-table.php b/wp-admin/includes/class-wp-list-table.php index b3299844fe..801927b1ea 100644 --- a/wp-admin/includes/class-wp-list-table.php +++ b/wp-admin/includes/class-wp-list-table.php @@ -78,21 +78,17 @@ class WP_List_Table { */ function WP_List_Table( $args = array() ) { $args = wp_parse_args( $args, array( - 'screen' => get_current_screen(), 'plural' => '', 'singular' => '', 'ajax' => true ) ); - $this->screen = $args['screen']; + $screen = get_current_screen(); - if ( is_string( $this->screen ) ) - $this->screen = convert_to_screen( $this->screen ); - - add_filter( 'manage_' . $this->screen->id . '_columns', array( &$this, 'get_columns' ), 0 ); + add_filter( "manage_{$screen->id}_columns", array( &$this, 'get_columns' ), 0 ); if ( !$args['plural'] ) - $args['plural'] = $this->screen->base; + $args['plural'] = $screen->base; $this->_args = $args; @@ -203,8 +199,10 @@ class WP_List_Table { * @access public */ function views() { + $screen = get_current_screen(); + $views = $this->get_views(); - $views = apply_filters( 'views_' . $this->screen->id, $views ); + $views = apply_filters( 'views_' . $screen->id, $views ); if ( empty( $views ) ) return; @@ -237,10 +235,11 @@ class WP_List_Table { * @access public */ function bulk_actions() { + $screen = get_current_screen(); if ( is_null( $this->_actions ) ) { $this->_actions = $this->get_bulk_actions(); - $this->_actions = apply_filters( 'bulk_actions-' . $this->screen->id, $this->_actions ); + $this->_actions = apply_filters( 'bulk_actions-' . $screen->id, $this->_actions ); $two = ''; } else { @@ -538,9 +537,11 @@ class WP_List_Table { */ function get_column_info() { if ( !isset( $this->_column_headers ) ) { - $columns = get_column_headers( $this->screen ); - $hidden = get_hidden_columns( $this->screen ); - $sortable = apply_filters( 'manage_' . $this->screen->id . '_sortable_columns', $this->get_sortable_columns() ); + $screen = get_current_screen(); + + $columns = get_column_headers( $screen ); + $hidden = get_hidden_columns( $screen ); + $sortable = apply_filters( "manage_{$screen->id}_sortable_columns", $this->get_sortable_columns() ); $this->_column_headers = array( $columns, $hidden, $sortable ); } @@ -557,7 +558,7 @@ class WP_List_Table { * @param bool $with_id Whether to set the id attribute or not */ function print_column_headers( $with_id = true ) { - $screen = $this->screen; + $screen = get_current_screen(); list( $columns, $hidden, $sortable ) = $this->get_column_info(); @@ -810,7 +811,7 @@ class WP_List_Table { function _js_vars() { $args = array( 'class' => get_class( $this ), - 'screen' => $this->screen + 'screen' => get_current_screen() ); printf( "\n", json_encode( $args ) ); diff --git a/wp-admin/includes/class-wp-plugins-list-table.php b/wp-admin/includes/class-wp-plugins-list-table.php index 326c458ffc..49db1f174f 100644 --- a/wp-admin/includes/class-wp-plugins-list-table.php +++ b/wp-admin/includes/class-wp-plugins-list-table.php @@ -57,7 +57,9 @@ class WP_Plugins_List_Table extends WP_List_Table { 'dropins' => array() ); - if ( ! is_multisite() || ( $this->screen->is_network && current_user_can('manage_network_plugins') ) ) { + $screen = get_current_screen(); + + if ( ! is_multisite() || ( $screen->is_network && current_user_can('manage_network_plugins') ) ) { if ( apply_filters( 'show_advanced_plugins', true, 'mustuse' ) ) $plugins['mustuse'] = get_mu_plugins(); if ( apply_filters( 'show_advanced_plugins', true, 'dropins' ) ) @@ -85,16 +87,16 @@ class WP_Plugins_List_Table extends WP_List_Table { foreach ( (array) $plugins['all'] as $plugin_file => $plugin_data ) { // Filter into individual sections - if ( is_plugin_active_for_network($plugin_file) && !$this->screen->is_network ) { + if ( is_plugin_active_for_network($plugin_file) && !$screen->is_network ) { unset( $plugins['all'][ $plugin_file ] ); continue; } elseif ( is_multisite() && is_network_only_plugin( $plugin_file ) && !current_user_can( 'manage_network_plugins' ) ) { $plugins['network'][ $plugin_file ] = $plugin_data; - } elseif ( ( !$this->screen->is_network && is_plugin_active( $plugin_file ) ) - || ( $this->screen->is_network && is_plugin_active_for_network( $plugin_file ) ) ) { + } elseif ( ( !$screen->is_network && is_plugin_active( $plugin_file ) ) + || ( $screen->is_network && is_plugin_active_for_network( $plugin_file ) ) ) { $plugins['active'][ $plugin_file ] = $plugin_data; } else { - if ( !$this->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; } @@ -128,7 +130,7 @@ class WP_Plugins_List_Table extends WP_List_Table { uasort( $this->items, array( &$this, '_order_callback' ) ); } - $plugins_per_page = $this->get_items_per_page( str_replace( '-', '_', "{$this->screen->id}_per_page" ) ); + $plugins_per_page = $this->get_items_per_page( str_replace( '-', '_', $screen->id . '_per_page' ) ); $start = ( $page - 1 ) * $plugins_per_page; @@ -253,15 +255,17 @@ class WP_Plugins_List_Table extends WP_List_Table { $actions = array(); + $screen = get_current_screen(); + if ( 'active' != $status ) { - $action = $this->screen->is_network ? 'network-activate-selected' : 'activate-selected'; + $action = $screen->is_network ? 'network-activate-selected' : 'activate-selected'; $actions[ $action ] = __( 'Activate' ); } if ( 'inactive' != $status && 'recent' != $status ) $actions['deactivate-selected'] = __( 'Deactivate' ); - if ( !is_multisite() || $this->screen->is_network ) { + if ( !is_multisite() || $screen->is_network ) { if ( current_user_can( 'update_plugins' ) ) $actions['update-selected'] = __( 'Update' ); if ( current_user_can( 'delete_plugins' ) && ( 'active' != $status ) ) @@ -302,6 +306,8 @@ class WP_Plugins_List_Table extends WP_List_Table { $context = $status; + $screen = get_current_screen(); + foreach ( $this->items as $plugin_file => $plugin_data ) { // preorder $actions = array( @@ -313,11 +319,11 @@ class WP_Plugins_List_Table extends WP_List_Table { ); if ( 'mustuse' == $context ) { - if ( is_multisite() && !$this->screen->is_network ) + if ( is_multisite() && !$screen->is_network ) continue; $is_active = true; } elseif ( 'dropins' == $context ) { - if ( is_multisite() && !$this->screen->is_network ) + if ( is_multisite() && !$screen->is_network ) continue; $dropins = _get_dropins(); $plugin_name = $plugin_file; @@ -337,15 +343,15 @@ class WP_Plugins_List_Table extends WP_List_Table { $description .= '

' . $plugin_data['Description'] . '

'; } else { $is_active_for_network = is_plugin_active_for_network($plugin_file); - if ( $this->screen->is_network ) + if ( $screen->is_network ) $is_active = $is_active_for_network; else $is_active = is_plugin_active( $plugin_file ); - if ( $is_active_for_network && !is_super_admin() && !$this->screen->is_network ) + if ( $is_active_for_network && !is_super_admin() && !$screen->is_network ) continue; - if ( $this->screen->is_network ) { + if ( $screen->is_network ) { if ( $is_active_for_network ) { if ( current_user_can( 'manage_network_plugins' ) ) $actions['network_deactivate'] = '' . __('Network Deactivate') . ''; @@ -359,7 +365,7 @@ class WP_Plugins_List_Table extends WP_List_Table { if ( $is_active ) { $actions['deactivate'] = '' . __('Deactivate') . ''; } else { - if ( is_network_only_plugin( $plugin_file ) && !$this->screen->is_network ) + if ( is_network_only_plugin( $plugin_file ) && !$screen->is_network ) continue; $actions['activate'] = '' . __('Activate') . ''; @@ -367,7 +373,7 @@ class WP_Plugins_List_Table extends WP_List_Table { if ( ! is_multisite() && current_user_can('delete_plugins') ) $actions['delete'] = '' . __('Delete') . ''; } // end if $is_active - } // end if $this->screen->is_network + } // end if $screen->is_network if ( current_user_can('edit_plugins') && is_writable(WP_PLUGIN_DIR . '/' . $plugin_file) ) $actions['edit'] = '' . __('Edit') . ''; diff --git a/wp-admin/includes/class-wp-posts-list-table.php b/wp-admin/includes/class-wp-posts-list-table.php index a9bb91ad28..4910294e6b 100644 --- a/wp-admin/includes/class-wp-posts-list-table.php +++ b/wp-admin/includes/class-wp-posts-list-table.php @@ -256,7 +256,7 @@ class WP_Posts_List_Table extends WP_List_Table { } function get_columns() { - $screen = $this->screen; + $screen = get_current_screen(); if ( empty( $screen ) ) $post_type = 'post'; @@ -681,7 +681,7 @@ class WP_Posts_List_Table extends WP_List_Table { function inline_edit() { global $mode; - $screen = $this->screen; + $screen = get_current_screen(); $post = get_default_post_to_edit( $screen->post_type ); $post_type_object = get_post_type_object( $screen->post_type ); diff --git a/wp-admin/includes/class-wp-terms-list-table.php b/wp-admin/includes/class-wp-terms-list-table.php index 8ece84abde..94bd6a25fe 100644 --- a/wp-admin/includes/class-wp-terms-list-table.php +++ b/wp-admin/includes/class-wp-terms-list-table.php @@ -290,7 +290,9 @@ class WP_Terms_List_Table extends WP_List_Table { } function column_default( $tag, $column_name ) { - return apply_filters( "manage_{$this->screen->taxonomy}_custom_column", '', $column_name, $tag->term_id ); + $screen = get_current_screen(); + + return apply_filters( "manage_{$screen->taxonomy}_custom_column", '', $column_name, $tag->term_id ); } /** diff --git a/wp-admin/includes/deprecated.php b/wp-admin/includes/deprecated.php index b14269b7ab..cc421e4a6a 100644 --- a/wp-admin/includes/deprecated.php +++ b/wp-admin/includes/deprecated.php @@ -703,10 +703,7 @@ function get_others_pending($user_id) { function register_column_headers($screen, $columns) { _deprecated_function( __FUNCTION__, '3.1', 'WP_List_Table' ); - global $wp_list_table; - - $wp_list_table = new _WP_List_Table_Compat($screen); - $wp_list_table->_columns = $columns; + $wp_list_table = new _WP_List_Table_Compat($screen, $columns); } /** @@ -719,23 +716,34 @@ function register_column_headers($screen, $columns) { function print_column_headers($screen, $id = true) { _deprecated_function( __FUNCTION__, '3.1', 'WP_List_Table' ); - global $wp_list_table; - if ( !is_a($wp_list_table, 'WP_List_Table') ) - $wp_list_table = new _WP_List_Table_Compat($screen); + $wp_list_table = new _WP_List_Table_Compat($screen); $wp_list_table->print_column_headers($id); } // Helper class to be used only by deprecated functions class _WP_List_Table_Compat extends WP_List_Table { + var $_screen; + var $_columns; - var $_columns = array(); + function _WP_List_Table_Compat( $screen, $columns = array() ) { + if ( is_string( $screen ) ) + $screen = convert_to_screen( $screen ); - function _WP_List_Table_Compat( $screen ) { - parent::WP_List_Table( array( - 'screen' => $screen, - 'ajax' => false - ) ); + $this->_screen = $screen; + + if ( !empty( $columns ) ) { + $this->_columns = $columns; + add_filter( 'manage_' . $screen->id . '_columns', array( &$this, 'get_columns' ), 0 ); + } + } + + function get_column_info() { + $columns = get_column_headers( $this->_screen ); + $hidden = get_hidden_columns( $this->_screen ); + $sortable = array(); + + return array( $columns, $hidden, $sortable ); } function get_columns() {