Use get_current_screen() in list table classes. Fixes #15338
git-svn-id: http://svn.automattic.com/wordpress/trunk@16235 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
2cd45b9938
commit
3d8f4b6b2e
|
@ -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'
|
||||
) );
|
||||
}
|
||||
|
|
|
@ -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( "<script type='text/javascript'>list_args = %s;</script>\n", json_encode( $args ) );
|
||||
|
|
|
@ -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 .= '<p>' . $plugin_data['Description'] . '</p>';
|
||||
} 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'] = '<a href="' . wp_nonce_url('plugins.php?action=deactivate&networkwide=1&plugin=' . $plugin_file . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'deactivate-plugin_' . $plugin_file) . '" title="' . __('Deactivate this plugin') . '">' . __('Network Deactivate') . '</a>';
|
||||
|
@ -359,7 +365,7 @@ class WP_Plugins_List_Table extends WP_List_Table {
|
|||
if ( $is_active ) {
|
||||
$actions['deactivate'] = '<a href="' . wp_nonce_url('plugins.php?action=deactivate&plugin=' . $plugin_file . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'deactivate-plugin_' . $plugin_file) . '" title="' . __('Deactivate this plugin') . '">' . __('Deactivate') . '</a>';
|
||||
} 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'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&plugin=' . $plugin_file . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'activate-plugin_' . $plugin_file) . '" title="' . __('Activate this plugin') . '" class="edit">' . __('Activate') . '</a>';
|
||||
|
@ -367,7 +373,7 @@ class WP_Plugins_List_Table extends WP_List_Table {
|
|||
if ( ! is_multisite() && current_user_can('delete_plugins') )
|
||||
$actions['delete'] = '<a href="' . wp_nonce_url('plugins.php?action=delete-selected&checked[]=' . $plugin_file . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'bulk-plugins') . '" title="' . __('Delete this plugin') . '" class="delete">' . __('Delete') . '</a>';
|
||||
} // 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'] = '<a href="plugin-editor.php?file=' . $plugin_file . '" title="' . __('Open this file in the Plugin Editor') . '" class="edit">' . __('Edit') . '</a>';
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue