wp/wp-admin/includes/list-table.php
author ymh <ymh.work@gmail.com>
Mon, 14 Oct 2019 17:39:30 +0200
changeset 7 cf61fcea0001
parent 5 5e2f62d02dcd
child 9 177826044cd9
permissions -rw-r--r--
resynchronize code repo with production
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
 * Helper functions for displaying a list of items in an ajaxified HTML table.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
 * @package WordPress
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
 * @subpackage List_Table
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
 * Fetch an instance of a WP_List_Table class.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    16
 * @global string $hook_suffix
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    17
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
 * @param string $class The type of the list table, which is the class name.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
 * @param array $args Optional. Arguments to pass to the class. Accepts 'screen'.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
 * @return object|bool Object on success, false if the class does not exist.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
function _get_list_table( $class, $args = array() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
	$core_classes = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
		//Site Admin
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
		'WP_Posts_List_Table' => 'posts',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
		'WP_Media_List_Table' => 'media',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
		'WP_Terms_List_Table' => 'terms',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
		'WP_Users_List_Table' => 'users',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
		'WP_Comments_List_Table' => 'comments',
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    30
		'WP_Post_Comments_List_Table' => array( 'comments', 'post-comments' ),
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
		'WP_Links_List_Table' => 'links',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
		'WP_Plugin_Install_List_Table' => 'plugin-install',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
		'WP_Themes_List_Table' => 'themes',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
		'WP_Theme_Install_List_Table' => array( 'themes', 'theme-install' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
		'WP_Plugins_List_Table' => 'plugins',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
		// Network Admin
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
		'WP_MS_Sites_List_Table' => 'ms-sites',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
		'WP_MS_Users_List_Table' => 'ms-users',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
		'WP_MS_Themes_List_Table' => 'ms-themes',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
	if ( isset( $core_classes[ $class ] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
		foreach ( (array) $core_classes[ $class ] as $required )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
			require_once( ABSPATH . 'wp-admin/includes/class-wp-' . $required . '-list-table.php' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
		if ( isset( $args['screen'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
			$args['screen'] = convert_to_screen( $args['screen'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
		elseif ( isset( $GLOBALS['hook_suffix'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
			$args['screen'] = get_current_screen();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
			$args['screen'] = null;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
		return new $class( $args );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
	return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
 * Register column headers for a particular screen.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
 * @since 2.7.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    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.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
 * @param array $columns An array of columns with column IDs as the keys and translated column names as the values
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
 * @see get_column_headers(), print_column_headers(), get_hidden_columns()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
function register_column_headers($screen, $columns) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    69
	new _WP_List_Table_Compat( $screen, $columns );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
 * Prints column headers for a particular screen.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
 * @since 2.7.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    76
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    77
 * @param string|WP_Screen $screen  The screen hook name or screen object.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    78
 * @param bool             $with_id Whether to set the id attribute or not.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    80
function print_column_headers( $screen, $with_id = true ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
	$wp_list_table = new _WP_List_Table_Compat($screen);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    83
	$wp_list_table->print_column_headers( $with_id );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
}