WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/25/2010 02:57:43 AM (9 years ago)
Author:
nacin
Message:

Introduce require_list_table(), rework get_list_table() calls, split default-list-tables into individual files. see #14579.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/class-wp-list-table.php

    r15954 r15955  
    816816 * @since 3.1.0
    817817 *
    818  * @param string $type The type of the list table
    819  * @return object
     818 * @param string $class The type of the list table, which is the class name except for core list tables.
     819 * @return object|bool Object on success, false if the class does not exist.
    820820 */
    821 function get_list_table( $type ) {
    822     require_once( ABSPATH . '/wp-admin/includes/default-list-tables.php' );
    823     // Temp
    824     require_once( ABSPATH . '/wp-admin/includes/list-table-posts.php' );
    825 
    826     $class = 'WP_' . strtr( ucwords( strtr( $type, '-', ' ') ), ' ', '_' ) . '_Table';
    827     $class = apply_filters( "get_list_table_$type", $class );
    828 
    829     return new $class;
     821function get_list_table( $class ) {
     822    $class = apply_filters( "get_list_table_$class", $class );
     823
     824    require_list_table( $class );
     825
     826    if ( class_exists( $class ) )
     827        return new $class;
     828    return false;
    830829}
    831830
     831/**
     832 * Include the proper file for a core list table.
     833 *
     834 * Useful for extending a core class that would not otherwise be required.
     835 *
     836 * @since 3.1.0
     837 *
     838 * @param string $table The core table to include.
     839 * @return bool True on success, false on failure.
     840 */
     841function require_list_table( $class ) {
     842    $core_classes = array( 'WP_Posts_Table' => 'posts', 'WP_Media_Table' => 'media', 'WP_Terms_Table' => 'terms',
     843        'WP_Users_Table' => 'users', 'WP_Comments_Table' => 'comments', 'WP_Post_Comments_Table' => 'comments',
     844        'WP_Links_Table' => 'links', 'WP_Sites_Table' => 'sites', 'WP_MS_Users_Table' => 'ms-users',
     845        'WP_Plugins_Table' => 'plugins', 'WP_Plugin_Install_Table' => 'plugin-install', 'WP_Themes_Table' => 'themes',
     846        'WP_Theme_Install_Table' => 'theme-install' );
     847
     848    if ( isset( $core_classes[ $class ] ) ) {
     849        require_once( ABSPATH . '/wp-admin/includes/list-table-' . $core_classes[ $class ] . '.php' );
     850        return true;
     851    }
     852    return false;
     853}
     854
     855?>
Note: See TracChangeset for help on using the changeset viewer.