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 |
* WordPress Administration Screen API. |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
* @subpackage Administration |
|
7 |
*/ |
|
8 |
||
9 |
/** |
|
10 |
* Get the column headers for a screen |
|
11 |
* |
|
12 |
* @since 2.7.0 |
|
13 |
* |
|
14 |
* @param string|WP_Screen $screen The screen you want the headers for |
|
16 | 15 |
* @return string[] The column header labels keyed by column ID. |
0 | 16 |
*/ |
17 |
function get_column_headers( $screen ) { |
|
18 | 18 |
static $column_headers = array(); |
19 |
||
9 | 20 |
if ( is_string( $screen ) ) { |
0 | 21 |
$screen = convert_to_screen( $screen ); |
9 | 22 |
} |
0 | 23 |
|
5 | 24 |
if ( ! isset( $column_headers[ $screen->id ] ) ) { |
25 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
26 |
* Filters the column headers for a list table on a specific screen. |
5 | 27 |
* |
28 |
* The dynamic portion of the hook name, `$screen->id`, refers to the |
|
29 |
* ID of a specific screen. For example, the screen ID for the Posts |
|
30 |
* list table is edit-post, so the filter for that screen would be |
|
31 |
* manage_edit-post_columns. |
|
32 |
* |
|
33 |
* @since 3.0.0 |
|
34 |
* |
|
16 | 35 |
* @param string[] $columns The column header labels keyed by column ID. |
5 | 36 |
*/ |
37 |
$column_headers[ $screen->id ] = apply_filters( "manage_{$screen->id}_columns", array() ); |
|
38 |
} |
|
0 | 39 |
|
40 |
return $column_headers[ $screen->id ]; |
|
41 |
} |
|
42 |
||
43 |
/** |
|
44 |
* Get a list of hidden columns. |
|
45 |
* |
|
46 |
* @since 2.7.0 |
|
47 |
* |
|
48 |
* @param string|WP_Screen $screen The screen you want the hidden columns for |
|
16 | 49 |
* @return string[] Array of IDs of hidden columns. |
0 | 50 |
*/ |
51 |
function get_hidden_columns( $screen ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
52 |
if ( is_string( $screen ) ) { |
0 | 53 |
$screen = convert_to_screen( $screen ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
54 |
} |
0 | 55 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
56 |
$hidden = get_user_option( 'manage' . $screen->id . 'columnshidden' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
57 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
58 |
$use_defaults = ! is_array( $hidden ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
59 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
60 |
if ( $use_defaults ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
61 |
$hidden = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
62 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
63 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
64 |
* Filters the default list of hidden columns. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
65 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
66 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
67 |
* |
16 | 68 |
* @param string[] $hidden Array of IDs of columns hidden by default. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
69 |
* @param WP_Screen $screen WP_Screen object of the current screen. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
70 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
71 |
$hidden = apply_filters( 'default_hidden_columns', $hidden, $screen ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
72 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
73 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
74 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
75 |
* Filters the list of hidden columns. |
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 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
78 |
* @since 4.4.1 Added the `use_defaults` parameter. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
79 |
* |
16 | 80 |
* @param string[] $hidden Array of IDs of hidden columns. |
81 |
* @param WP_Screen $screen WP_Screen object of the current screen. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
82 |
* @param bool $use_defaults Whether to show the default columns. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
83 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
84 |
return apply_filters( 'hidden_columns', $hidden, $screen, $use_defaults ); |
0 | 85 |
} |
86 |
||
87 |
/** |
|
88 |
* Prints the meta box preferences for screen meta. |
|
89 |
* |
|
90 |
* @since 2.7.0 |
|
91 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
92 |
* @global array $wp_meta_boxes Global meta box state. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
93 |
* |
5 | 94 |
* @param WP_Screen $screen |
0 | 95 |
*/ |
96 |
function meta_box_prefs( $screen ) { |
|
97 |
global $wp_meta_boxes; |
|
98 |
||
9 | 99 |
if ( is_string( $screen ) ) { |
0 | 100 |
$screen = convert_to_screen( $screen ); |
9 | 101 |
} |
0 | 102 |
|
9 | 103 |
if ( empty( $wp_meta_boxes[ $screen->id ] ) ) { |
0 | 104 |
return; |
9 | 105 |
} |
0 | 106 |
|
9 | 107 |
$hidden = get_hidden_meta_boxes( $screen ); |
0 | 108 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
109 |
foreach ( array_keys( $wp_meta_boxes[ $screen->id ] ) as $context ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
110 |
foreach ( array( 'high', 'core', 'default', 'low' ) as $priority ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
111 |
if ( ! isset( $wp_meta_boxes[ $screen->id ][ $context ][ $priority ] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
112 |
continue; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
113 |
} |
18 | 114 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
115 |
foreach ( $wp_meta_boxes[ $screen->id ][ $context ][ $priority ] as $box ) { |
18 | 116 |
if ( false === $box || ! $box['title'] ) { |
0 | 117 |
continue; |
9 | 118 |
} |
18 | 119 |
|
16 | 120 |
// Submit box cannot be hidden. |
121 |
if ( 'submitdiv' === $box['id'] || 'linksubmitdiv' === $box['id'] ) { |
|
0 | 122 |
continue; |
9 | 123 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
124 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
125 |
$widget_title = $box['title']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
126 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
127 |
if ( is_array( $box['args'] ) && isset( $box['args']['__widget_basename'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
128 |
$widget_title = $box['args']['__widget_basename']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
129 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
130 |
|
16 | 131 |
$is_hidden = in_array( $box['id'], $hidden, true ); |
132 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
133 |
printf( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
134 |
'<label for="%1$s-hide"><input class="hide-postbox-tog" name="%1$s-hide" type="checkbox" id="%1$s-hide" value="%1$s" %2$s />%3$s</label>', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
135 |
esc_attr( $box['id'] ), |
16 | 136 |
checked( $is_hidden, false, false ), |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
137 |
$widget_title |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
138 |
); |
0 | 139 |
} |
140 |
} |
|
141 |
} |
|
142 |
} |
|
143 |
||
144 |
/** |
|
16 | 145 |
* Gets an array of IDs of hidden meta boxes. |
0 | 146 |
* |
147 |
* @since 2.7.0 |
|
148 |
* |
|
149 |
* @param string|WP_Screen $screen Screen identifier |
|
16 | 150 |
* @return string[] IDs of hidden meta boxes. |
0 | 151 |
*/ |
152 |
function get_hidden_meta_boxes( $screen ) { |
|
9 | 153 |
if ( is_string( $screen ) ) { |
0 | 154 |
$screen = convert_to_screen( $screen ); |
9 | 155 |
} |
0 | 156 |
|
157 |
$hidden = get_user_option( "metaboxhidden_{$screen->id}" ); |
|
158 |
||
159 |
$use_defaults = ! is_array( $hidden ); |
|
160 |
||
16 | 161 |
// Hide slug boxes by default. |
0 | 162 |
if ( $use_defaults ) { |
163 |
$hidden = array(); |
|
18 | 164 |
|
16 | 165 |
if ( 'post' === $screen->base ) { |
166 |
if ( in_array( $screen->post_type, array( 'post', 'page', 'attachment' ), true ) ) { |
|
9 | 167 |
$hidden = array( 'slugdiv', 'trackbacksdiv', 'postcustom', 'postexcerpt', 'commentstatusdiv', 'commentsdiv', 'authordiv', 'revisionsdiv' ); |
168 |
} else { |
|
0 | 169 |
$hidden = array( 'slugdiv' ); |
9 | 170 |
} |
0 | 171 |
} |
5 | 172 |
|
173 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
174 |
* Filters the default list of hidden meta boxes. |
5 | 175 |
* |
176 |
* @since 3.1.0 |
|
177 |
* |
|
16 | 178 |
* @param string[] $hidden An array of IDs of meta boxes hidden by default. |
5 | 179 |
* @param WP_Screen $screen WP_Screen object of the current screen. |
180 |
*/ |
|
0 | 181 |
$hidden = apply_filters( 'default_hidden_meta_boxes', $hidden, $screen ); |
182 |
} |
|
183 |
||
5 | 184 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
185 |
* Filters the list of hidden meta boxes. |
5 | 186 |
* |
187 |
* @since 3.3.0 |
|
188 |
* |
|
16 | 189 |
* @param string[] $hidden An array of IDs of hidden meta boxes. |
5 | 190 |
* @param WP_Screen $screen WP_Screen object of the current screen. |
191 |
* @param bool $use_defaults Whether to show the default meta boxes. |
|
192 |
* Default true. |
|
193 |
*/ |
|
0 | 194 |
return apply_filters( 'hidden_meta_boxes', $hidden, $screen, $use_defaults ); |
195 |
} |
|
196 |
||
197 |
/** |
|
198 |
* Register and configure an admin screen option |
|
199 |
* |
|
200 |
* @since 3.1.0 |
|
201 |
* |
|
202 |
* @param string $option An option name. |
|
16 | 203 |
* @param mixed $args Option-dependent arguments. |
0 | 204 |
*/ |
205 |
function add_screen_option( $option, $args = array() ) { |
|
206 |
$current_screen = get_current_screen(); |
|
207 |
||
9 | 208 |
if ( ! $current_screen ) { |
0 | 209 |
return; |
9 | 210 |
} |
0 | 211 |
|
212 |
$current_screen->add_option( $option, $args ); |
|
213 |
} |
|
214 |
||
215 |
/** |
|
216 |
* Get the current screen object |
|
217 |
* |
|
218 |
* @since 3.1.0 |
|
219 |
* |
|
16 | 220 |
* @global WP_Screen $current_screen WordPress current screen object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
221 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
222 |
* @return WP_Screen|null Current screen object or null when screen not defined. |
0 | 223 |
*/ |
224 |
function get_current_screen() { |
|
225 |
global $current_screen; |
|
226 |
||
9 | 227 |
if ( ! isset( $current_screen ) ) { |
0 | 228 |
return null; |
9 | 229 |
} |
0 | 230 |
|
231 |
return $current_screen; |
|
232 |
} |
|
233 |
||
234 |
/** |
|
235 |
* Set the current screen object |
|
236 |
* |
|
237 |
* @since 3.0.0 |
|
238 |
* |
|
16 | 239 |
* @param string|WP_Screen $hook_name Optional. The hook name (also known as the hook suffix) used to determine the screen, |
240 |
* or an existing screen object. |
|
0 | 241 |
*/ |
242 |
function set_current_screen( $hook_name = '' ) { |
|
243 |
WP_Screen::get( $hook_name )->set_current_screen(); |
|
244 |
} |