diff --git a/wp-admin/admin-ajax.php b/wp-admin/admin-ajax.php index d0cbae7f5..a79b1881b 100644 --- a/wp-admin/admin-ajax.php +++ b/wp-admin/admin-ajax.php @@ -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'); diff --git a/wp-admin/edit-comments.php b/wp-admin/edit-comments.php index 10a64801c..4ecc65141 100644 --- a/wp-admin/edit-comments.php +++ b/wp-admin/edit-comments.php @@ -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'] ) ) { diff --git a/wp-admin/edit-tags.php b/wp-admin/edit-tags.php index a09921004..73ad049b3 100644 --- a/wp-admin/edit-tags.php +++ b/wp-admin/edit-tags.php @@ -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; diff --git a/wp-admin/edit.php b/wp-admin/edit.php index 98387f313..6d302a530 100644 --- a/wp-admin/edit.php +++ b/wp-admin/edit.php @@ -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 diff --git a/wp-admin/includes/list-table.php b/wp-admin/includes/list-table.php index 089e24867..ffd095226 100644 --- a/wp-admin/includes/list-table.php +++ b/wp-admin/includes/list-table.php @@ -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; +} + diff --git a/wp-admin/includes/meta-boxes.php b/wp-admin/includes/meta-boxes.php index 284a2ece1..7ee3f6cf2 100644 --- a/wp-admin/includes/meta-boxes.php +++ b/wp-admin/includes/meta-boxes.php @@ -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'); ?>