Make WordPress Core

Ticket #14579: 14579-rework-get_list_table.diff

File 14579-rework-get_list_table.diff, 11.7 KB (added by nacin, 14 years ago)

Reworks get_list_table() to conditionally include classes. Introduces require_list_table() to include core classes. Allows for plugins to prefix classes instead of by default forcing them into WP_*_Table.

  • wp-admin/users.php

     
    1212/** WordPress Registration API */
    1313require_once( ABSPATH . WPINC . '/registration.php');
    1414
    15 $wp_list_table = get_list_table('users');
     15$wp_list_table = get_list_table('Users');
    1616$wp_list_table->check_permissions();
    1717
    1818$title = __('Users');
  • wp-admin/edit-comments.php

     
    99/** WordPress Administration Bootstrap */
    1010require_once('./admin.php');
    1111
    12 $wp_list_table = get_list_table('comments');
     12$wp_list_table = get_list_table('Comments');
    1313$wp_list_table->check_permissions();
    1414
    1515$doaction = $wp_list_table->current_action();
  • wp-admin/admin-ajax.php

     
    5151if ( isset( $_GET['action'] ) ) :
    5252switch ( $action = $_GET['action'] ) :
    5353case 'fetch-list' :
    54         require_once( ABSPATH . '/wp-admin/includes/default-list-tables.php' );
    55         // Temp
    56         require_once( ABSPATH . '/wp-admin/includes/list-table-posts.php' );
    5754
    58         $class = $_GET['list_args']['class'];
     55        $wp_list_table = get_list_table( $_GET['list_args']['class'] );
     56        if ( ! $wp_list_table )
     57                die( '0' );
    5958
    60         if ( class_exists( $class ) ) {
    61                 $current_screen = (object) $_GET['list_args']['screen'];
    62                 $wp_list_table = new $class;
    63                 $wp_list_table->ajax_response();
    64         }
     59        $current_screen = (object) $_GET['list_args']['screen'];
     60        $wp_list_table->ajax_response();
    6561
    66         die('0');
    6762        break;
    6863case 'ajax-tag-search' :
    6964        if ( !current_user_can( 'edit_posts' ) )
     
    558553        if ( isset($_POST['screen']) )
    559554                set_current_screen($_POST['screen']);
    560555
    561         $wp_list_table = get_list_table('terms');
     556        $wp_list_table = get_list_table('Terms');
    562557
    563558        $level = 0;
    564559        if ( is_taxonomy_hierarchical($taxonomy) ) {
     
    622617        if ( !current_user_can( 'edit_posts' ) )
    623618                die('-1');
    624619
    625         $wp_list_table = get_list_table('comments');
     620        $wp_list_table = get_list_table('Comments');
    626621        $wp_list_table->from_ajax = true;
    627622
    628623        $wp_list_table->prepare_items();
     
    651646        if ( !current_user_can( 'edit_post', $post_ID ) )
    652647                die('-1');
    653648
    654         $wp_list_table = get_list_table('post-comments');
     649        $wp_list_table = get_list_table('Post_Comments');
    655650
    656651        $wp_list_table->prepare_items();
    657652
     
    676671case 'replyto-comment' :
    677672        check_ajax_referer( $action, '_ajax_nonce-replyto-comment' );
    678673
    679         $wp_list_table = get_list_table('comments');
     674        $wp_list_table = get_list_table('Comments');
    680675        $wp_list_table->checkbox = ( isset($_POST['checkbox']) && true == $_POST['checkbox'] ) ? 1 : 0;
    681676
    682677        $comment_post_ID = (int) $_POST['comment_post_ID'];
     
    757752        $comments_status = isset($_POST['comments_listing']) ? $_POST['comments_listing'] : '';
    758753
    759754        $checkbox = ( isset($_POST['checkbox']) && true == $_POST['checkbox'] ) ? 1 : 0;
    760         $wp_list_table = get_list_table( $checkbox ? 'comments' : 'post-comments' );
     755        $wp_list_table = get_list_table( $checkbox ? 'Comments' : 'Post_Comments' );
    761756
    762757        ob_start();
    763758                $wp_list_table->single_row( get_comment( $comment_id ) );
     
    905900        }
    906901        $user_object = new WP_User( $user_id );
    907902
    908         $wp_list_table = get_list_table('users');
     903        $wp_list_table = get_list_table('Users');
    909904
    910905        $x = new WP_Ajax_Response( array(
    911906                'what' => 'user',
     
    12041199        // update the post
    12051200        edit_post();
    12061201
    1207         $wp_list_table = get_list_table('posts');
     1202        $wp_list_table = get_list_table('Posts');
    12081203
    12091204        $mode = $_POST['post_view'];
    12101205        $wp_list_table->display_rows( array( get_post( $_POST['post_ID'] ) ) );
     
    12141209case 'inline-save-tax':
    12151210        check_ajax_referer( 'taxinlineeditnonce', '_inline_edit' );
    12161211
    1217         $wp_list_table = get_list_table('terms');
     1212        $wp_list_table = get_list_table('Terms');
    12181213
    12191214        $wp_list_table->check_permissions('edit');
    12201215
  • wp-admin/includes/class-wp-list-table.php

     
    804804
    805805                $class = get_class( $this );
    806806
     807                $core_classes = array( 'WP_Posts_Table', 'WP_Media_Table', 'WP_Terms_Table', 'WP_Users_Table',
     808                        'WP_Comments_Table', 'WP_Post_Comments_Table', 'WP_Links_Table', 'WP_Sites_Table', 'WP_MS_Users_Table',
     809                        'WP_Plugins_Table', 'WP_Plugin_Install_Table', 'WP_Themes_Table', 'WP_Theme_Install_Table' );
     810
     811                if ( in_array( $class, $core_classes ) )
     812                        $class = substr( $class, 3, -6 );
     813
    807814                printf( "<script type='text/javascript'>list_args = %s;</script>\n",
    808815                        json_encode( compact( 'screen', 'class' ) )
    809816                );
    810817        }
     818
    811819}
    812820
    813821/**
     
    815823 *
    816824 * @since 3.1.0
    817825 *
    818  * @param string $type The type of the list table
    819  * @return object
     826 * @param string $class The type of the list table, which is the class name except for core list tables.
     827 * @return object|bool Object on success, false if the class does not exist.
    820828 */
    821 function get_list_table( $type ) {
     829function get_list_table( $class ) {
    822830        require_once( ABSPATH . '/wp-admin/includes/default-list-tables.php' );
    823         // Temp
    824         require_once( ABSPATH . '/wp-admin/includes/list-table-posts.php' );
    825831
    826         $class = 'WP_' . strtr( ucwords( strtr( $type, '-', ' ') ), ' ', '_' ) . '_Table';
    827         $class = apply_filters( "get_list_table_$type", $class );
     832        if ( require_list_table( $class ) )
     833                $class = 'WP_' . $class . '_Table';
    828834
    829         return new $class;
     835        $class = apply_filters( "get_list_table_$class", $class );
     836
     837        if ( class_exists( $class ) )
     838                return new $class;
     839        return false;
    830840}
    831841
     842/**
     843 * Include the proper file for a core list table.
     844 *
     845 * Useful for extending a core class that would not otherwise be required.
     846 *
     847 * @since 3.1.0
     848 *
     849 * @param string $table The core table to include.
     850 * @return bool Whether the table is a core table.
     851 */
     852function require_list_table( $table ) {
     853        $core_tables = array( 'Posts', 'Media', 'Terms', 'Users', 'Comments', 'Post_Comments',
     854                'Links', 'Sites', 'MS_Users', 'Plugins', 'Plugin_Install', 'Themes', 'Theme_Install' );
     855        if ( in_array( $table, $core_tables ) )
     856                require_once( ABSPATH . '/wp-admin/includes/list-table-' . strtolower( str_replace( '_', '-', $table ) ) . '.php' );
     857        else
     858                return false;
     859        return true;
     860}
     861
     862?>
     863 No newline at end of file
  • wp-admin/includes/meta-boxes.php

     
    461461
    462462        wp_nonce_field( 'get-comments', 'add_comment_nonce', false );
    463463
    464         $wp_list_table = get_list_table('post-comments');
     464        $wp_list_table = get_list_table('Post_Comments');
    465465?>
    466466
    467467<table class="widefat comments-box fixed" cellspacing="0" style="display:none;">
  • wp-admin/includes/template.php

     
    329329                return;
    330330        }
    331331
    332         $wp_list_table = get_list_table('comments');
     332        $wp_list_table = get_list_table('Comments');
    333333
    334334        list ( $columns, $hidden ) = $wp_list_table->get_column_info();
    335335        $hidden = array_intersect( array_keys( $columns ), array_filter( $hidden ) );
  • wp-admin/edit-tags.php

     
    99/** WordPress Administration Bootstrap */
    1010require_once('./admin.php');
    1111
    12 $wp_list_table = get_list_table('terms');
     12$wp_list_table = get_list_table('Terms');
    1313$wp_list_table->check_permissions();
    1414
    1515$title = $tax->labels->name;
  • wp-admin/upload.php

     
    99/** WordPress Administration Bootstrap */
    1010require_once( './admin.php' );
    1111
    12 $wp_list_table = get_list_table('media');
     12$wp_list_table = get_list_table('Media');
    1313$wp_list_table->check_permissions();
    1414
    1515// Handle bulk actions
  • wp-admin/plugin-install.php

     
    99/** WordPress Administration Bootstrap */
    1010require_once('./admin.php');
    1111
    12 $wp_list_table = get_list_table('plugin-install');
     12$wp_list_table = get_list_table('Plugin_Install');
    1313$wp_list_table->check_permissions();
    1414$wp_list_table->prepare_items();
    1515
  • wp-admin/network/users.php

     
    99
    1010require_once( './admin.php' );
    1111
    12 $wp_list_table = get_list_table('ms-users');
     12$wp_list_table = get_list_table('MS_Users');
    1313$wp_list_table->check_permissions();
    1414$wp_list_table->prepare_items();
    1515
  • wp-admin/network/sites.php

     
    1212if ( ! is_multisite() )
    1313        wp_die( __( 'Multisite support is not enabled.' ) );
    1414
    15 $wp_list_table = get_list_table('sites');
     15$wp_list_table = get_list_table('Sites');
    1616$wp_list_table->check_permissions();
    1717
    1818$title = __( 'Sites' );
  • wp-admin/plugins.php

     
    99/** WordPress Administration Bootstrap */
    1010require_once('./admin.php');
    1111
    12 $wp_list_table = get_list_table('plugins');
     12$wp_list_table = get_list_table('Plugins');
    1313$wp_list_table->check_permissions();
    1414
    1515$action = $wp_list_table->current_action();
  • wp-admin/edit.php

     
    99/** WordPress Administration Bootstrap */
    1010require_once( './admin.php' );
    1111
    12 $wp_list_table = get_list_table('posts');
     12$wp_list_table = get_list_table('Posts');
    1313$wp_list_table->check_permissions();
    1414
    1515// Back-compat for viewing comments of an entry
  • wp-admin/link-manager.php

     
    99/** Load WordPress Administration Bootstrap */
    1010require_once ('admin.php');
    1111
    12 $wp_list_table = get_list_table('links');
     12$wp_list_table = get_list_table('Links');
    1313$wp_list_table->check_permissions();
    1414
    1515// Handle bulk deletes
  • wp-admin/theme-install.php

     
    99/** WordPress Administration Bootstrap */
    1010require_once('./admin.php');
    1111
    12 $wp_list_table = get_list_table('theme-install');
     12$wp_list_table = get_list_table('Theme_Install');
    1313$wp_list_table->check_permissions();
    1414$wp_list_table->prepare_items();
    1515
  • wp-admin/themes.php

     
    99/** WordPress Administration Bootstrap */
    1010require_once('./admin.php');
    1111
    12 $wp_list_table = get_list_table('themes');
     12$wp_list_table = get_list_table('Themes');
    1313$wp_list_table->check_permissions();
    1414
    1515if ( current_user_can('switch_themes') && isset($_GET['action']) ) {