3 * Helper functions for displaying a list of items in an ajaxified HTML table.
6 * @subpackage List_Table
11 * Fetch an instance of a WP_List_Table class.
16 * @global string $hook_suffix
18 * @param string $class The type of the list table, which is the class name.
19 * @param array $args Optional. Arguments to pass to the class. Accepts 'screen'.
20 * @return object|bool Object on success, false if the class does not exist.
22 function _get_list_table( $class, $args = array() ) {
23 $core_classes = array(
25 'WP_Posts_List_Table' => 'posts',
26 'WP_Media_List_Table' => 'media',
27 'WP_Terms_List_Table' => 'terms',
28 'WP_Users_List_Table' => 'users',
29 'WP_Comments_List_Table' => 'comments',
30 'WP_Post_Comments_List_Table' => 'comments',
31 'WP_Links_List_Table' => 'links',
32 'WP_Plugin_Install_List_Table' => 'plugin-install',
33 'WP_Themes_List_Table' => 'themes',
34 'WP_Theme_Install_List_Table' => array( 'themes', 'theme-install' ),
35 'WP_Plugins_List_Table' => 'plugins',
37 'WP_MS_Sites_List_Table' => 'ms-sites',
38 'WP_MS_Users_List_Table' => 'ms-users',
39 'WP_MS_Themes_List_Table' => 'ms-themes',
42 if ( isset( $core_classes[ $class ] ) ) {
43 foreach ( (array) $core_classes[ $class ] as $required )
44 require_once( ABSPATH . 'wp-admin/includes/class-wp-' . $required . '-list-table.php' );
46 if ( isset( $args['screen'] ) )
47 $args['screen'] = convert_to_screen( $args['screen'] );
48 elseif ( isset( $GLOBALS['hook_suffix'] ) )
49 $args['screen'] = get_current_screen();
51 $args['screen'] = null;
53 return new $class( $args );
60 * Register column headers for a particular screen.
64 * @param string $screen The handle for the screen to add help to. This is usually the hook name returned by the add_*_page() functions.
65 * @param array $columns An array of columns with column IDs as the keys and translated column names as the values
66 * @see get_column_headers(), print_column_headers(), get_hidden_columns()
68 function register_column_headers($screen, $columns) {
69 $wp_list_table = new _WP_List_Table_Compat($screen, $columns);
73 * Prints column headers for a particular screen.
77 function print_column_headers($screen, $id = true) {
78 $wp_list_table = new _WP_List_Table_Compat($screen);
80 $wp_list_table->print_column_headers($id);
84 * Helper class to be used only by back compat functions
88 class _WP_List_Table_Compat extends WP_List_Table {
92 public function __construct( $screen, $columns = array() ) {
93 if ( is_string( $screen ) )
94 $screen = convert_to_screen( $screen );
96 $this->_screen = $screen;
98 if ( !empty( $columns ) ) {
99 $this->_columns = $columns;
100 add_filter( 'manage_' . $screen->id . '_columns', array( $this, 'get_columns' ), 0 );
109 protected function get_column_info() {
110 $columns = get_column_headers( $this->_screen );
111 $hidden = get_hidden_columns( $this->_screen );
114 return array( $columns, $hidden, $sortable );
122 public function get_columns() {
123 return $this->_columns;