Introduce get_list_table(). See #14579

git-svn-id: http://svn.automattic.com/wordpress/trunk@15528 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
scribu 2010-08-25 00:51:44 +00:00
parent 385dbb646d
commit 75219a5110
17 changed files with 46 additions and 60 deletions

View File

@ -51,12 +51,11 @@ if ( ! is_user_logged_in() ) {
if ( isset( $_GET['action'] ) ) :
switch ( $action = $_GET['action'] ) :
case 'fetch-list' :
require_once( './includes/default-list-tables.php' );
require_once( ABSPATH . '/wp-admin/includes/default-list-tables.php' );
$class = $_GET['list_args']['class'];
if ( class_exists( $class ) ) {
global $current_screen;
$current_screen = (object) $_GET['list_args']['screen'];
$wp_list_table = new $class;
$wp_list_table->ajax_response();
@ -557,8 +556,7 @@ case 'add-tag' :
if ( isset($_POST['screen']) )
set_current_screen($_POST['screen']);
require_once( './includes/default-list-tables.php' );
$wp_list_table = new WP_Terms_Table();
$wp_list_table = get_list_table('terms');
$level = 0;
$tag_full_name = false;
@ -625,8 +623,7 @@ case 'add-comment' :
if ( !current_user_can( 'edit_posts' ) )
die('-1');
require_once( './includes/default-list-tables.php' );
$wp_list_table = new WP_Comments_Table();
$wp_list_table = get_list_table('comments');
$wp_list_table->prepare_items();
if ( !$wp_list_table->has_items() )
@ -654,8 +651,7 @@ case 'get-comments' :
if ( !current_user_can( 'edit_post', $post_ID ) )
die('-1');
require_once( './includes/default-list-tables.php' );
$wp_list_table = new WP_Comments_Table();
$wp_list_table = get_list_table('comments');
$wp_list_table->prepare_items();
if ( !$wp_list_table->has_items() )
@ -679,8 +675,7 @@ case 'get-comments' :
case 'replyto-comment' :
check_ajax_referer( $action, '_ajax_nonce-replyto-comment' );
require_once( './includes/default-list-tables.php' );
$wp_list_table = new WP_Comments_Table();
$wp_list_table = get_list_table('comments');
$comment_post_ID = (int) $_POST['comment_post_ID'];
if ( !current_user_can( 'edit_post', $comment_post_ID ) )
@ -761,8 +756,7 @@ case 'edit-comment' :
$checkbox = ( isset($_POST['checkbox']) && true == $_POST['checkbox'] ) ? 1 : 0;
$comments_listing = isset($_POST['comments_listing']) ? $_POST['comments_listing'] : '';
require_once( './includes/default-list-tables.php' );
$wp_list_table = new WP_Comments_Table();
$wp_list_table = get_list_table('comments');
ob_start();
$wp_list_table->single_row( $comment_id, $mode, $comments_listing, $checkbox );
@ -910,8 +904,7 @@ case 'add-user' :
}
$user_object = new WP_User( $user_id );
require_once( './includes/default-list-tables.php' );
$wp_list_table = new WP_Users_Table();
$wp_list_table = get_list_table('users');
$x = new WP_Ajax_Response( array(
'what' => 'user',
@ -1203,8 +1196,7 @@ case 'inline-save':
// update the post
edit_post();
require_once( './includes/default-list-tables.php' );
$wp_list_table = new WP_Posts_Table();
$wp_list_table = get_list_table('posts');
$mode = $_POST['post_view'];
$wp_list_table->display_rows( array( get_post( $_POST['post_ID'] ) ) );
@ -1214,8 +1206,7 @@ case 'inline-save':
case 'inline-save-tax':
check_ajax_referer( 'taxinlineeditnonce', '_inline_edit' );
require_once( './includes/default-list-tables.php' );
$wp_list_table = new WP_Terms_Table();
$wp_list_table = get_list_table('terms');
$wp_list_table->check_permissions('edit');

View File

@ -9,9 +9,7 @@
/** WordPress Administration Bootstrap */
require_once('./admin.php');
require_once( './includes/default-list-tables.php' );
$wp_list_table = new WP_Comments_Table;
$wp_list_table = get_list_table('comments');
$wp_list_table->check_permissions();
if ( isset( $_REQUEST['doaction'] ) || isset( $_REQUEST['doaction2'] ) || isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) ) {

View File

@ -9,9 +9,7 @@
/** WordPress Administration Bootstrap */
require_once('./admin.php');
require_once( './includes/default-list-tables.php' );
$wp_list_table = new WP_Terms_Table;
$wp_list_table = get_list_table('terms');
$wp_list_table->check_permissions();
$title = $tax->labels->name;

View File

@ -9,9 +9,7 @@
/** WordPress Administration Bootstrap */
require_once( './admin.php' );
require_once( './includes/default-list-tables.php' );
$wp_list_table = new WP_Posts_Table;
$wp_list_table = get_list_table('posts');
$wp_list_table->check_permissions();
// Back-compat for viewing comments of an entry

View File

@ -628,8 +628,9 @@ class WP_List_Table {
}
/**
* Handle an incoming ajax request ( called from admin-ajax.php )
* Handle an incoming ajax request (called from admin-ajax.php)
*
* @since 3.1.0
* @access public
*/
function ajax_response() {
@ -665,3 +666,23 @@ class WP_List_Table {
);
}
}
/**
* Fetch an instance of a WP_List_Table class
*
* @since 3.1.0
*
* @param string $type The type of the list table
* @return object
*/
function get_list_table( $type ) {
require_once( ABSPATH . '/wp-admin/includes/default-list-tables.php' );
$type = strtr( ucwords( strtr( $type, '-', ' ') ), ' ', '_' );
$class = "WP_{$type}_Table";
$class = apply_filters( "get_list_table_$type", $class );
return new $class;
}

View File

@ -462,8 +462,7 @@ function post_comment_meta_box($post) {
add_filter('manage_edit-comments_columns', 'post_comment_meta_box_thead', 8, 1);
add_filter('manage_edit-comments_sortable_columns', create_function('', 'return array();'), 8);
require_once( './includes/default-list-tables.php' );
$wp_list_table = new WP_Comments_Table;
$wp_list_table = get_list_table('comments');
?>
<table class="widefat comments-box fixed" cellspacing="0" style="display:none;">

View File

@ -293,8 +293,7 @@ function wp_comment_reply($position = '1', $checkbox = false, $mode = 'single',
return;
}
require_once( './includes/default-list-tables.php' );
$wp_list_table = new WP_Comments_Table( 'reply' );
$wp_list_table = get_list_table('comments');
$columns = $wp_list_table->get_column_headers();
$hidden = array_intersect( array_keys( $columns ), array_filter( $wp_list_table->get_hidden_columns() ) );

View File

@ -9,9 +9,7 @@
/** Load WordPress Administration Bootstrap */
require_once ('admin.php');
require_once( './includes/default-list-tables.php' );
$wp_list_table = new WP_Links_Table;
$wp_list_table = get_list_table('links');
$wp_list_table->check_permissions();
// Handle bulk deletes

View File

@ -12,9 +12,7 @@ require_once( './admin.php' );
if ( ! is_multisite() )
wp_die( __( 'Multisite support is not enabled.' ) );
require_once( '../includes/default-list-tables.php' );
$wp_list_table = new WP_Sites_Table;
$wp_list_table = get_list_table('sites');
$wp_list_table->check_permissions();
$title = __( 'Sites' );

View File

@ -9,9 +9,7 @@
require_once( './admin.php' );
require_once( '../includes/default-list-tables.php' );
$wp_list_table = new WP_MS_Users_Table;
$wp_list_table = get_list_table('ms-users');
$wp_list_table->check_permissions();
$wp_list_table->prepare_items();

View File

@ -9,9 +9,7 @@
/** WordPress Administration Bootstrap */
require_once('./admin.php');
require_once( './includes/default-list-tables.php' );
$wp_list_table = new WP_Plugin_Install_Table;
$wp_list_table = get_list_table('plugin-install');
$wp_list_table->check_permissions();
$wp_list_table->prepare_items();

View File

@ -9,9 +9,7 @@
/** WordPress Administration Bootstrap */
require_once('./admin.php');
require_once( ABSPATH . 'wp-admin/includes/default-list-tables.php' );
$wp_list_table = new WP_Plugins_Table;
$wp_list_table = get_list_table('plugins');
$wp_list_table->check_permissions();
if ( isset($_POST['clear-recent-list']) )

View File

@ -9,9 +9,7 @@
/** WordPress Administration Bootstrap */
require_once('./admin.php');
require_once( './includes/default-list-tables.php' );
$wp_list_table = new WP_Theme_Install_Table;
$wp_list_table = get_list_table('theme-install');
$wp_list_table->check_permissions();
$wp_list_table->prepare_items();

View File

@ -9,9 +9,7 @@
/** WordPress Administration Bootstrap */
require_once('./admin.php');
require_once( './includes/default-list-tables.php' );
$wp_list_table = new WP_Themes_Table;
$wp_list_table = get_list_table('themes');
$wp_list_table->check_permissions();
if ( current_user_can('switch_themes') && isset($_GET['action']) ) {

View File

@ -9,9 +9,7 @@
/** WordPress Administration Bootstrap */
require_once( './admin.php' );
require_once( './includes/default-list-tables.php' );
$wp_list_table = new WP_Media_Table;
$wp_list_table = get_list_table('media');
$wp_list_table->check_permissions();
// Handle bulk actions

View File

@ -12,9 +12,7 @@ require_once( './admin.php' );
/** WordPress Registration API */
require_once( ABSPATH . WPINC . '/registration.php');
require_once( './includes/default-list-tables.php' );
$wp_list_table = new WP_Users_Table;
$wp_list_table = get_list_table('users');
$wp_list_table->check_permissions();
$title = __('Users');