author | ymh <ymh.work@gmail.com> |
Fri, 05 Sep 2025 18:52:52 +0200 | |
changeset 22 | 8c2e4d02f4ef |
parent 21 | 48c4eec2b7e6 |
permissions | -rw-r--r-- |
0 | 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 |
/** |
|
9 | 11 |
* Fetches an instance of a WP_List_Table class. |
0 | 12 |
* |
13 |
* @since 3.1.0 |
|
14 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
15 |
* @global string $hook_suffix |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
16 |
* |
19 | 17 |
* @param string $class_name The type of the list table, which is the class name. |
18 |
* @param array $args Optional. Arguments to pass to the class. Accepts 'screen'. |
|
18 | 19 |
* @return WP_List_Table|false List table object on success, false if the class does not exist. |
0 | 20 |
*/ |
19 | 21 |
function _get_list_table( $class_name, $args = array() ) { |
0 | 22 |
$core_classes = array( |
16 | 23 |
// Site Admin. |
24 |
'WP_Posts_List_Table' => 'posts', |
|
25 |
'WP_Media_List_Table' => 'media', |
|
26 |
'WP_Terms_List_Table' => 'terms', |
|
27 |
'WP_Users_List_Table' => 'users', |
|
28 |
'WP_Comments_List_Table' => 'comments', |
|
29 |
'WP_Post_Comments_List_Table' => array( 'comments', 'post-comments' ), |
|
30 |
'WP_Links_List_Table' => 'links', |
|
31 |
'WP_Plugin_Install_List_Table' => 'plugin-install', |
|
32 |
'WP_Themes_List_Table' => 'themes', |
|
33 |
'WP_Theme_Install_List_Table' => array( 'themes', 'theme-install' ), |
|
34 |
'WP_Plugins_List_Table' => 'plugins', |
|
18 | 35 |
'WP_Application_Passwords_List_Table' => 'application-passwords', |
16 | 36 |
|
37 |
// Network Admin. |
|
38 |
'WP_MS_Sites_List_Table' => 'ms-sites', |
|
39 |
'WP_MS_Users_List_Table' => 'ms-users', |
|
40 |
'WP_MS_Themes_List_Table' => 'ms-themes', |
|
41 |
||
42 |
// Privacy requests tables. |
|
43 |
'WP_Privacy_Data_Export_Requests_List_Table' => 'privacy-data-export-requests', |
|
44 |
'WP_Privacy_Data_Removal_Requests_List_Table' => 'privacy-data-removal-requests', |
|
0 | 45 |
); |
46 |
||
19 | 47 |
if ( isset( $core_classes[ $class_name ] ) ) { |
48 |
foreach ( (array) $core_classes[ $class_name ] as $required ) { |
|
16 | 49 |
require_once ABSPATH . 'wp-admin/includes/class-wp-' . $required . '-list-table.php'; |
9 | 50 |
} |
0 | 51 |
|
9 | 52 |
if ( isset( $args['screen'] ) ) { |
0 | 53 |
$args['screen'] = convert_to_screen( $args['screen'] ); |
9 | 54 |
} elseif ( isset( $GLOBALS['hook_suffix'] ) ) { |
0 | 55 |
$args['screen'] = get_current_screen(); |
9 | 56 |
} else { |
0 | 57 |
$args['screen'] = null; |
9 | 58 |
} |
0 | 59 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
60 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
61 |
* Filters the list table class to instantiate. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
62 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
63 |
* @since 6.1.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
64 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
65 |
* @param string $class_name The list table class to use. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
66 |
* @param array $args An array containing _get_list_table() arguments. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
67 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
68 |
$custom_class_name = apply_filters( 'wp_list_table_class_name', $class_name, $args ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
69 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
70 |
if ( is_string( $custom_class_name ) && class_exists( $custom_class_name ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
71 |
$class_name = $custom_class_name; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
72 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
73 |
|
19 | 74 |
return new $class_name( $args ); |
0 | 75 |
} |
76 |
||
77 |
return false; |
|
78 |
} |
|
79 |
||
80 |
/** |
|
81 |
* Register column headers for a particular screen. |
|
82 |
* |
|
16 | 83 |
* @see get_column_headers(), print_column_headers(), get_hidden_columns() |
84 |
* |
|
0 | 85 |
* @since 2.7.0 |
86 |
* |
|
18 | 87 |
* @param string $screen The handle for the screen to register column headers for. This is |
88 |
* usually the hook name returned by the `add_*_page()` functions. |
|
89 |
* @param string[] $columns An array of columns with column IDs as the keys and translated |
|
90 |
* column names as the values. |
|
0 | 91 |
*/ |
9 | 92 |
function register_column_headers( $screen, $columns ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
93 |
new _WP_List_Table_Compat( $screen, $columns ); |
0 | 94 |
} |
95 |
||
96 |
/** |
|
97 |
* Prints column headers for a particular screen. |
|
98 |
* |
|
99 |
* @since 2.7.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
100 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
101 |
* @param string|WP_Screen $screen The screen hook name or screen object. |
16 | 102 |
* @param bool $with_id Whether to set the ID attribute or not. |
0 | 103 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
104 |
function print_column_headers( $screen, $with_id = true ) { |
9 | 105 |
$wp_list_table = new _WP_List_Table_Compat( $screen ); |
0 | 106 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
107 |
$wp_list_table->print_column_headers( $with_id ); |
0 | 108 |
} |