wp/wp-admin/includes/list-table.php
changeset 7 cf61fcea0001
parent 5 5e2f62d02dcd
child 9 177826044cd9
equal deleted inserted replaced
6:490d5cc509ed 7:cf61fcea0001
    11  * Fetch an instance of a WP_List_Table class.
    11  * Fetch an instance of a WP_List_Table class.
    12  *
    12  *
    13  * @access private
    13  * @access private
    14  * @since 3.1.0
    14  * @since 3.1.0
    15  *
    15  *
       
    16  * @global string $hook_suffix
       
    17  *
    16  * @param string $class The type of the list table, which is the class name.
    18  * @param string $class The type of the list table, which is the class name.
    17  * @param array $args Optional. Arguments to pass to the class. Accepts 'screen'.
    19  * @param array $args Optional. Arguments to pass to the class. Accepts 'screen'.
    18  * @return object|bool Object on success, false if the class does not exist.
    20  * @return object|bool Object on success, false if the class does not exist.
    19  */
    21  */
    20 function _get_list_table( $class, $args = array() ) {
    22 function _get_list_table( $class, $args = array() ) {
    23 		'WP_Posts_List_Table' => 'posts',
    25 		'WP_Posts_List_Table' => 'posts',
    24 		'WP_Media_List_Table' => 'media',
    26 		'WP_Media_List_Table' => 'media',
    25 		'WP_Terms_List_Table' => 'terms',
    27 		'WP_Terms_List_Table' => 'terms',
    26 		'WP_Users_List_Table' => 'users',
    28 		'WP_Users_List_Table' => 'users',
    27 		'WP_Comments_List_Table' => 'comments',
    29 		'WP_Comments_List_Table' => 'comments',
    28 		'WP_Post_Comments_List_Table' => 'comments',
    30 		'WP_Post_Comments_List_Table' => array( 'comments', 'post-comments' ),
    29 		'WP_Links_List_Table' => 'links',
    31 		'WP_Links_List_Table' => 'links',
    30 		'WP_Plugin_Install_List_Table' => 'plugin-install',
    32 		'WP_Plugin_Install_List_Table' => 'plugin-install',
    31 		'WP_Themes_List_Table' => 'themes',
    33 		'WP_Themes_List_Table' => 'themes',
    32 		'WP_Theme_Install_List_Table' => array( 'themes', 'theme-install' ),
    34 		'WP_Theme_Install_List_Table' => array( 'themes', 'theme-install' ),
    33 		'WP_Plugins_List_Table' => 'plugins',
    35 		'WP_Plugins_List_Table' => 'plugins',
    62  * @param string $screen The handle for the screen to add help to. This is usually the hook name returned by the add_*_page() functions.
    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.
    63  * @param array $columns An array of columns with column IDs as the keys and translated column names as the values
    65  * @param array $columns An array of columns with column IDs as the keys and translated column names as the values
    64  * @see get_column_headers(), print_column_headers(), get_hidden_columns()
    66  * @see get_column_headers(), print_column_headers(), get_hidden_columns()
    65  */
    67  */
    66 function register_column_headers($screen, $columns) {
    68 function register_column_headers($screen, $columns) {
    67 	$wp_list_table = new _WP_List_Table_Compat($screen, $columns);
    69 	new _WP_List_Table_Compat( $screen, $columns );
    68 }
    70 }
    69 
    71 
    70 /**
    72 /**
    71  * Prints column headers for a particular screen.
    73  * Prints column headers for a particular screen.
    72  *
    74  *
    73  * @since 2.7.0
    75  * @since 2.7.0
       
    76  *
       
    77  * @param string|WP_Screen $screen  The screen hook name or screen object.
       
    78  * @param bool             $with_id Whether to set the id attribute or not.
    74  */
    79  */
    75 function print_column_headers($screen, $id = true) {
    80 function print_column_headers( $screen, $with_id = true ) {
    76 	$wp_list_table = new _WP_List_Table_Compat($screen);
    81 	$wp_list_table = new _WP_List_Table_Compat($screen);
    77 
    82 
    78 	$wp_list_table->print_column_headers($id);
    83 	$wp_list_table->print_column_headers( $with_id );
    79 }
    84 }
    80 
       
    81 /**
       
    82  * Helper class to be used only by back compat functions
       
    83  *
       
    84  * @since 3.1.0
       
    85  */
       
    86 class _WP_List_Table_Compat extends WP_List_Table {
       
    87 	public $_screen;
       
    88 	public $_columns;
       
    89 
       
    90 	public function __construct( $screen, $columns = array() ) {
       
    91 		if ( is_string( $screen ) )
       
    92 			$screen = convert_to_screen( $screen );
       
    93 
       
    94 		$this->_screen = $screen;
       
    95 
       
    96 		if ( !empty( $columns ) ) {
       
    97 			$this->_columns = $columns;
       
    98 			add_filter( 'manage_' . $screen->id . '_columns', array( $this, 'get_columns' ), 0 );
       
    99 		}
       
   100 	}
       
   101 
       
   102 	protected function get_column_info() {
       
   103 		$columns = get_column_headers( $this->_screen );
       
   104 		$hidden = get_hidden_columns( $this->_screen );
       
   105 		$sortable = array();
       
   106 
       
   107 		return array( $columns, $hidden, $sortable );
       
   108 	}
       
   109 
       
   110 	public function get_columns() {
       
   111 		return $this->_columns;
       
   112 	}
       
   113 }