From 76ac1c93a8b85aa7ea17641b2e8d1c20ad12a670 Mon Sep 17 00:00:00 2001 From: scribu Date: Wed, 25 Aug 2010 00:51:44 +0000 Subject: [PATCH] Introduce get_list_table(). See #14579 git-svn-id: https://develop.svn.wordpress.org/trunk@15528 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-admin/admin-ajax.php | 27 +++++++++------------------ wp-admin/edit-comments.php | 4 +--- wp-admin/edit-tags.php | 4 +--- wp-admin/edit.php | 4 +--- wp-admin/includes/list-table.php | 23 ++++++++++++++++++++++- wp-admin/includes/meta-boxes.php | 3 +-- wp-admin/includes/template.php | 3 +-- wp-admin/link-manager.php | 4 +--- wp-admin/network/admin.php | 2 +- wp-admin/network/sites.php | 4 +--- wp-admin/network/users.php | 4 +--- wp-admin/plugin-install.php | 4 +--- wp-admin/plugins.php | 4 +--- wp-admin/theme-install.php | 4 +--- wp-admin/themes.php | 4 +--- wp-admin/upload.php | 4 +--- wp-admin/users.php | 4 +--- 17 files changed, 46 insertions(+), 60 deletions(-) diff --git a/wp-admin/admin-ajax.php b/wp-admin/admin-ajax.php index d0cbae7f59..a79b1881b1 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 10a64801c9..4ecc65141b 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 a099210043..73ad049b30 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 98387f313f..6d302a5302 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 089e248677..ffd095226c 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 284a2ece1b..7ee3f6cf27 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'); ?> diff --git a/wp-admin/includes/template.php b/wp-admin/includes/template.php index 0b00c7ca85..25f6e8d20b 100644 --- a/wp-admin/includes/template.php +++ b/wp-admin/includes/template.php @@ -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() ) ); diff --git a/wp-admin/link-manager.php b/wp-admin/link-manager.php index 19455b0f78..bc118e25ef 100644 --- a/wp-admin/link-manager.php +++ b/wp-admin/link-manager.php @@ -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 diff --git a/wp-admin/network/admin.php b/wp-admin/network/admin.php index 20965be0ec..ac183e4d52 100644 --- a/wp-admin/network/admin.php +++ b/wp-admin/network/admin.php @@ -10,4 +10,4 @@ if ( ! is_multisite() ) if ( ! is_main_site() ) wp_redirect( network_admin_url() ); -?> \ No newline at end of file +?> diff --git a/wp-admin/network/sites.php b/wp-admin/network/sites.php index 97a6c0d624..818e41df91 100644 --- a/wp-admin/network/sites.php +++ b/wp-admin/network/sites.php @@ -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' ); diff --git a/wp-admin/network/users.php b/wp-admin/network/users.php index b5d49d0a1d..9a97040801 100644 --- a/wp-admin/network/users.php +++ b/wp-admin/network/users.php @@ -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(); diff --git a/wp-admin/plugin-install.php b/wp-admin/plugin-install.php index 8abbf1930b..53bf99033c 100644 --- a/wp-admin/plugin-install.php +++ b/wp-admin/plugin-install.php @@ -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(); diff --git a/wp-admin/plugins.php b/wp-admin/plugins.php index a081bf0656..089a44789a 100644 --- a/wp-admin/plugins.php +++ b/wp-admin/plugins.php @@ -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']) ) diff --git a/wp-admin/theme-install.php b/wp-admin/theme-install.php index bc1cd47ffc..2ab0892f9b 100644 --- a/wp-admin/theme-install.php +++ b/wp-admin/theme-install.php @@ -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(); diff --git a/wp-admin/themes.php b/wp-admin/themes.php index 15f5068663..0df3582323 100644 --- a/wp-admin/themes.php +++ b/wp-admin/themes.php @@ -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']) ) { diff --git a/wp-admin/upload.php b/wp-admin/upload.php index 6623288f08..7f790a9f5a 100644 --- a/wp-admin/upload.php +++ b/wp-admin/upload.php @@ -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 diff --git a/wp-admin/users.php b/wp-admin/users.php index 08c72df0ed..1d5a6fb62a 100644 --- a/wp-admin/users.php +++ b/wp-admin/users.php @@ -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');