|
1 <?php |
|
2 /** |
|
3 * Helper functions for displaying a list of items in an ajaxified HTML table. |
|
4 * |
|
5 * @package WordPress |
|
6 * @subpackage List_Table |
|
7 * @since 3.1.0 |
|
8 */ |
|
9 |
|
10 /** |
|
11 * Fetch an instance of a WP_List_Table class. |
|
12 * |
|
13 * @access private |
|
14 * @since 3.1.0 |
|
15 * |
|
16 * @param string $class The type of the list table, which is the class name. |
|
17 * @return object|bool Object on success, false if the class does not exist. |
|
18 */ |
|
19 function _get_list_table( $class ) { |
|
20 $core_classes = array( |
|
21 //Site Admin |
|
22 'WP_Posts_List_Table' => 'posts', |
|
23 'WP_Media_List_Table' => 'media', |
|
24 'WP_Terms_List_Table' => 'terms', |
|
25 'WP_Users_List_Table' => 'users', |
|
26 'WP_Comments_List_Table' => 'comments', |
|
27 'WP_Post_Comments_List_Table' => 'comments', |
|
28 'WP_Links_List_Table' => 'links', |
|
29 'WP_Plugin_Install_List_Table' => 'plugin-install', |
|
30 'WP_Themes_List_Table' => 'themes', |
|
31 'WP_Theme_Install_List_Table' => array( 'themes', 'theme-install' ), |
|
32 'WP_Plugins_List_Table' => 'plugins', |
|
33 // Network Admin |
|
34 'WP_MS_Sites_List_Table' => 'ms-sites', |
|
35 'WP_MS_Users_List_Table' => 'ms-users', |
|
36 'WP_MS_Themes_List_Table' => 'ms-themes', |
|
37 ); |
|
38 |
|
39 if ( isset( $core_classes[ $class ] ) ) { |
|
40 foreach ( (array) $core_classes[ $class ] as $required ) |
|
41 require_once( ABSPATH . 'wp-admin/includes/class-wp-' . $required . '-list-table.php' ); |
|
42 return new $class; |
|
43 } |
|
44 |
|
45 return false; |
|
46 } |
|
47 |
|
48 /** |
|
49 * Register column headers for a particular screen. |
|
50 * |
|
51 * @since 2.7.0 |
|
52 * |
|
53 * @param string $screen The handle for the screen to add help to. This is usually the hook name returned by the add_*_page() functions. |
|
54 * @param array $columns An array of columns with column IDs as the keys and translated column names as the values |
|
55 * @see get_column_headers(), print_column_headers(), get_hidden_columns() |
|
56 */ |
|
57 function register_column_headers($screen, $columns) { |
|
58 $wp_list_table = new _WP_List_Table_Compat($screen, $columns); |
|
59 } |
|
60 |
|
61 /** |
|
62 * Prints column headers for a particular screen. |
|
63 * |
|
64 * @since 2.7.0 |
|
65 */ |
|
66 function print_column_headers($screen, $id = true) { |
|
67 $wp_list_table = new _WP_List_Table_Compat($screen); |
|
68 |
|
69 $wp_list_table->print_column_headers($id); |
|
70 } |
|
71 |
|
72 /** |
|
73 * Helper class to be used only by back compat functions |
|
74 * |
|
75 * @since 3.1.0 |
|
76 */ |
|
77 class _WP_List_Table_Compat extends WP_List_Table { |
|
78 var $_screen; |
|
79 var $_columns; |
|
80 |
|
81 function _WP_List_Table_Compat( $screen, $columns = array() ) { |
|
82 if ( is_string( $screen ) ) |
|
83 $screen = convert_to_screen( $screen ); |
|
84 |
|
85 $this->_screen = $screen; |
|
86 |
|
87 if ( !empty( $columns ) ) { |
|
88 $this->_columns = $columns; |
|
89 add_filter( 'manage_' . $screen->id . '_columns', array( &$this, 'get_columns' ), 0 ); |
|
90 } |
|
91 } |
|
92 |
|
93 function get_column_info() { |
|
94 $columns = get_column_headers( $this->_screen ); |
|
95 $hidden = get_hidden_columns( $this->_screen ); |
|
96 $sortable = array(); |
|
97 |
|
98 return array( $columns, $hidden, $sortable ); |
|
99 } |
|
100 |
|
101 function get_columns() { |
|
102 return $this->_columns; |
|
103 } |
|
104 } |