author | ymh <ymh.work@gmail.com> |
Fri, 05 Sep 2025 18:40:08 +0200 | |
changeset 21 | 48c4eec2b7e6 |
parent 19 | 3d72ae0968f4 |
child 22 | 8c2e4d02f4ef |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
3 |
* Theme, template, and stylesheet functions. |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
* @subpackage Theme |
|
7 |
*/ |
|
8 |
||
9 |
/** |
|
10 |
* Returns an array of WP_Theme objects based on the arguments. |
|
11 |
* |
|
12 |
* Despite advances over get_themes(), this function is quite expensive, and grows |
|
13 |
* linearly with additional themes. Stick to wp_get_theme() if possible. |
|
14 |
* |
|
15 |
* @since 3.4.0 |
|
16 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
17 |
* @global array $wp_theme_directories |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
18 |
* |
9 | 19 |
* @param array $args { |
20 |
* Optional. The search arguments. |
|
21 |
* |
|
16 | 22 |
* @type mixed $errors True to return themes with errors, false to return |
23 |
* themes without errors, null to return all themes. |
|
24 |
* Default false. |
|
25 |
* @type mixed $allowed (Multisite) True to return only allowed themes for a site. |
|
26 |
* False to return only disallowed themes for a site. |
|
27 |
* 'site' to return only site-allowed themes. |
|
28 |
* 'network' to return only network-allowed themes. |
|
29 |
* Null to return all themes. Default null. |
|
30 |
* @type int $blog_id (Multisite) The blog ID used to calculate which themes |
|
31 |
* are allowed. Default 0, synonymous for the current blog. |
|
9 | 32 |
* } |
33 |
* @return WP_Theme[] Array of WP_Theme objects. |
|
0 | 34 |
*/ |
35 |
function wp_get_themes( $args = array() ) { |
|
36 |
global $wp_theme_directories; |
|
37 |
||
9 | 38 |
$defaults = array( |
39 |
'errors' => false, |
|
40 |
'allowed' => null, |
|
41 |
'blog_id' => 0, |
|
42 |
); |
|
43 |
$args = wp_parse_args( $args, $defaults ); |
|
0 | 44 |
|
45 |
$theme_directories = search_theme_directories(); |
|
46 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
47 |
if ( is_array( $wp_theme_directories ) && count( $wp_theme_directories ) > 1 ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
48 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
49 |
* Make sure the active theme wins out, in case search_theme_directories() picks the wrong |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
50 |
* one in the case of a conflict. (Normally, last registered theme root wins.) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
51 |
*/ |
0 | 52 |
$current_theme = get_stylesheet(); |
53 |
if ( isset( $theme_directories[ $current_theme ] ) ) { |
|
54 |
$root_of_current_theme = get_raw_theme_root( $current_theme ); |
|
16 | 55 |
if ( ! in_array( $root_of_current_theme, $wp_theme_directories, true ) ) { |
0 | 56 |
$root_of_current_theme = WP_CONTENT_DIR . $root_of_current_theme; |
9 | 57 |
} |
0 | 58 |
$theme_directories[ $current_theme ]['theme_root'] = $root_of_current_theme; |
59 |
} |
|
60 |
} |
|
61 |
||
9 | 62 |
if ( empty( $theme_directories ) ) { |
0 | 63 |
return array(); |
9 | 64 |
} |
0 | 65 |
|
66 |
if ( is_multisite() && null !== $args['allowed'] ) { |
|
67 |
$allowed = $args['allowed']; |
|
9 | 68 |
if ( 'network' === $allowed ) { |
0 | 69 |
$theme_directories = array_intersect_key( $theme_directories, WP_Theme::get_allowed_on_network() ); |
9 | 70 |
} elseif ( 'site' === $allowed ) { |
0 | 71 |
$theme_directories = array_intersect_key( $theme_directories, WP_Theme::get_allowed_on_site( $args['blog_id'] ) ); |
9 | 72 |
} elseif ( $allowed ) { |
0 | 73 |
$theme_directories = array_intersect_key( $theme_directories, WP_Theme::get_allowed( $args['blog_id'] ) ); |
9 | 74 |
} else { |
0 | 75 |
$theme_directories = array_diff_key( $theme_directories, WP_Theme::get_allowed( $args['blog_id'] ) ); |
9 | 76 |
} |
0 | 77 |
} |
78 |
||
9 | 79 |
$themes = array(); |
0 | 80 |
static $_themes = array(); |
81 |
||
82 |
foreach ( $theme_directories as $theme => $theme_root ) { |
|
9 | 83 |
if ( isset( $_themes[ $theme_root['theme_root'] . '/' . $theme ] ) ) { |
0 | 84 |
$themes[ $theme ] = $_themes[ $theme_root['theme_root'] . '/' . $theme ]; |
9 | 85 |
} else { |
16 | 86 |
$themes[ $theme ] = new WP_Theme( $theme, $theme_root['theme_root'] ); |
87 |
||
88 |
$_themes[ $theme_root['theme_root'] . '/' . $theme ] = $themes[ $theme ]; |
|
9 | 89 |
} |
0 | 90 |
} |
91 |
||
92 |
if ( null !== $args['errors'] ) { |
|
93 |
foreach ( $themes as $theme => $wp_theme ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
94 |
if ( (bool) $wp_theme->errors() !== $args['errors'] ) { |
0 | 95 |
unset( $themes[ $theme ] ); |
9 | 96 |
} |
0 | 97 |
} |
98 |
} |
|
99 |
||
100 |
return $themes; |
|
101 |
} |
|
102 |
||
103 |
/** |
|
104 |
* Gets a WP_Theme object for a theme. |
|
105 |
* |
|
106 |
* @since 3.4.0 |
|
107 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
108 |
* @global array $wp_theme_directories |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
109 |
* |
19 | 110 |
* @param string $stylesheet Optional. Directory name for the theme. Defaults to active theme. |
16 | 111 |
* @param string $theme_root Optional. Absolute path of the theme root to look in. |
112 |
* If not specified, get_raw_theme_root() is used to calculate |
|
19 | 113 |
* the theme root for the $stylesheet provided (or active theme). |
16 | 114 |
* @return WP_Theme Theme object. Be sure to check the object's exists() method |
115 |
* if you need to confirm the theme's existence. |
|
0 | 116 |
*/ |
16 | 117 |
function wp_get_theme( $stylesheet = '', $theme_root = '' ) { |
0 | 118 |
global $wp_theme_directories; |
119 |
||
9 | 120 |
if ( empty( $stylesheet ) ) { |
0 | 121 |
$stylesheet = get_stylesheet(); |
9 | 122 |
} |
0 | 123 |
|
124 |
if ( empty( $theme_root ) ) { |
|
125 |
$theme_root = get_raw_theme_root( $stylesheet ); |
|
9 | 126 |
if ( false === $theme_root ) { |
0 | 127 |
$theme_root = WP_CONTENT_DIR . '/themes'; |
16 | 128 |
} elseif ( ! in_array( $theme_root, (array) $wp_theme_directories, true ) ) { |
0 | 129 |
$theme_root = WP_CONTENT_DIR . $theme_root; |
9 | 130 |
} |
0 | 131 |
} |
132 |
||
133 |
return new WP_Theme( $stylesheet, $theme_root ); |
|
134 |
} |
|
135 |
||
136 |
/** |
|
137 |
* Clears the cache held by get_theme_roots() and WP_Theme. |
|
138 |
* |
|
139 |
* @since 3.5.0 |
|
16 | 140 |
* @param bool $clear_update_cache Whether to clear the theme updates cache. |
0 | 141 |
*/ |
142 |
function wp_clean_themes_cache( $clear_update_cache = true ) { |
|
9 | 143 |
if ( $clear_update_cache ) { |
0 | 144 |
delete_site_transient( 'update_themes' ); |
9 | 145 |
} |
0 | 146 |
search_theme_directories( true ); |
9 | 147 |
foreach ( wp_get_themes( array( 'errors' => null ) ) as $theme ) { |
0 | 148 |
$theme->cache_delete(); |
9 | 149 |
} |
0 | 150 |
} |
151 |
||
152 |
/** |
|
153 |
* Whether a child theme is in use. |
|
154 |
* |
|
155 |
* @since 3.0.0 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
156 |
* @since 6.5.0 Makes use of global template variables. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
157 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
158 |
* @global string $wp_stylesheet_path Path to current theme's stylesheet directory. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
159 |
* @global string $wp_template_path Path to current theme's template directory. |
0 | 160 |
* |
16 | 161 |
* @return bool True if a child theme is in use, false otherwise. |
9 | 162 |
*/ |
0 | 163 |
function is_child_theme() { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
164 |
global $wp_stylesheet_path, $wp_template_path; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
165 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
166 |
return $wp_stylesheet_path !== $wp_template_path; |
0 | 167 |
} |
168 |
||
169 |
/** |
|
16 | 170 |
* Retrieves name of the current stylesheet. |
0 | 171 |
* |
16 | 172 |
* The theme name that is currently set as the front end theme. |
0 | 173 |
* |
16 | 174 |
* For all intents and purposes, the template name and the stylesheet name |
175 |
* are going to be the same for most cases. |
|
0 | 176 |
* |
177 |
* @since 1.5.0 |
|
178 |
* |
|
179 |
* @return string Stylesheet name. |
|
180 |
*/ |
|
181 |
function get_stylesheet() { |
|
5 | 182 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
183 |
* Filters the name of current stylesheet. |
5 | 184 |
* |
185 |
* @since 1.5.0 |
|
186 |
* |
|
187 |
* @param string $stylesheet Name of the current stylesheet. |
|
188 |
*/ |
|
189 |
return apply_filters( 'stylesheet', get_option( 'stylesheet' ) ); |
|
0 | 190 |
} |
191 |
||
192 |
/** |
|
19 | 193 |
* Retrieves stylesheet directory path for the active theme. |
0 | 194 |
* |
195 |
* @since 1.5.0 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
196 |
* @since 6.4.0 Memoizes filter execution so that it only runs once for the current theme. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
197 |
* @since 6.4.2 Memoization removed. |
0 | 198 |
* |
19 | 199 |
* @return string Path to active theme's stylesheet directory. |
0 | 200 |
*/ |
201 |
function get_stylesheet_directory() { |
|
9 | 202 |
$stylesheet = get_stylesheet(); |
203 |
$theme_root = get_theme_root( $stylesheet ); |
|
0 | 204 |
$stylesheet_dir = "$theme_root/$stylesheet"; |
205 |
||
5 | 206 |
/** |
19 | 207 |
* Filters the stylesheet directory path for the active theme. |
5 | 208 |
* |
209 |
* @since 1.5.0 |
|
210 |
* |
|
19 | 211 |
* @param string $stylesheet_dir Absolute path to the active theme. |
212 |
* @param string $stylesheet Directory name of the active theme. |
|
5 | 213 |
* @param string $theme_root Absolute path to themes directory. |
214 |
*/ |
|
0 | 215 |
return apply_filters( 'stylesheet_directory', $stylesheet_dir, $stylesheet, $theme_root ); |
216 |
} |
|
217 |
||
218 |
/** |
|
19 | 219 |
* Retrieves stylesheet directory URI for the active theme. |
0 | 220 |
* |
221 |
* @since 1.5.0 |
|
222 |
* |
|
19 | 223 |
* @return string URI to active theme's stylesheet directory. |
0 | 224 |
*/ |
225 |
function get_stylesheet_directory_uri() { |
|
9 | 226 |
$stylesheet = str_replace( '%2F', '/', rawurlencode( get_stylesheet() ) ); |
227 |
$theme_root_uri = get_theme_root_uri( $stylesheet ); |
|
0 | 228 |
$stylesheet_dir_uri = "$theme_root_uri/$stylesheet"; |
229 |
||
5 | 230 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
231 |
* Filters the stylesheet directory URI. |
5 | 232 |
* |
233 |
* @since 1.5.0 |
|
234 |
* |
|
235 |
* @param string $stylesheet_dir_uri Stylesheet directory URI. |
|
236 |
* @param string $stylesheet Name of the activated theme's directory. |
|
237 |
* @param string $theme_root_uri Themes root URI. |
|
238 |
*/ |
|
0 | 239 |
return apply_filters( 'stylesheet_directory_uri', $stylesheet_dir_uri, $stylesheet, $theme_root_uri ); |
240 |
} |
|
241 |
||
242 |
/** |
|
19 | 243 |
* Retrieves stylesheet URI for the active theme. |
0 | 244 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
245 |
* The stylesheet file name is 'style.css' which is appended to the stylesheet directory URI path. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
246 |
* See get_stylesheet_directory_uri(). |
0 | 247 |
* |
248 |
* @since 1.5.0 |
|
249 |
* |
|
19 | 250 |
* @return string URI to active theme's stylesheet. |
0 | 251 |
*/ |
252 |
function get_stylesheet_uri() { |
|
253 |
$stylesheet_dir_uri = get_stylesheet_directory_uri(); |
|
9 | 254 |
$stylesheet_uri = $stylesheet_dir_uri . '/style.css'; |
5 | 255 |
/** |
19 | 256 |
* Filters the URI of the active theme stylesheet. |
5 | 257 |
* |
258 |
* @since 1.5.0 |
|
259 |
* |
|
19 | 260 |
* @param string $stylesheet_uri Stylesheet URI for the active theme/child theme. |
261 |
* @param string $stylesheet_dir_uri Stylesheet directory URI for the active theme/child theme. |
|
5 | 262 |
*/ |
263 |
return apply_filters( 'stylesheet_uri', $stylesheet_uri, $stylesheet_dir_uri ); |
|
0 | 264 |
} |
265 |
||
266 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
267 |
* Retrieves the localized stylesheet URI. |
0 | 268 |
* |
269 |
* The stylesheet directory for the localized stylesheet files are located, by |
|
270 |
* default, in the base theme directory. The name of the locale file will be the |
|
271 |
* locale followed by '.css'. If that does not exist, then the text direction |
|
272 |
* stylesheet will be checked for existence, for example 'ltr.css'. |
|
273 |
* |
|
274 |
* The theme may change the location of the stylesheet directory by either using |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
275 |
* the {@see 'stylesheet_directory_uri'} or {@see 'locale_stylesheet_uri'} filters. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
276 |
* |
0 | 277 |
* If you want to change the location of the stylesheet files for the entire |
278 |
* WordPress workflow, then change the former. If you just have the locale in a |
|
279 |
* separate folder, then change the latter. |
|
280 |
* |
|
281 |
* @since 2.1.0 |
|
282 |
* |
|
16 | 283 |
* @global WP_Locale $wp_locale WordPress date and time locale object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
284 |
* |
19 | 285 |
* @return string URI to active theme's localized stylesheet. |
0 | 286 |
*/ |
287 |
function get_locale_stylesheet_uri() { |
|
288 |
global $wp_locale; |
|
289 |
$stylesheet_dir_uri = get_stylesheet_directory_uri(); |
|
9 | 290 |
$dir = get_stylesheet_directory(); |
291 |
$locale = get_locale(); |
|
292 |
if ( file_exists( "$dir/$locale.css" ) ) { |
|
0 | 293 |
$stylesheet_uri = "$stylesheet_dir_uri/$locale.css"; |
9 | 294 |
} elseif ( ! empty( $wp_locale->text_direction ) && file_exists( "$dir/{$wp_locale->text_direction}.css" ) ) { |
0 | 295 |
$stylesheet_uri = "$stylesheet_dir_uri/{$wp_locale->text_direction}.css"; |
9 | 296 |
} else { |
0 | 297 |
$stylesheet_uri = ''; |
9 | 298 |
} |
5 | 299 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
300 |
* Filters the localized stylesheet URI. |
5 | 301 |
* |
302 |
* @since 2.1.0 |
|
303 |
* |
|
304 |
* @param string $stylesheet_uri Localized stylesheet URI. |
|
305 |
* @param string $stylesheet_dir_uri Stylesheet directory URI. |
|
306 |
*/ |
|
307 |
return apply_filters( 'locale_stylesheet_uri', $stylesheet_uri, $stylesheet_dir_uri ); |
|
0 | 308 |
} |
309 |
||
310 |
/** |
|
19 | 311 |
* Retrieves name of the active theme. |
0 | 312 |
* |
313 |
* @since 1.5.0 |
|
314 |
* |
|
315 |
* @return string Template name. |
|
316 |
*/ |
|
317 |
function get_template() { |
|
5 | 318 |
/** |
19 | 319 |
* Filters the name of the active theme. |
5 | 320 |
* |
321 |
* @since 1.5.0 |
|
322 |
* |
|
19 | 323 |
* @param string $template active theme's directory name. |
5 | 324 |
*/ |
325 |
return apply_filters( 'template', get_option( 'template' ) ); |
|
0 | 326 |
} |
327 |
||
328 |
/** |
|
19 | 329 |
* Retrieves template directory path for the active theme. |
0 | 330 |
* |
331 |
* @since 1.5.0 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
332 |
* @since 6.4.0 Memoizes filter execution so that it only runs once for the current theme. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
333 |
* @since 6.4.1 Memoization removed. |
0 | 334 |
* |
19 | 335 |
* @return string Path to active theme's template directory. |
0 | 336 |
*/ |
337 |
function get_template_directory() { |
|
9 | 338 |
$template = get_template(); |
339 |
$theme_root = get_theme_root( $template ); |
|
0 | 340 |
$template_dir = "$theme_root/$template"; |
341 |
||
5 | 342 |
/** |
19 | 343 |
* Filters the active theme directory path. |
5 | 344 |
* |
345 |
* @since 1.5.0 |
|
346 |
* |
|
19 | 347 |
* @param string $template_dir The path of the active theme directory. |
348 |
* @param string $template Directory name of the active theme. |
|
5 | 349 |
* @param string $theme_root Absolute path to the themes directory. |
350 |
*/ |
|
0 | 351 |
return apply_filters( 'template_directory', $template_dir, $template, $theme_root ); |
352 |
} |
|
353 |
||
354 |
/** |
|
19 | 355 |
* Retrieves template directory URI for the active theme. |
0 | 356 |
* |
357 |
* @since 1.5.0 |
|
358 |
* |
|
19 | 359 |
* @return string URI to active theme's template directory. |
0 | 360 |
*/ |
361 |
function get_template_directory_uri() { |
|
9 | 362 |
$template = str_replace( '%2F', '/', rawurlencode( get_template() ) ); |
363 |
$theme_root_uri = get_theme_root_uri( $template ); |
|
0 | 364 |
$template_dir_uri = "$theme_root_uri/$template"; |
365 |
||
5 | 366 |
/** |
19 | 367 |
* Filters the active theme directory URI. |
5 | 368 |
* |
369 |
* @since 1.5.0 |
|
370 |
* |
|
19 | 371 |
* @param string $template_dir_uri The URI of the active theme directory. |
372 |
* @param string $template Directory name of the active theme. |
|
5 | 373 |
* @param string $theme_root_uri The themes root URI. |
374 |
*/ |
|
0 | 375 |
return apply_filters( 'template_directory_uri', $template_dir_uri, $template, $theme_root_uri ); |
376 |
} |
|
377 |
||
378 |
/** |
|
16 | 379 |
* Retrieves theme roots. |
0 | 380 |
* |
381 |
* @since 2.9.0 |
|
382 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
383 |
* @global array $wp_theme_directories |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
384 |
* |
16 | 385 |
* @return array|string An array of theme roots keyed by template/stylesheet |
386 |
* or a single theme root if all themes have the same root. |
|
0 | 387 |
*/ |
388 |
function get_theme_roots() { |
|
389 |
global $wp_theme_directories; |
|
390 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
391 |
if ( ! is_array( $wp_theme_directories ) || count( $wp_theme_directories ) <= 1 ) { |
0 | 392 |
return '/themes'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
393 |
} |
0 | 394 |
|
395 |
$theme_roots = get_site_transient( 'theme_roots' ); |
|
396 |
if ( false === $theme_roots ) { |
|
397 |
search_theme_directories( true ); // Regenerate the transient. |
|
398 |
$theme_roots = get_site_transient( 'theme_roots' ); |
|
399 |
} |
|
400 |
return $theme_roots; |
|
401 |
} |
|
402 |
||
403 |
/** |
|
16 | 404 |
* Registers a directory that contains themes. |
0 | 405 |
* |
406 |
* @since 2.9.0 |
|
407 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
408 |
* @global array $wp_theme_directories |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
409 |
* |
16 | 410 |
* @param string $directory Either the full filesystem path to a theme folder |
411 |
* or a folder within WP_CONTENT_DIR. |
|
412 |
* @return bool True if successfully registered a directory that contains themes, |
|
413 |
* false if the directory does not exist. |
|
0 | 414 |
*/ |
415 |
function register_theme_directory( $directory ) { |
|
416 |
global $wp_theme_directories; |
|
417 |
||
418 |
if ( ! file_exists( $directory ) ) { |
|
16 | 419 |
// Try prepending as the theme directory could be relative to the content directory. |
0 | 420 |
$directory = WP_CONTENT_DIR . '/' . $directory; |
16 | 421 |
// If this directory does not exist, return and do not register. |
5 | 422 |
if ( ! file_exists( $directory ) ) { |
0 | 423 |
return false; |
5 | 424 |
} |
0 | 425 |
} |
426 |
||
5 | 427 |
if ( ! is_array( $wp_theme_directories ) ) { |
428 |
$wp_theme_directories = array(); |
|
429 |
} |
|
430 |
||
431 |
$untrailed = untrailingslashit( $directory ); |
|
16 | 432 |
if ( ! empty( $untrailed ) && ! in_array( $untrailed, $wp_theme_directories, true ) ) { |
5 | 433 |
$wp_theme_directories[] = $untrailed; |
434 |
} |
|
0 | 435 |
|
436 |
return true; |
|
437 |
} |
|
438 |
||
439 |
/** |
|
16 | 440 |
* Searches all registered theme directories for complete and valid themes. |
0 | 441 |
* |
442 |
* @since 2.9.0 |
|
443 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
444 |
* @global array $wp_theme_directories |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
445 |
* |
16 | 446 |
* @param bool $force Optional. Whether to force a new directory scan. Default false. |
447 |
* @return array|false Valid themes found on success, false on failure. |
|
0 | 448 |
*/ |
449 |
function search_theme_directories( $force = false ) { |
|
450 |
global $wp_theme_directories; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
451 |
static $found_themes = null; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
452 |
|
9 | 453 |
if ( empty( $wp_theme_directories ) ) { |
0 | 454 |
return false; |
9 | 455 |
} |
456 |
||
457 |
if ( ! $force && isset( $found_themes ) ) { |
|
0 | 458 |
return $found_themes; |
9 | 459 |
} |
0 | 460 |
|
461 |
$found_themes = array(); |
|
462 |
||
463 |
$wp_theme_directories = (array) $wp_theme_directories; |
|
5 | 464 |
$relative_theme_roots = array(); |
0 | 465 |
|
16 | 466 |
/* |
467 |
* Set up maybe-relative, maybe-absolute array of theme directories. |
|
468 |
* We always want to return absolute, but we need to cache relative |
|
469 |
* to use in get_theme_root(). |
|
470 |
*/ |
|
0 | 471 |
foreach ( $wp_theme_directories as $theme_root ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
472 |
if ( str_starts_with( $theme_root, WP_CONTENT_DIR ) ) { |
0 | 473 |
$relative_theme_roots[ str_replace( WP_CONTENT_DIR, '', $theme_root ) ] = $theme_root; |
9 | 474 |
} else { |
0 | 475 |
$relative_theme_roots[ $theme_root ] = $theme_root; |
9 | 476 |
} |
0 | 477 |
} |
478 |
||
5 | 479 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
480 |
* Filters whether to get the cache of the registered theme directories. |
5 | 481 |
* |
482 |
* @since 3.4.0 |
|
483 |
* |
|
484 |
* @param bool $cache_expiration Whether to get the cache of the theme directories. Default false. |
|
16 | 485 |
* @param string $context The class or function name calling the filter. |
5 | 486 |
*/ |
16 | 487 |
$cache_expiration = apply_filters( 'wp_cache_themes_persistently', false, 'search_theme_directories' ); |
488 |
||
489 |
if ( $cache_expiration ) { |
|
0 | 490 |
$cached_roots = get_site_transient( 'theme_roots' ); |
491 |
if ( is_array( $cached_roots ) ) { |
|
492 |
foreach ( $cached_roots as $theme_dir => $theme_root ) { |
|
493 |
// A cached theme root is no longer around, so skip it. |
|
9 | 494 |
if ( ! isset( $relative_theme_roots[ $theme_root ] ) ) { |
0 | 495 |
continue; |
9 | 496 |
} |
0 | 497 |
$found_themes[ $theme_dir ] = array( |
498 |
'theme_file' => $theme_dir . '/style.css', |
|
499 |
'theme_root' => $relative_theme_roots[ $theme_root ], // Convert relative to absolute. |
|
500 |
); |
|
501 |
} |
|
502 |
return $found_themes; |
|
503 |
} |
|
9 | 504 |
if ( ! is_int( $cache_expiration ) ) { |
16 | 505 |
$cache_expiration = 30 * MINUTE_IN_SECONDS; |
9 | 506 |
} |
0 | 507 |
} else { |
16 | 508 |
$cache_expiration = 30 * MINUTE_IN_SECONDS; |
0 | 509 |
} |
510 |
||
511 |
/* Loop the registered theme directories and extract all themes */ |
|
512 |
foreach ( $wp_theme_directories as $theme_root ) { |
|
513 |
||
19 | 514 |
// Start with directories in the root of the active theme directory. |
0 | 515 |
$dirs = @ scandir( $theme_root ); |
516 |
if ( ! $dirs ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
517 |
wp_trigger_error( __FUNCTION__, "$theme_root is not readable" ); |
0 | 518 |
continue; |
519 |
} |
|
520 |
foreach ( $dirs as $dir ) { |
|
16 | 521 |
if ( ! is_dir( $theme_root . '/' . $dir ) || '.' === $dir[0] || 'CVS' === $dir ) { |
0 | 522 |
continue; |
9 | 523 |
} |
0 | 524 |
if ( file_exists( $theme_root . '/' . $dir . '/style.css' ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
525 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
526 |
* wp-content/themes/a-single-theme |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
527 |
* wp-content/themes is $theme_root, a-single-theme is $dir. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
528 |
*/ |
0 | 529 |
$found_themes[ $dir ] = array( |
530 |
'theme_file' => $dir . '/style.css', |
|
531 |
'theme_root' => $theme_root, |
|
532 |
); |
|
533 |
} else { |
|
534 |
$found_theme = false; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
535 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
536 |
* wp-content/themes/a-folder-of-themes/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
537 |
* wp-content/themes is $theme_root, a-folder-of-themes is $dir, then themes are $sub_dirs. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
538 |
*/ |
0 | 539 |
$sub_dirs = @ scandir( $theme_root . '/' . $dir ); |
540 |
if ( ! $sub_dirs ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
541 |
wp_trigger_error( __FUNCTION__, "$theme_root/$dir is not readable" ); |
0 | 542 |
continue; |
543 |
} |
|
544 |
foreach ( $sub_dirs as $sub_dir ) { |
|
16 | 545 |
if ( ! is_dir( $theme_root . '/' . $dir . '/' . $sub_dir ) || '.' === $dir[0] || 'CVS' === $dir ) { |
0 | 546 |
continue; |
9 | 547 |
} |
548 |
if ( ! file_exists( $theme_root . '/' . $dir . '/' . $sub_dir . '/style.css' ) ) { |
|
0 | 549 |
continue; |
9 | 550 |
} |
0 | 551 |
$found_themes[ $dir . '/' . $sub_dir ] = array( |
552 |
'theme_file' => $dir . '/' . $sub_dir . '/style.css', |
|
553 |
'theme_root' => $theme_root, |
|
554 |
); |
|
9 | 555 |
$found_theme = true; |
0 | 556 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
557 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
558 |
* Never mind the above, it's just a theme missing a style.css. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
559 |
* Return it; WP_Theme will catch the error. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
560 |
*/ |
9 | 561 |
if ( ! $found_theme ) { |
0 | 562 |
$found_themes[ $dir ] = array( |
563 |
'theme_file' => $dir . '/style.css', |
|
564 |
'theme_root' => $theme_root, |
|
565 |
); |
|
9 | 566 |
} |
0 | 567 |
} |
568 |
} |
|
569 |
} |
|
570 |
||
571 |
asort( $found_themes ); |
|
572 |
||
9 | 573 |
$theme_roots = array(); |
0 | 574 |
$relative_theme_roots = array_flip( $relative_theme_roots ); |
575 |
||
576 |
foreach ( $found_themes as $theme_dir => $theme_data ) { |
|
577 |
$theme_roots[ $theme_dir ] = $relative_theme_roots[ $theme_data['theme_root'] ]; // Convert absolute to relative. |
|
578 |
} |
|
579 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
580 |
if ( get_site_transient( 'theme_roots' ) !== $theme_roots ) { |
0 | 581 |
set_site_transient( 'theme_roots', $theme_roots, $cache_expiration ); |
9 | 582 |
} |
0 | 583 |
|
584 |
return $found_themes; |
|
585 |
} |
|
586 |
||
587 |
/** |
|
16 | 588 |
* Retrieves path to themes directory. |
0 | 589 |
* |
590 |
* Does not have trailing slash. |
|
591 |
* |
|
592 |
* @since 1.5.0 |
|
593 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
594 |
* @global array $wp_theme_directories |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
595 |
* |
16 | 596 |
* @param string $stylesheet_or_template Optional. The stylesheet or template name of the theme. |
597 |
* Default is to leverage the main theme root. |
|
598 |
* @return string Themes directory path. |
|
0 | 599 |
*/ |
16 | 600 |
function get_theme_root( $stylesheet_or_template = '' ) { |
0 | 601 |
global $wp_theme_directories; |
602 |
||
16 | 603 |
$theme_root = ''; |
604 |
||
605 |
if ( $stylesheet_or_template ) { |
|
606 |
$theme_root = get_raw_theme_root( $stylesheet_or_template ); |
|
607 |
if ( $theme_root ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
608 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
609 |
* Always prepend WP_CONTENT_DIR unless the root currently registered as a theme directory. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
610 |
* This gives relative theme roots the benefit of the doubt when things go haywire. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
611 |
*/ |
16 | 612 |
if ( ! in_array( $theme_root, (array) $wp_theme_directories, true ) ) { |
613 |
$theme_root = WP_CONTENT_DIR . $theme_root; |
|
614 |
} |
|
9 | 615 |
} |
16 | 616 |
} |
617 |
||
618 |
if ( ! $theme_root ) { |
|
0 | 619 |
$theme_root = WP_CONTENT_DIR . '/themes'; |
620 |
} |
|
621 |
||
5 | 622 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
623 |
* Filters the absolute path to the themes directory. |
5 | 624 |
* |
625 |
* @since 1.5.0 |
|
626 |
* |
|
627 |
* @param string $theme_root Absolute path to themes directory. |
|
628 |
*/ |
|
0 | 629 |
return apply_filters( 'theme_root', $theme_root ); |
630 |
} |
|
631 |
||
632 |
/** |
|
16 | 633 |
* Retrieves URI for themes directory. |
0 | 634 |
* |
635 |
* Does not have trailing slash. |
|
636 |
* |
|
637 |
* @since 1.5.0 |
|
638 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
639 |
* @global array $wp_theme_directories |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
640 |
* |
0 | 641 |
* @param string $stylesheet_or_template Optional. The stylesheet or template name of the theme. |
9 | 642 |
* Default is to leverage the main theme root. |
16 | 643 |
* @param string $theme_root Optional. The theme root for which calculations will be based, |
644 |
* preventing the need for a get_raw_theme_root() call. Default empty. |
|
645 |
* @return string Themes directory URI. |
|
0 | 646 |
*/ |
16 | 647 |
function get_theme_root_uri( $stylesheet_or_template = '', $theme_root = '' ) { |
0 | 648 |
global $wp_theme_directories; |
649 |
||
9 | 650 |
if ( $stylesheet_or_template && ! $theme_root ) { |
0 | 651 |
$theme_root = get_raw_theme_root( $stylesheet_or_template ); |
9 | 652 |
} |
0 | 653 |
|
654 |
if ( $stylesheet_or_template && $theme_root ) { |
|
16 | 655 |
if ( in_array( $theme_root, (array) $wp_theme_directories, true ) ) { |
0 | 656 |
// Absolute path. Make an educated guess. YMMV -- but note the filter below. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
657 |
if ( str_starts_with( $theme_root, WP_CONTENT_DIR ) ) { |
0 | 658 |
$theme_root_uri = content_url( str_replace( WP_CONTENT_DIR, '', $theme_root ) ); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
659 |
} elseif ( str_starts_with( $theme_root, ABSPATH ) ) { |
0 | 660 |
$theme_root_uri = site_url( str_replace( ABSPATH, '', $theme_root ) ); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
661 |
} elseif ( str_starts_with( $theme_root, WP_PLUGIN_DIR ) || str_starts_with( $theme_root, WPMU_PLUGIN_DIR ) ) { |
0 | 662 |
$theme_root_uri = plugins_url( basename( $theme_root ), $theme_root ); |
9 | 663 |
} else { |
0 | 664 |
$theme_root_uri = $theme_root; |
9 | 665 |
} |
0 | 666 |
} else { |
667 |
$theme_root_uri = content_url( $theme_root ); |
|
668 |
} |
|
669 |
} else { |
|
670 |
$theme_root_uri = content_url( 'themes' ); |
|
671 |
} |
|
672 |
||
5 | 673 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
674 |
* Filters the URI for themes directory. |
5 | 675 |
* |
676 |
* @since 1.5.0 |
|
677 |
* |
|
678 |
* @param string $theme_root_uri The URI for themes directory. |
|
679 |
* @param string $siteurl WordPress web address which is set in General Options. |
|
16 | 680 |
* @param string $stylesheet_or_template The stylesheet or template name of the theme. |
5 | 681 |
*/ |
682 |
return apply_filters( 'theme_root_uri', $theme_root_uri, get_option( 'siteurl' ), $stylesheet_or_template ); |
|
0 | 683 |
} |
684 |
||
685 |
/** |
|
16 | 686 |
* Gets the raw theme root relative to the content directory with no filters applied. |
0 | 687 |
* |
688 |
* @since 3.1.0 |
|
689 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
690 |
* @global array $wp_theme_directories |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
691 |
* |
16 | 692 |
* @param string $stylesheet_or_template The stylesheet or template name of the theme. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
693 |
* @param bool $skip_cache Optional. Whether to skip the cache. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
694 |
* Defaults to false, meaning the cache is used. |
16 | 695 |
* @return string Theme root. |
0 | 696 |
*/ |
697 |
function get_raw_theme_root( $stylesheet_or_template, $skip_cache = false ) { |
|
698 |
global $wp_theme_directories; |
|
699 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
700 |
if ( ! is_array( $wp_theme_directories ) || count( $wp_theme_directories ) <= 1 ) { |
0 | 701 |
return '/themes'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
702 |
} |
0 | 703 |
|
704 |
$theme_root = false; |
|
705 |
||
19 | 706 |
// If requesting the root for the active theme, consult options to avoid calling get_theme_roots(). |
0 | 707 |
if ( ! $skip_cache ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
708 |
if ( get_option( 'stylesheet' ) === $stylesheet_or_template ) { |
9 | 709 |
$theme_root = get_option( 'stylesheet_root' ); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
710 |
} elseif ( get_option( 'template' ) === $stylesheet_or_template ) { |
9 | 711 |
$theme_root = get_option( 'template_root' ); |
712 |
} |
|
0 | 713 |
} |
714 |
||
9 | 715 |
if ( empty( $theme_root ) ) { |
0 | 716 |
$theme_roots = get_theme_roots(); |
9 | 717 |
if ( ! empty( $theme_roots[ $stylesheet_or_template ] ) ) { |
718 |
$theme_root = $theme_roots[ $stylesheet_or_template ]; |
|
719 |
} |
|
0 | 720 |
} |
721 |
||
722 |
return $theme_root; |
|
723 |
} |
|
724 |
||
725 |
/** |
|
16 | 726 |
* Displays localized stylesheet link element. |
0 | 727 |
* |
728 |
* @since 2.1.0 |
|
729 |
*/ |
|
730 |
function locale_stylesheet() { |
|
731 |
$stylesheet = get_locale_stylesheet_uri(); |
|
9 | 732 |
if ( empty( $stylesheet ) ) { |
0 | 733 |
return; |
9 | 734 |
} |
16 | 735 |
|
736 |
$type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"'; |
|
737 |
||
738 |
printf( |
|
739 |
'<link rel="stylesheet" href="%s"%s media="screen" />', |
|
740 |
$stylesheet, |
|
741 |
$type_attr |
|
742 |
); |
|
0 | 743 |
} |
744 |
||
745 |
/** |
|
746 |
* Switches the theme. |
|
747 |
* |
|
748 |
* Accepts one argument: $stylesheet of the theme. It also accepts an additional function signature |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
749 |
* of two arguments: $template then $stylesheet. This is for backward compatibility. |
0 | 750 |
* |
751 |
* @since 2.5.0 |
|
752 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
753 |
* @global array $wp_theme_directories |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
754 |
* @global WP_Customize_Manager $wp_customize |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
755 |
* @global array $sidebars_widgets |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
756 |
* @global array $wp_registered_sidebars |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
757 |
* |
16 | 758 |
* @param string $stylesheet Stylesheet name. |
0 | 759 |
*/ |
760 |
function switch_theme( $stylesheet ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
761 |
global $wp_theme_directories, $wp_customize, $sidebars_widgets, $wp_registered_sidebars; |
0 | 762 |
|
16 | 763 |
$requirements = validate_theme_requirements( $stylesheet ); |
764 |
if ( is_wp_error( $requirements ) ) { |
|
765 |
wp_die( $requirements ); |
|
766 |
} |
|
767 |
||
5 | 768 |
$_sidebars_widgets = null; |
769 |
if ( 'wp_ajax_customize_save' === current_action() ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
770 |
$old_sidebars_widgets_data_setting = $wp_customize->get_setting( 'old_sidebars_widgets_data' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
771 |
if ( $old_sidebars_widgets_data_setting ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
772 |
$_sidebars_widgets = $wp_customize->post_value( $old_sidebars_widgets_data_setting ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
773 |
} |
5 | 774 |
} elseif ( is_array( $sidebars_widgets ) ) { |
775 |
$_sidebars_widgets = $sidebars_widgets; |
|
776 |
} |
|
777 |
||
778 |
if ( is_array( $_sidebars_widgets ) ) { |
|
9 | 779 |
set_theme_mod( |
780 |
'sidebars_widgets', |
|
781 |
array( |
|
782 |
'time' => time(), |
|
783 |
'data' => $_sidebars_widgets, |
|
784 |
) |
|
785 |
); |
|
5 | 786 |
} |
0 | 787 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
788 |
$nav_menu_locations = get_theme_mod( 'nav_menu_locations' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
789 |
update_option( 'theme_switch_menu_locations', $nav_menu_locations ); |
0 | 790 |
|
791 |
if ( func_num_args() > 1 ) { |
|
792 |
$stylesheet = func_get_arg( 1 ); |
|
793 |
} |
|
794 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
795 |
$old_theme = wp_get_theme(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
796 |
$new_theme = wp_get_theme( $stylesheet ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
797 |
$template = $new_theme->get_template(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
798 |
|
9 | 799 |
if ( wp_is_recovery_mode() ) { |
800 |
$paused_themes = wp_paused_themes(); |
|
801 |
$paused_themes->delete( $old_theme->get_stylesheet() ); |
|
802 |
$paused_themes->delete( $old_theme->get_template() ); |
|
803 |
} |
|
804 |
||
0 | 805 |
update_option( 'template', $template ); |
806 |
update_option( 'stylesheet', $stylesheet ); |
|
807 |
||
808 |
if ( count( $wp_theme_directories ) > 1 ) { |
|
809 |
update_option( 'template_root', get_raw_theme_root( $template, true ) ); |
|
810 |
update_option( 'stylesheet_root', get_raw_theme_root( $stylesheet, true ) ); |
|
811 |
} else { |
|
812 |
delete_option( 'template_root' ); |
|
813 |
delete_option( 'stylesheet_root' ); |
|
814 |
} |
|
815 |
||
9 | 816 |
$new_name = $new_theme->get( 'Name' ); |
0 | 817 |
|
818 |
update_option( 'current_theme', $new_name ); |
|
819 |
||
5 | 820 |
// Migrate from the old mods_{name} option to theme_mods_{slug}. |
0 | 821 |
if ( is_admin() && false === get_option( 'theme_mods_' . $stylesheet ) ) { |
822 |
$default_theme_mods = (array) get_option( 'mods_' . $new_name ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
823 |
if ( ! empty( $nav_menu_locations ) && empty( $default_theme_mods['nav_menu_locations'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
824 |
$default_theme_mods['nav_menu_locations'] = $nav_menu_locations; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
825 |
} |
0 | 826 |
add_option( "theme_mods_$stylesheet", $default_theme_mods ); |
5 | 827 |
} else { |
828 |
/* |
|
829 |
* Since retrieve_widgets() is called when initializing a theme in the Customizer, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
830 |
* we need to remove the theme mods to avoid overwriting changes made via |
5 | 831 |
* the Customizer when accessing wp-admin/widgets.php. |
832 |
*/ |
|
833 |
if ( 'wp_ajax_customize_save' === current_action() ) { |
|
834 |
remove_theme_mod( 'sidebars_widgets' ); |
|
835 |
} |
|
0 | 836 |
} |
837 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
838 |
// Stores classic sidebars for later use by block themes. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
839 |
if ( $new_theme->is_block_theme() ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
840 |
set_theme_mod( 'wp_classic_sidebars', $wp_registered_sidebars ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
841 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
842 |
|
0 | 843 |
update_option( 'theme_switched', $old_theme->get_stylesheet() ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
844 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
845 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
846 |
* Reset template globals when switching themes outside of a switched blog |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
847 |
* context to ensure templates will be loaded from the new theme. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
848 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
849 |
if ( ! is_multisite() || ! ms_is_switched() ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
850 |
wp_set_template_globals(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
851 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
852 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
853 |
// Clear pattern caches. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
854 |
if ( ! is_multisite() ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
855 |
$new_theme->delete_pattern_cache(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
856 |
$old_theme->delete_pattern_cache(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
857 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
858 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
859 |
// Set autoload=no for the old theme, autoload=yes for the switched theme. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
860 |
$theme_mods_options = array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
861 |
'theme_mods_' . $stylesheet => 'yes', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
862 |
'theme_mods_' . $old_theme->get_stylesheet() => 'no', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
863 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
864 |
wp_set_option_autoload_values( $theme_mods_options ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
865 |
|
5 | 866 |
/** |
867 |
* Fires after the theme is switched. |
|
868 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
869 |
* See {@see 'after_switch_theme'}. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
870 |
* |
5 | 871 |
* @since 1.5.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
872 |
* @since 4.5.0 Introduced the `$old_theme` parameter. |
5 | 873 |
* |
874 |
* @param string $new_name Name of the new theme. |
|
875 |
* @param WP_Theme $new_theme WP_Theme instance of the new theme. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
876 |
* @param WP_Theme $old_theme WP_Theme instance of the old theme. |
5 | 877 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
878 |
do_action( 'switch_theme', $new_name, $new_theme, $old_theme ); |
0 | 879 |
} |
880 |
||
881 |
/** |
|
19 | 882 |
* Checks that the active theme has the required files. |
883 |
* |
|
884 |
* Standalone themes need to have a `templates/index.html` or `index.php` template file. |
|
885 |
* Child themes need to have a `Template` header in the `style.css` stylesheet. |
|
0 | 886 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
887 |
* Does not initially check the default theme, which is the fallback and should always exist. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
888 |
* But if it doesn't exist, it'll fall back to the latest core default theme that does exist. |
19 | 889 |
* Will switch theme to the fallback theme if active theme does not validate. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
890 |
* |
16 | 891 |
* You can use the {@see 'validate_current_theme'} filter to return false to disable |
892 |
* this functionality. |
|
0 | 893 |
* |
894 |
* @since 1.5.0 |
|
19 | 895 |
* @since 6.0.0 Removed the requirement for block themes to have an `index.php` template. |
16 | 896 |
* |
0 | 897 |
* @see WP_DEFAULT_THEME |
898 |
* |
|
899 |
* @return bool |
|
900 |
*/ |
|
901 |
function validate_current_theme() { |
|
5 | 902 |
/** |
19 | 903 |
* Filters whether to validate the active theme. |
5 | 904 |
* |
905 |
* @since 2.7.0 |
|
906 |
* |
|
19 | 907 |
* @param bool $validate Whether to validate the active theme. Default true. |
5 | 908 |
*/ |
9 | 909 |
if ( wp_installing() || ! apply_filters( 'validate_current_theme', true ) ) { |
0 | 910 |
return true; |
9 | 911 |
} |
0 | 912 |
|
19 | 913 |
if ( |
914 |
! file_exists( get_template_directory() . '/templates/index.html' ) |
|
915 |
&& ! file_exists( get_template_directory() . '/block-templates/index.html' ) // Deprecated path support since 5.9.0. |
|
916 |
&& ! file_exists( get_template_directory() . '/index.php' ) |
|
917 |
) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
918 |
// Invalid. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
919 |
} elseif ( ! file_exists( get_template_directory() . '/style.css' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
920 |
// Invalid. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
921 |
} elseif ( is_child_theme() && ! file_exists( get_stylesheet_directory() . '/style.css' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
922 |
// Invalid. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
923 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
924 |
// Valid. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
925 |
return true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
926 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
927 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
928 |
$default = wp_get_theme( WP_DEFAULT_THEME ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
929 |
if ( $default->exists() ) { |
0 | 930 |
switch_theme( WP_DEFAULT_THEME ); |
931 |
return false; |
|
932 |
} |
|
933 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
934 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
935 |
* If we're in an invalid state but WP_DEFAULT_THEME doesn't exist, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
936 |
* switch to the latest core default theme that's installed. |
16 | 937 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
938 |
* If it turns out that this latest core default theme is our current |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
939 |
* theme, then there's nothing we can do about that, so we have to bail, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
940 |
* rather than going into an infinite loop. (This is why there are |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
941 |
* checks against WP_DEFAULT_THEME above, also.) We also can't do anything |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
942 |
* if it turns out there is no default theme installed. (That's `false`.) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
943 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
944 |
$default = WP_Theme::get_core_default_theme(); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
945 |
if ( false === $default || get_stylesheet() === $default->get_stylesheet() ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
946 |
return true; |
0 | 947 |
} |
948 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
949 |
switch_theme( $default->get_stylesheet() ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
950 |
return false; |
0 | 951 |
} |
952 |
||
953 |
/** |
|
16 | 954 |
* Validates the theme requirements for WordPress version and PHP version. |
955 |
* |
|
956 |
* Uses the information from `Requires at least` and `Requires PHP` headers |
|
957 |
* defined in the theme's `style.css` file. |
|
958 |
* |
|
959 |
* @since 5.5.0 |
|
18 | 960 |
* @since 5.8.0 Removed support for using `readme.txt` as a fallback. |
16 | 961 |
* |
962 |
* @param string $stylesheet Directory name for the theme. |
|
963 |
* @return true|WP_Error True if requirements are met, WP_Error on failure. |
|
964 |
*/ |
|
965 |
function validate_theme_requirements( $stylesheet ) { |
|
966 |
$theme = wp_get_theme( $stylesheet ); |
|
967 |
||
968 |
$requirements = array( |
|
969 |
'requires' => ! empty( $theme->get( 'RequiresWP' ) ) ? $theme->get( 'RequiresWP' ) : '', |
|
970 |
'requires_php' => ! empty( $theme->get( 'RequiresPHP' ) ) ? $theme->get( 'RequiresPHP' ) : '', |
|
971 |
); |
|
972 |
||
973 |
$compatible_wp = is_wp_version_compatible( $requirements['requires'] ); |
|
974 |
$compatible_php = is_php_version_compatible( $requirements['requires_php'] ); |
|
975 |
||
976 |
if ( ! $compatible_wp && ! $compatible_php ) { |
|
977 |
return new WP_Error( |
|
978 |
'theme_wp_php_incompatible', |
|
979 |
sprintf( |
|
980 |
/* translators: %s: Theme name. */ |
|
981 |
_x( '<strong>Error:</strong> Current WordPress and PHP versions do not meet minimum requirements for %s.', 'theme' ), |
|
982 |
$theme->display( 'Name' ) |
|
983 |
) |
|
984 |
); |
|
985 |
} elseif ( ! $compatible_php ) { |
|
986 |
return new WP_Error( |
|
987 |
'theme_php_incompatible', |
|
988 |
sprintf( |
|
989 |
/* translators: %s: Theme name. */ |
|
990 |
_x( '<strong>Error:</strong> Current PHP version does not meet minimum requirements for %s.', 'theme' ), |
|
991 |
$theme->display( 'Name' ) |
|
992 |
) |
|
993 |
); |
|
994 |
} elseif ( ! $compatible_wp ) { |
|
995 |
return new WP_Error( |
|
996 |
'theme_wp_incompatible', |
|
997 |
sprintf( |
|
998 |
/* translators: %s: Theme name. */ |
|
999 |
_x( '<strong>Error:</strong> Current WordPress version does not meet minimum requirements for %s.', 'theme' ), |
|
1000 |
$theme->display( 'Name' ) |
|
1001 |
) |
|
1002 |
); |
|
1003 |
} |
|
1004 |
||
1005 |
return true; |
|
1006 |
} |
|
1007 |
||
1008 |
/** |
|
1009 |
* Retrieves all theme modifications. |
|
0 | 1010 |
* |
1011 |
* @since 3.1.0 |
|
19 | 1012 |
* @since 5.9.0 The return value is always an array. |
1013 |
* |
|
1014 |
* @return array Theme modifications. |
|
0 | 1015 |
*/ |
1016 |
function get_theme_mods() { |
|
1017 |
$theme_slug = get_option( 'stylesheet' ); |
|
9 | 1018 |
$mods = get_option( "theme_mods_$theme_slug" ); |
19 | 1019 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1020 |
if ( false === $mods ) { |
0 | 1021 |
$theme_name = get_option( 'current_theme' ); |
9 | 1022 |
if ( false === $theme_name ) { |
1023 |
$theme_name = wp_get_theme()->get( 'Name' ); |
|
1024 |
} |
|
19 | 1025 |
|
0 | 1026 |
$mods = get_option( "mods_$theme_name" ); // Deprecated location. |
1027 |
if ( is_admin() && false !== $mods ) { |
|
1028 |
update_option( "theme_mods_$theme_slug", $mods ); |
|
1029 |
delete_option( "mods_$theme_name" ); |
|
1030 |
} |
|
1031 |
} |
|
19 | 1032 |
|
1033 |
if ( ! is_array( $mods ) ) { |
|
1034 |
$mods = array(); |
|
1035 |
} |
|
1036 |
||
0 | 1037 |
return $mods; |
1038 |
} |
|
1039 |
||
1040 |
/** |
|
19 | 1041 |
* Retrieves theme modification value for the active theme. |
1042 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1043 |
* If the modification name does not exist and `$default_value` is a string, then the |
19 | 1044 |
* default will be passed through the {@link https://www.php.net/sprintf sprintf()} |
1045 |
* PHP function with the template directory URI as the first value and the |
|
1046 |
* stylesheet directory URI as the second value. |
|
0 | 1047 |
* |
1048 |
* @since 2.1.0 |
|
1049 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1050 |
* @param string $name Theme modification name. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1051 |
* @param mixed $default_value Optional. Theme modification default value. Default false. |
16 | 1052 |
* @return mixed Theme modification value. |
0 | 1053 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1054 |
function get_theme_mod( $name, $default_value = false ) { |
0 | 1055 |
$mods = get_theme_mods(); |
1056 |
||
9 | 1057 |
if ( isset( $mods[ $name ] ) ) { |
5 | 1058 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1059 |
* Filters the theme modification, or 'theme_mod', value. |
5 | 1060 |
* |
16 | 1061 |
* The dynamic portion of the hook name, `$name`, refers to the key name |
1062 |
* of the modification array. For example, 'header_textcolor', 'header_image', |
|
1063 |
* and so on depending on the theme options. |
|
5 | 1064 |
* |
1065 |
* @since 2.2.0 |
|
1066 |
* |
|
19 | 1067 |
* @param mixed $current_mod The value of the active theme modification. |
5 | 1068 |
*/ |
9 | 1069 |
return apply_filters( "theme_mod_{$name}", $mods[ $name ] ); |
5 | 1070 |
} |
0 | 1071 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1072 |
if ( is_string( $default_value ) ) { |
16 | 1073 |
// Only run the replacement if an sprintf() string format pattern was found. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1074 |
if ( preg_match( '#(?<!%)%(?:\d+\$?)?s#', $default_value ) ) { |
18 | 1075 |
// Remove a single trailing percent sign. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1076 |
$default_value = preg_replace( '#(?<!%)%$#', '', $default_value ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1077 |
$default_value = sprintf( $default_value, get_template_directory_uri(), get_stylesheet_directory_uri() ); |
16 | 1078 |
} |
9 | 1079 |
} |
0 | 1080 |
|
5 | 1081 |
/** This filter is documented in wp-includes/theme.php */ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1082 |
return apply_filters( "theme_mod_{$name}", $default_value ); |
0 | 1083 |
} |
1084 |
||
1085 |
/** |
|
19 | 1086 |
* Updates theme modification value for the active theme. |
0 | 1087 |
* |
1088 |
* @since 2.1.0 |
|
18 | 1089 |
* @since 5.6.0 A return value was added. |
0 | 1090 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1091 |
* @param string $name Theme modification name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1092 |
* @param mixed $value Theme modification value. |
18 | 1093 |
* @return bool True if the value was updated, false otherwise. |
0 | 1094 |
*/ |
1095 |
function set_theme_mod( $name, $value ) { |
|
9 | 1096 |
$mods = get_theme_mods(); |
5 | 1097 |
$old_value = isset( $mods[ $name ] ) ? $mods[ $name ] : false; |
0 | 1098 |
|
5 | 1099 |
/** |
16 | 1100 |
* Filters the theme modification, or 'theme_mod', value on save. |
5 | 1101 |
* |
16 | 1102 |
* The dynamic portion of the hook name, `$name`, refers to the key name |
1103 |
* of the modification array. For example, 'header_textcolor', 'header_image', |
|
5 | 1104 |
* and so on depending on the theme options. |
1105 |
* |
|
1106 |
* @since 3.9.0 |
|
1107 |
* |
|
19 | 1108 |
* @param mixed $value The new value of the theme modification. |
1109 |
* @param mixed $old_value The current value of the theme modification. |
|
5 | 1110 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1111 |
$mods[ $name ] = apply_filters( "pre_set_theme_mod_{$name}", $value, $old_value ); |
0 | 1112 |
|
1113 |
$theme = get_option( 'stylesheet' ); |
|
18 | 1114 |
|
1115 |
return update_option( "theme_mods_$theme", $mods ); |
|
0 | 1116 |
} |
1117 |
||
1118 |
/** |
|
19 | 1119 |
* Removes theme modification name from active theme list. |
0 | 1120 |
* |
16 | 1121 |
* If removing the name also removes all elements, then the entire option |
1122 |
* will be removed. |
|
0 | 1123 |
* |
1124 |
* @since 2.1.0 |
|
1125 |
* |
|
1126 |
* @param string $name Theme modification name. |
|
1127 |
*/ |
|
1128 |
function remove_theme_mod( $name ) { |
|
1129 |
$mods = get_theme_mods(); |
|
1130 |
||
9 | 1131 |
if ( ! isset( $mods[ $name ] ) ) { |
0 | 1132 |
return; |
9 | 1133 |
} |
0 | 1134 |
|
1135 |
unset( $mods[ $name ] ); |
|
1136 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1137 |
if ( empty( $mods ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1138 |
remove_theme_mods(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1139 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1140 |
} |
18 | 1141 |
|
0 | 1142 |
$theme = get_option( 'stylesheet' ); |
18 | 1143 |
|
0 | 1144 |
update_option( "theme_mods_$theme", $mods ); |
1145 |
} |
|
1146 |
||
1147 |
/** |
|
19 | 1148 |
* Removes theme modifications option for the active theme. |
0 | 1149 |
* |
1150 |
* @since 2.1.0 |
|
1151 |
*/ |
|
1152 |
function remove_theme_mods() { |
|
1153 |
delete_option( 'theme_mods_' . get_option( 'stylesheet' ) ); |
|
1154 |
||
1155 |
// Old style. |
|
1156 |
$theme_name = get_option( 'current_theme' ); |
|
9 | 1157 |
if ( false === $theme_name ) { |
1158 |
$theme_name = wp_get_theme()->get( 'Name' ); |
|
1159 |
} |
|
18 | 1160 |
|
0 | 1161 |
delete_option( 'mods_' . $theme_name ); |
1162 |
} |
|
1163 |
||
1164 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1165 |
* Retrieves the custom header text color in 3- or 6-digit hexadecimal form. |
0 | 1166 |
* |
1167 |
* @since 2.1.0 |
|
1168 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1169 |
* @return string Header text color in 3- or 6-digit hexadecimal form (minus the hash symbol). |
0 | 1170 |
*/ |
1171 |
function get_header_textcolor() { |
|
9 | 1172 |
return get_theme_mod( 'header_textcolor', get_theme_support( 'custom-header', 'default-text-color' ) ); |
0 | 1173 |
} |
1174 |
||
1175 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1176 |
* Displays the custom header text color in 3- or 6-digit hexadecimal form (minus the hash symbol). |
0 | 1177 |
* |
1178 |
* @since 2.1.0 |
|
1179 |
*/ |
|
1180 |
function header_textcolor() { |
|
1181 |
echo get_header_textcolor(); |
|
1182 |
} |
|
1183 |
||
1184 |
/** |
|
1185 |
* Whether to display the header text. |
|
1186 |
* |
|
1187 |
* @since 3.4.0 |
|
1188 |
* |
|
1189 |
* @return bool |
|
1190 |
*/ |
|
1191 |
function display_header_text() { |
|
9 | 1192 |
if ( ! current_theme_supports( 'custom-header', 'header-text' ) ) { |
0 | 1193 |
return false; |
9 | 1194 |
} |
0 | 1195 |
|
1196 |
$text_color = get_theme_mod( 'header_textcolor', get_theme_support( 'custom-header', 'default-text-color' ) ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1197 |
return 'blank' !== $text_color; |
0 | 1198 |
} |
1199 |
||
1200 |
/** |
|
16 | 1201 |
* Checks whether a header image is set or not. |
5 | 1202 |
* |
1203 |
* @since 4.2.0 |
|
1204 |
* |
|
1205 |
* @see get_header_image() |
|
1206 |
* |
|
1207 |
* @return bool Whether a header image is set or not. |
|
1208 |
*/ |
|
1209 |
function has_header_image() { |
|
1210 |
return (bool) get_header_image(); |
|
1211 |
} |
|
1212 |
||
1213 |
/** |
|
16 | 1214 |
* Retrieves header image for custom header. |
0 | 1215 |
* |
1216 |
* @since 2.1.0 |
|
1217 |
* |
|
5 | 1218 |
* @return string|false |
0 | 1219 |
*/ |
1220 |
function get_header_image() { |
|
1221 |
$url = get_theme_mod( 'header_image', get_theme_support( 'custom-header', 'default-image' ) ); |
|
1222 |
||
16 | 1223 |
if ( 'remove-header' === $url ) { |
0 | 1224 |
return false; |
9 | 1225 |
} |
1226 |
||
1227 |
if ( is_random_header_image() ) { |
|
0 | 1228 |
$url = get_random_header_image(); |
9 | 1229 |
} |
0 | 1230 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1231 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1232 |
* Filters the header image URL. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1233 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1234 |
* @since 6.1.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1235 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1236 |
* @param string $url Header image URL. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1237 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1238 |
$url = apply_filters( 'get_header_image', $url ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1239 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1240 |
if ( ! is_string( $url ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1241 |
return false; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1242 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1243 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1244 |
$url = trim( $url ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1245 |
return sanitize_url( set_url_scheme( $url ) ); |
0 | 1246 |
} |
1247 |
||
1248 |
/** |
|
16 | 1249 |
* Creates image tag markup for a custom header image. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1250 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1251 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1252 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1253 |
* @param array $attr Optional. Additional attributes for the image tag. Can be used |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1254 |
* to override the default attributes. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1255 |
* @return string HTML image element markup or empty string on failure. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1256 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1257 |
function get_header_image_tag( $attr = array() ) { |
9 | 1258 |
$header = get_custom_header(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1259 |
$header->url = get_header_image(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1260 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1261 |
if ( ! $header->url ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1262 |
return ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1263 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1264 |
|
9 | 1265 |
$width = absint( $header->width ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1266 |
$height = absint( $header->height ); |
19 | 1267 |
$alt = ''; |
1268 |
||
1269 |
// Use alternative text assigned to the image, if available. Otherwise, leave it empty. |
|
1270 |
if ( ! empty( $header->attachment_id ) ) { |
|
1271 |
$image_alt = get_post_meta( $header->attachment_id, '_wp_attachment_image_alt', true ); |
|
1272 |
||
1273 |
if ( is_string( $image_alt ) ) { |
|
1274 |
$alt = $image_alt; |
|
1275 |
} |
|
1276 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1277 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1278 |
$attr = wp_parse_args( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1279 |
$attr, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1280 |
array( |
9 | 1281 |
'src' => $header->url, |
1282 |
'width' => $width, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1283 |
'height' => $height, |
19 | 1284 |
'alt' => $alt, |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1285 |
) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1286 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1287 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1288 |
// Generate 'srcset' and 'sizes' if not already present. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1289 |
if ( empty( $attr['srcset'] ) && ! empty( $header->attachment_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1290 |
$image_meta = get_post_meta( $header->attachment_id, '_wp_attachment_metadata', true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1291 |
$size_array = array( $width, $height ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1292 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1293 |
if ( is_array( $image_meta ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1294 |
$srcset = wp_calculate_image_srcset( $size_array, $header->url, $image_meta, $header->attachment_id ); |
19 | 1295 |
|
1296 |
if ( ! empty( $attr['sizes'] ) ) { |
|
1297 |
$sizes = $attr['sizes']; |
|
1298 |
} else { |
|
1299 |
$sizes = wp_calculate_image_sizes( $size_array, $header->url, $image_meta, $header->attachment_id ); |
|
1300 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1301 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1302 |
if ( $srcset && $sizes ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1303 |
$attr['srcset'] = $srcset; |
9 | 1304 |
$attr['sizes'] = $sizes; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1305 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1306 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1307 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1308 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1309 |
$attr = array_merge( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1310 |
$attr, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1311 |
wp_get_loading_optimization_attributes( 'img', $attr, 'get_header_image_tag' ) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1312 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1313 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1314 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1315 |
* If the default value of `lazy` for the `loading` attribute is overridden |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1316 |
* to omit the attribute for this image, ensure it is not included. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1317 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1318 |
if ( isset( $attr['loading'] ) && ! $attr['loading'] ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1319 |
unset( $attr['loading'] ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1320 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1321 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1322 |
// If the `fetchpriority` attribute is overridden and set to false or an empty string. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1323 |
if ( isset( $attr['fetchpriority'] ) && ! $attr['fetchpriority'] ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1324 |
unset( $attr['fetchpriority'] ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1325 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1326 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1327 |
// If the `decoding` attribute is overridden and set to false or an empty string. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1328 |
if ( isset( $attr['decoding'] ) && ! $attr['decoding'] ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1329 |
unset( $attr['decoding'] ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1330 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1331 |
|
19 | 1332 |
/** |
1333 |
* Filters the list of header image attributes. |
|
1334 |
* |
|
1335 |
* @since 5.9.0 |
|
1336 |
* |
|
1337 |
* @param array $attr Array of the attributes for the image tag. |
|
1338 |
* @param object $header The custom header object returned by 'get_custom_header()'. |
|
1339 |
*/ |
|
1340 |
$attr = apply_filters( 'get_header_image_tag_attributes', $attr, $header ); |
|
1341 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1342 |
$attr = array_map( 'esc_attr', $attr ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1343 |
$html = '<img'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1344 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1345 |
foreach ( $attr as $name => $value ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1346 |
$html .= ' ' . $name . '="' . $value . '"'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1347 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1348 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1349 |
$html .= ' />'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1350 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1351 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1352 |
* Filters the markup of header images. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1353 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1354 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1355 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1356 |
* @param string $html The HTML image tag markup being filtered. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1357 |
* @param object $header The custom header object returned by 'get_custom_header()'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1358 |
* @param array $attr Array of the attributes for the image tag. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1359 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1360 |
return apply_filters( 'get_header_image_tag', $html, $header, $attr ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1361 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1362 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1363 |
/** |
16 | 1364 |
* Displays the image markup for a custom header image. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1365 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1366 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1367 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1368 |
* @param array $attr Optional. Attributes for the image markup. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1369 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1370 |
function the_header_image_tag( $attr = array() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1371 |
echo get_header_image_tag( $attr ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1372 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1373 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1374 |
/** |
16 | 1375 |
* Gets random header image data from registered images in theme. |
0 | 1376 |
* |
1377 |
* @since 3.4.0 |
|
1378 |
* |
|
1379 |
* @access private |
|
1380 |
* |
|
16 | 1381 |
* @global array $_wp_default_headers |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1382 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1383 |
* @return object |
0 | 1384 |
*/ |
1385 |
function _get_random_header_data() { |
|
19 | 1386 |
global $_wp_default_headers; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1387 |
static $_wp_random_header = null; |
0 | 1388 |
|
1389 |
if ( empty( $_wp_random_header ) ) { |
|
1390 |
$header_image_mod = get_theme_mod( 'header_image', '' ); |
|
9 | 1391 |
$headers = array(); |
1392 |
||
16 | 1393 |
if ( 'random-uploaded-image' === $header_image_mod ) { |
0 | 1394 |
$headers = get_uploaded_header_images(); |
9 | 1395 |
} elseif ( ! empty( $_wp_default_headers ) ) { |
16 | 1396 |
if ( 'random-default-image' === $header_image_mod ) { |
0 | 1397 |
$headers = $_wp_default_headers; |
1398 |
} else { |
|
9 | 1399 |
if ( current_theme_supports( 'custom-header', 'random-default' ) ) { |
0 | 1400 |
$headers = $_wp_default_headers; |
9 | 1401 |
} |
0 | 1402 |
} |
1403 |
} |
|
1404 |
||
9 | 1405 |
if ( empty( $headers ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1406 |
return new stdClass(); |
9 | 1407 |
} |
0 | 1408 |
|
1409 |
$_wp_random_header = (object) $headers[ array_rand( $headers ) ]; |
|
1410 |
||
19 | 1411 |
$_wp_random_header->url = sprintf( |
1412 |
$_wp_random_header->url, |
|
1413 |
get_template_directory_uri(), |
|
1414 |
get_stylesheet_directory_uri() |
|
1415 |
); |
|
1416 |
||
1417 |
$_wp_random_header->thumbnail_url = sprintf( |
|
1418 |
$_wp_random_header->thumbnail_url, |
|
1419 |
get_template_directory_uri(), |
|
1420 |
get_stylesheet_directory_uri() |
|
1421 |
); |
|
0 | 1422 |
} |
16 | 1423 |
|
0 | 1424 |
return $_wp_random_header; |
1425 |
} |
|
1426 |
||
1427 |
/** |
|
16 | 1428 |
* Gets random header image URL from registered images in theme. |
0 | 1429 |
* |
1430 |
* @since 3.2.0 |
|
1431 |
* |
|
16 | 1432 |
* @return string Path to header image. |
0 | 1433 |
*/ |
1434 |
function get_random_header_image() { |
|
1435 |
$random_image = _get_random_header_data(); |
|
16 | 1436 |
|
9 | 1437 |
if ( empty( $random_image->url ) ) { |
0 | 1438 |
return ''; |
9 | 1439 |
} |
16 | 1440 |
|
0 | 1441 |
return $random_image->url; |
1442 |
} |
|
1443 |
||
1444 |
/** |
|
16 | 1445 |
* Checks if random header image is in use. |
0 | 1446 |
* |
1447 |
* Always true if user expressly chooses the option in Appearance > Header. |
|
1448 |
* Also true if theme has multiple header images registered, no specific header image |
|
1449 |
* is chosen, and theme turns on random headers with add_theme_support(). |
|
1450 |
* |
|
1451 |
* @since 3.2.0 |
|
1452 |
* |
|
16 | 1453 |
* @param string $type The random pool to use. Possible values include 'any', |
1454 |
* 'default', 'uploaded'. Default 'any'. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1455 |
* @return bool |
0 | 1456 |
*/ |
1457 |
function is_random_header_image( $type = 'any' ) { |
|
1458 |
$header_image_mod = get_theme_mod( 'header_image', get_theme_support( 'custom-header', 'default-image' ) ); |
|
1459 |
||
16 | 1460 |
if ( 'any' === $type ) { |
1461 |
if ( 'random-default-image' === $header_image_mod |
|
1462 |
|| 'random-uploaded-image' === $header_image_mod |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1463 |
|| ( empty( $header_image_mod ) && '' !== get_random_header_image() ) |
16 | 1464 |
) { |
0 | 1465 |
return true; |
9 | 1466 |
} |
0 | 1467 |
} else { |
16 | 1468 |
if ( "random-$type-image" === $header_image_mod ) { |
0 | 1469 |
return true; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1470 |
} elseif ( 'default' === $type |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1471 |
&& empty( $header_image_mod ) && '' !== get_random_header_image() |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1472 |
) { |
0 | 1473 |
return true; |
9 | 1474 |
} |
0 | 1475 |
} |
1476 |
||
1477 |
return false; |
|
1478 |
} |
|
1479 |
||
1480 |
/** |
|
16 | 1481 |
* Displays header image URL. |
0 | 1482 |
* |
1483 |
* @since 2.1.0 |
|
1484 |
*/ |
|
1485 |
function header_image() { |
|
5 | 1486 |
$image = get_header_image(); |
16 | 1487 |
|
5 | 1488 |
if ( $image ) { |
1489 |
echo esc_url( $image ); |
|
1490 |
} |
|
0 | 1491 |
} |
1492 |
||
1493 |
/** |
|
19 | 1494 |
* Gets the header images uploaded for the active theme. |
0 | 1495 |
* |
1496 |
* @since 3.2.0 |
|
1497 |
* |
|
1498 |
* @return array |
|
1499 |
*/ |
|
1500 |
function get_uploaded_header_images() { |
|
1501 |
$header_images = array(); |
|
1502 |
||
16 | 1503 |
// @todo Caching. |
9 | 1504 |
$headers = get_posts( |
1505 |
array( |
|
1506 |
'post_type' => 'attachment', |
|
1507 |
'meta_key' => '_wp_attachment_is_custom_header', |
|
1508 |
'meta_value' => get_option( 'stylesheet' ), |
|
1509 |
'orderby' => 'none', |
|
1510 |
'nopaging' => true, |
|
1511 |
) |
|
1512 |
); |
|
1513 |
||
1514 |
if ( empty( $headers ) ) { |
|
0 | 1515 |
return array(); |
9 | 1516 |
} |
0 | 1517 |
|
1518 |
foreach ( (array) $headers as $header ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1519 |
$url = sanitize_url( wp_get_attachment_url( $header->ID ) ); |
9 | 1520 |
$header_data = wp_get_attachment_metadata( $header->ID ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1521 |
$header_index = $header->ID; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1522 |
|
19 | 1523 |
$header_images[ $header_index ] = array(); |
1524 |
$header_images[ $header_index ]['attachment_id'] = $header->ID; |
|
1525 |
$header_images[ $header_index ]['url'] = $url; |
|
1526 |
$header_images[ $header_index ]['thumbnail_url'] = $url; |
|
1527 |
$header_images[ $header_index ]['alt_text'] = get_post_meta( $header->ID, '_wp_attachment_image_alt', true ); |
|
1528 |
||
1529 |
if ( isset( $header_data['attachment_parent'] ) ) { |
|
1530 |
$header_images[ $header_index ]['attachment_parent'] = $header_data['attachment_parent']; |
|
1531 |
} else { |
|
1532 |
$header_images[ $header_index ]['attachment_parent'] = ''; |
|
1533 |
} |
|
9 | 1534 |
|
1535 |
if ( isset( $header_data['width'] ) ) { |
|
1536 |
$header_images[ $header_index ]['width'] = $header_data['width']; |
|
1537 |
} |
|
1538 |
if ( isset( $header_data['height'] ) ) { |
|
1539 |
$header_images[ $header_index ]['height'] = $header_data['height']; |
|
1540 |
} |
|
0 | 1541 |
} |
1542 |
||
1543 |
return $header_images; |
|
1544 |
} |
|
1545 |
||
1546 |
/** |
|
16 | 1547 |
* Gets the header image data. |
0 | 1548 |
* |
1549 |
* @since 3.4.0 |
|
1550 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1551 |
* @global array $_wp_default_headers |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1552 |
* |
0 | 1553 |
* @return object |
1554 |
*/ |
|
1555 |
function get_custom_header() { |
|
1556 |
global $_wp_default_headers; |
|
1557 |
||
1558 |
if ( is_random_header_image() ) { |
|
1559 |
$data = _get_random_header_data(); |
|
1560 |
} else { |
|
1561 |
$data = get_theme_mod( 'header_image_data' ); |
|
1562 |
if ( ! $data && current_theme_supports( 'custom-header', 'default-image' ) ) { |
|
16 | 1563 |
$directory_args = array( get_template_directory_uri(), get_stylesheet_directory_uri() ); |
1564 |
$data = array(); |
|
1565 |
$data['url'] = vsprintf( get_theme_support( 'custom-header', 'default-image' ), $directory_args ); |
|
1566 |
$data['thumbnail_url'] = $data['url']; |
|
0 | 1567 |
if ( ! empty( $_wp_default_headers ) ) { |
1568 |
foreach ( (array) $_wp_default_headers as $default_header ) { |
|
1569 |
$url = vsprintf( $default_header['url'], $directory_args ); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1570 |
if ( $data['url'] === $url ) { |
9 | 1571 |
$data = $default_header; |
1572 |
$data['url'] = $url; |
|
0 | 1573 |
$data['thumbnail_url'] = vsprintf( $data['thumbnail_url'], $directory_args ); |
1574 |
break; |
|
1575 |
} |
|
1576 |
} |
|
1577 |
} |
|
1578 |
} |
|
1579 |
} |
|
1580 |
||
1581 |
$default = array( |
|
1582 |
'url' => '', |
|
1583 |
'thumbnail_url' => '', |
|
1584 |
'width' => get_theme_support( 'custom-header', 'width' ), |
|
1585 |
'height' => get_theme_support( 'custom-header', 'height' ), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1586 |
'video' => get_theme_support( 'custom-header', 'video' ), |
0 | 1587 |
); |
1588 |
return (object) wp_parse_args( $data, $default ); |
|
1589 |
} |
|
1590 |
||
1591 |
/** |
|
16 | 1592 |
* Registers a selection of default headers to be displayed by the custom header admin UI. |
0 | 1593 |
* |
1594 |
* @since 3.0.0 |
|
1595 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1596 |
* @global array $_wp_default_headers |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1597 |
* |
16 | 1598 |
* @param array $headers Array of headers keyed by a string ID. The IDs point to arrays |
1599 |
* containing 'url', 'thumbnail_url', and 'description' keys. |
|
0 | 1600 |
*/ |
1601 |
function register_default_headers( $headers ) { |
|
1602 |
global $_wp_default_headers; |
|
1603 |
||
1604 |
$_wp_default_headers = array_merge( (array) $_wp_default_headers, (array) $headers ); |
|
1605 |
} |
|
1606 |
||
1607 |
/** |
|
16 | 1608 |
* Unregisters default headers. |
0 | 1609 |
* |
1610 |
* This function must be called after register_default_headers() has already added the |
|
1611 |
* header you want to remove. |
|
1612 |
* |
|
1613 |
* @see register_default_headers() |
|
1614 |
* @since 3.0.0 |
|
1615 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1616 |
* @global array $_wp_default_headers |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1617 |
* |
0 | 1618 |
* @param string|array $header The header string id (key of array) to remove, or an array thereof. |
5 | 1619 |
* @return bool|void A single header returns true on success, false on failure. |
1620 |
* There is currently no return value for multiple headers. |
|
0 | 1621 |
*/ |
1622 |
function unregister_default_headers( $header ) { |
|
1623 |
global $_wp_default_headers; |
|
19 | 1624 |
|
0 | 1625 |
if ( is_array( $header ) ) { |
1626 |
array_map( 'unregister_default_headers', $header ); |
|
1627 |
} elseif ( isset( $_wp_default_headers[ $header ] ) ) { |
|
1628 |
unset( $_wp_default_headers[ $header ] ); |
|
1629 |
return true; |
|
1630 |
} else { |
|
1631 |
return false; |
|
1632 |
} |
|
1633 |
} |
|
1634 |
||
1635 |
/** |
|
16 | 1636 |
* Checks whether a header video is set or not. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1637 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1638 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1639 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1640 |
* @see get_header_video_url() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1641 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1642 |
* @return bool Whether a header video is set or not. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1643 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1644 |
function has_header_video() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1645 |
return (bool) get_header_video_url(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1646 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1647 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1648 |
/** |
16 | 1649 |
* Retrieves header video URL for custom header. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1650 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1651 |
* Uses a local video if present, or falls back to an external video. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1652 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1653 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1654 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1655 |
* @return string|false Header video URL or false if there is no video. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1656 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1657 |
function get_header_video_url() { |
16 | 1658 |
$id = absint( get_theme_mod( 'header_video' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1659 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1660 |
if ( $id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1661 |
// Get the file URL from the attachment ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1662 |
$url = wp_get_attachment_url( $id ); |
16 | 1663 |
} else { |
1664 |
$url = get_theme_mod( 'external_header_video' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1665 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1666 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1667 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1668 |
* Filters the header video URL. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1669 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1670 |
* @since 4.7.3 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1671 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1672 |
* @param string $url Header video URL, if available. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1673 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1674 |
$url = apply_filters( 'get_header_video_url', $url ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1675 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1676 |
if ( ! $id && ! $url ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1677 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1678 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1679 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1680 |
return sanitize_url( set_url_scheme( $url ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1681 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1682 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1683 |
/** |
16 | 1684 |
* Displays header video URL. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1685 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1686 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1687 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1688 |
function the_header_video_url() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1689 |
$video = get_header_video_url(); |
16 | 1690 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1691 |
if ( $video ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1692 |
echo esc_url( $video ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1693 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1694 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1695 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1696 |
/** |
16 | 1697 |
* Retrieves header video settings. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1698 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1699 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1700 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1701 |
* @return array |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1702 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1703 |
function get_header_video_settings() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1704 |
$header = get_custom_header(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1705 |
$video_url = get_header_video_url(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1706 |
$video_type = wp_check_filetype( $video_url, wp_get_mime_types() ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1707 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1708 |
$settings = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1709 |
'mimeType' => '', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1710 |
'posterUrl' => get_header_image(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1711 |
'videoUrl' => $video_url, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1712 |
'width' => absint( $header->width ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1713 |
'height' => absint( $header->height ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1714 |
'minWidth' => 900, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1715 |
'minHeight' => 500, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1716 |
'l10n' => array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1717 |
'pause' => __( 'Pause' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1718 |
'play' => __( 'Play' ), |
9 | 1719 |
'pauseSpeak' => __( 'Video is paused.' ), |
1720 |
'playSpeak' => __( 'Video is playing.' ), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1721 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1722 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1723 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1724 |
if ( preg_match( '#^https?://(?:www\.)?(?:youtube\.com/watch|youtu\.be/)#', $video_url ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1725 |
$settings['mimeType'] = 'video/x-youtube'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1726 |
} elseif ( ! empty( $video_type['type'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1727 |
$settings['mimeType'] = $video_type['type']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1728 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1729 |
|
9 | 1730 |
/** |
1731 |
* Filters header video settings. |
|
1732 |
* |
|
1733 |
* @since 4.7.0 |
|
1734 |
* |
|
1735 |
* @param array $settings An array of header video settings. |
|
1736 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1737 |
return apply_filters( 'header_video_settings', $settings ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1738 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1739 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1740 |
/** |
16 | 1741 |
* Checks whether a custom header is set or not. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1742 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1743 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1744 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1745 |
* @return bool True if a custom header is set. False if not. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1746 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1747 |
function has_custom_header() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1748 |
if ( has_header_image() || ( has_header_video() && is_header_video_active() ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1749 |
return true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1750 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1751 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1752 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1753 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1754 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1755 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1756 |
* Checks whether the custom header video is eligible to show on the current page. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1757 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1758 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1759 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1760 |
* @return bool True if the custom header video should be shown. False if not. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1761 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1762 |
function is_header_video_active() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1763 |
if ( ! get_theme_support( 'custom-header', 'video' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1764 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1765 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1766 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1767 |
$video_active_cb = get_theme_support( 'custom-header', 'video-active-callback' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1768 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1769 |
if ( empty( $video_active_cb ) || ! is_callable( $video_active_cb ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1770 |
$show_video = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1771 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1772 |
$show_video = call_user_func( $video_active_cb ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1773 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1774 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1775 |
/** |
16 | 1776 |
* Filters whether the custom header video is eligible to show on the current page. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1777 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1778 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1779 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1780 |
* @param bool $show_video Whether the custom header video should be shown. Returns the value |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1781 |
* of the theme setting for the `custom-header`'s `video-active-callback`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1782 |
* If no callback is set, the default value is that of `is_front_page()`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1783 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1784 |
return apply_filters( 'is_header_video_active', $show_video ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1785 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1786 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1787 |
/** |
16 | 1788 |
* Retrieves the markup for a custom header. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1789 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1790 |
* The container div will always be returned in the Customizer preview. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1791 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1792 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1793 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1794 |
* @return string The markup for a custom header on success. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1795 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1796 |
function get_custom_header_markup() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1797 |
if ( ! has_custom_header() && ! is_customize_preview() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1798 |
return ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1799 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1800 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1801 |
return sprintf( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1802 |
'<div id="wp-custom-header" class="wp-custom-header">%s</div>', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1803 |
get_header_image_tag() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1804 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1805 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1806 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1807 |
/** |
16 | 1808 |
* Prints the markup for a custom header. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1809 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1810 |
* A container div will always be printed in the Customizer preview. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1811 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1812 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1813 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1814 |
function the_custom_header_markup() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1815 |
$custom_header = get_custom_header_markup(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1816 |
if ( empty( $custom_header ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1817 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1818 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1819 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1820 |
echo $custom_header; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1821 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1822 |
if ( is_header_video_active() && ( has_header_video() || is_customize_preview() ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1823 |
wp_enqueue_script( 'wp-custom-header' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1824 |
wp_localize_script( 'wp-custom-header', '_wpCustomHeaderSettings', get_header_video_settings() ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1825 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1826 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1827 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1828 |
/** |
16 | 1829 |
* Retrieves background image for custom background. |
0 | 1830 |
* |
1831 |
* @since 3.0.0 |
|
1832 |
* |
|
1833 |
* @return string |
|
1834 |
*/ |
|
1835 |
function get_background_image() { |
|
9 | 1836 |
return get_theme_mod( 'background_image', get_theme_support( 'custom-background', 'default-image' ) ); |
0 | 1837 |
} |
1838 |
||
1839 |
/** |
|
16 | 1840 |
* Displays background image path. |
0 | 1841 |
* |
1842 |
* @since 3.0.0 |
|
1843 |
*/ |
|
1844 |
function background_image() { |
|
1845 |
echo get_background_image(); |
|
1846 |
} |
|
1847 |
||
1848 |
/** |
|
16 | 1849 |
* Retrieves value for custom background color. |
0 | 1850 |
* |
1851 |
* @since 3.0.0 |
|
1852 |
* |
|
1853 |
* @return string |
|
1854 |
*/ |
|
1855 |
function get_background_color() { |
|
9 | 1856 |
return get_theme_mod( 'background_color', get_theme_support( 'custom-background', 'default-color' ) ); |
0 | 1857 |
} |
1858 |
||
1859 |
/** |
|
16 | 1860 |
* Displays background color value. |
0 | 1861 |
* |
1862 |
* @since 3.0.0 |
|
1863 |
*/ |
|
1864 |
function background_color() { |
|
1865 |
echo get_background_color(); |
|
1866 |
} |
|
1867 |
||
1868 |
/** |
|
1869 |
* Default custom background callback. |
|
1870 |
* |
|
1871 |
* @since 3.0.0 |
|
1872 |
*/ |
|
1873 |
function _custom_background_cb() { |
|
1874 |
// $background is the saved custom image, or the default image. |
|
1875 |
$background = set_url_scheme( get_background_image() ); |
|
1876 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1877 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1878 |
* $color is the saved custom color. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1879 |
* A default has to be specified in style.css. It will not be printed here. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1880 |
*/ |
5 | 1881 |
$color = get_background_color(); |
1882 |
||
16 | 1883 |
if ( get_theme_support( 'custom-background', 'default-color' ) === $color ) { |
5 | 1884 |
$color = false; |
1885 |
} |
|
0 | 1886 |
|
16 | 1887 |
$type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"'; |
1888 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1889 |
if ( ! $background && ! $color ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1890 |
if ( is_customize_preview() ) { |
16 | 1891 |
printf( '<style%s id="custom-background-css"></style>', $type_attr ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1892 |
} |
0 | 1893 |
return; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1894 |
} |
0 | 1895 |
|
1896 |
$style = $color ? "background-color: #$color;" : ''; |
|
1897 |
||
1898 |
if ( $background ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1899 |
$image = ' background-image: url("' . sanitize_url( $background ) . '");'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1900 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1901 |
// Background Position. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1902 |
$position_x = get_theme_mod( 'background_position_x', get_theme_support( 'custom-background', 'default-position-x' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1903 |
$position_y = get_theme_mod( 'background_position_y', get_theme_support( 'custom-background', 'default-position-y' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1904 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1905 |
if ( ! in_array( $position_x, array( 'left', 'center', 'right' ), true ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1906 |
$position_x = 'left'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1907 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1908 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1909 |
if ( ! in_array( $position_y, array( 'top', 'center', 'bottom' ), true ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1910 |
$position_y = 'top'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1911 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1912 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1913 |
$position = " background-position: $position_x $position_y;"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1914 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1915 |
// Background Size. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1916 |
$size = get_theme_mod( 'background_size', get_theme_support( 'custom-background', 'default-size' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1917 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1918 |
if ( ! in_array( $size, array( 'auto', 'contain', 'cover' ), true ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1919 |
$size = 'auto'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1920 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1921 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1922 |
$size = " background-size: $size;"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1923 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1924 |
// Background Repeat. |
5 | 1925 |
$repeat = get_theme_mod( 'background_repeat', get_theme_support( 'custom-background', 'default-repeat' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1926 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1927 |
if ( ! in_array( $repeat, array( 'repeat-x', 'repeat-y', 'repeat', 'no-repeat' ), true ) ) { |
0 | 1928 |
$repeat = 'repeat'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1929 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1930 |
|
0 | 1931 |
$repeat = " background-repeat: $repeat;"; |
1932 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1933 |
// Background Scroll. |
5 | 1934 |
$attachment = get_theme_mod( 'background_attachment', get_theme_support( 'custom-background', 'default-attachment' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1935 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1936 |
if ( 'fixed' !== $attachment ) { |
0 | 1937 |
$attachment = 'scroll'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1938 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1939 |
|
0 | 1940 |
$attachment = " background-attachment: $attachment;"; |
1941 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1942 |
$style .= $image . $position . $size . $repeat . $attachment; |
0 | 1943 |
} |
9 | 1944 |
?> |
16 | 1945 |
<style<?php echo $type_attr; ?> id="custom-background-css"> |
0 | 1946 |
body.custom-background { <?php echo trim( $style ); ?> } |
1947 |
</style> |
|
9 | 1948 |
<?php |
0 | 1949 |
} |
1950 |
||
1951 |
/** |
|
16 | 1952 |
* Renders the Custom CSS style element. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1953 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1954 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1955 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1956 |
function wp_custom_css_cb() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1957 |
$styles = wp_get_custom_css(); |
9 | 1958 |
if ( $styles || is_customize_preview() ) : |
16 | 1959 |
$type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"'; |
9 | 1960 |
?> |
16 | 1961 |
<style<?php echo $type_attr; ?> id="wp-custom-css"> |
19 | 1962 |
<?php |
1963 |
// Note that esc_html() cannot be used because `div > span` is not interpreted properly. |
|
1964 |
echo strip_tags( $styles ); |
|
1965 |
?> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1966 |
</style> |
9 | 1967 |
<?php |
1968 |
endif; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1969 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1970 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1971 |
/** |
16 | 1972 |
* Fetches the `custom_css` post for a given theme. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1973 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1974 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1975 |
* |
19 | 1976 |
* @param string $stylesheet Optional. A theme object stylesheet name. Defaults to the active theme. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1977 |
* @return WP_Post|null The custom_css post or null if none exists. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1978 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1979 |
function wp_get_custom_css_post( $stylesheet = '' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1980 |
if ( empty( $stylesheet ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1981 |
$stylesheet = get_stylesheet(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1982 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1983 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1984 |
$custom_css_query_vars = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1985 |
'post_type' => 'custom_css', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1986 |
'post_status' => get_post_stati(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1987 |
'name' => sanitize_title( $stylesheet ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1988 |
'posts_per_page' => 1, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1989 |
'no_found_rows' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1990 |
'cache_results' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1991 |
'update_post_meta_cache' => false, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1992 |
'update_post_term_cache' => false, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1993 |
'lazy_load_term_meta' => false, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1994 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1995 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1996 |
$post = null; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1997 |
if ( get_stylesheet() === $stylesheet ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1998 |
$post_id = get_theme_mod( 'custom_css_post_id' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1999 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2000 |
if ( $post_id > 0 && get_post( $post_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2001 |
$post = get_post( $post_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2002 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2003 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2004 |
// `-1` indicates no post exists; no query necessary. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2005 |
if ( ! $post && -1 !== $post_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2006 |
$query = new WP_Query( $custom_css_query_vars ); |
9 | 2007 |
$post = $query->post; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2008 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2009 |
* Cache the lookup. See wp_update_custom_css_post(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2010 |
* @todo This should get cleared if a custom_css post is added/removed. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2011 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2012 |
set_theme_mod( 'custom_css_post_id', $post ? $post->ID : -1 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2013 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2014 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2015 |
$query = new WP_Query( $custom_css_query_vars ); |
9 | 2016 |
$post = $query->post; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2017 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2018 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2019 |
return $post; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2020 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2021 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2022 |
/** |
16 | 2023 |
* Fetches the saved Custom CSS content for rendering. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2024 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2025 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2026 |
* |
19 | 2027 |
* @param string $stylesheet Optional. A theme object stylesheet name. Defaults to the active theme. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2028 |
* @return string The Custom CSS Post content. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2029 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2030 |
function wp_get_custom_css( $stylesheet = '' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2031 |
$css = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2032 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2033 |
if ( empty( $stylesheet ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2034 |
$stylesheet = get_stylesheet(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2035 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2036 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2037 |
$post = wp_get_custom_css_post( $stylesheet ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2038 |
if ( $post ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2039 |
$css = $post->post_content; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2040 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2041 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2042 |
/** |
19 | 2043 |
* Filters the custom CSS output into the head element. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2044 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2045 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2046 |
* |
19 | 2047 |
* @param string $css CSS pulled in from the Custom CSS post type. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2048 |
* @param string $stylesheet The theme stylesheet name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2049 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2050 |
$css = apply_filters( 'wp_get_custom_css', $css, $stylesheet ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2051 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2052 |
return $css; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2053 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2054 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2055 |
/** |
16 | 2056 |
* Updates the `custom_css` post for a given theme. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2057 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2058 |
* Inserts a `custom_css` post when one doesn't yet exist. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2059 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2060 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2061 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2062 |
* @param string $css CSS, stored in `post_content`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2063 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2064 |
* Args. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2065 |
* |
19 | 2066 |
* @type string $preprocessed Optional. Pre-processed CSS, stored in `post_content_filtered`. |
2067 |
* Normally empty string. |
|
2068 |
* @type string $stylesheet Optional. Stylesheet (child theme) to update. |
|
2069 |
* Defaults to active theme/stylesheet. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2070 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2071 |
* @return WP_Post|WP_Error Post on success, error on failure. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2072 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2073 |
function wp_update_custom_css_post( $css, $args = array() ) { |
9 | 2074 |
$args = wp_parse_args( |
2075 |
$args, |
|
2076 |
array( |
|
2077 |
'preprocessed' => '', |
|
2078 |
'stylesheet' => get_stylesheet(), |
|
2079 |
) |
|
2080 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2081 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2082 |
$data = array( |
9 | 2083 |
'css' => $css, |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2084 |
'preprocessed' => $args['preprocessed'], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2085 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2086 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2087 |
/** |
19 | 2088 |
* Filters the `css` (`post_content`) and `preprocessed` (`post_content_filtered`) args |
2089 |
* for a `custom_css` post being updated. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2090 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2091 |
* This filter can be used by plugin that offer CSS pre-processors, to store the original |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2092 |
* pre-processed CSS in `post_content_filtered` and then store processed CSS in `post_content`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2093 |
* When used in this way, the `post_content_filtered` should be supplied as the setting value |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2094 |
* instead of `post_content` via a the `customize_value_custom_css` filter, for example: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2095 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2096 |
* <code> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2097 |
* add_filter( 'customize_value_custom_css', function( $value, $setting ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2098 |
* $post = wp_get_custom_css_post( $setting->stylesheet ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2099 |
* if ( $post && ! empty( $post->post_content_filtered ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2100 |
* $css = $post->post_content_filtered; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2101 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2102 |
* return $css; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2103 |
* }, 10, 2 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2104 |
* </code> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2105 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2106 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2107 |
* @param array $data { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2108 |
* Custom CSS data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2109 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2110 |
* @type string $css CSS stored in `post_content`. |
19 | 2111 |
* @type string $preprocessed Pre-processed CSS stored in `post_content_filtered`. |
2112 |
* Normally empty string. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2113 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2114 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2115 |
* The args passed into `wp_update_custom_css_post()` merged with defaults. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2116 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2117 |
* @type string $css The original CSS passed in to be updated. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2118 |
* @type string $preprocessed The original preprocessed CSS passed in to be updated. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2119 |
* @type string $stylesheet The stylesheet (theme) being updated. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2120 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2121 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2122 |
$data = apply_filters( 'update_custom_css_data', $data, array_merge( $args, compact( 'css' ) ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2123 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2124 |
$post_data = array( |
9 | 2125 |
'post_title' => $args['stylesheet'], |
2126 |
'post_name' => sanitize_title( $args['stylesheet'] ), |
|
2127 |
'post_type' => 'custom_css', |
|
2128 |
'post_status' => 'publish', |
|
2129 |
'post_content' => $data['css'], |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2130 |
'post_content_filtered' => $data['preprocessed'], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2131 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2132 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2133 |
// Update post if it already exists, otherwise create a new one. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2134 |
$post = wp_get_custom_css_post( $args['stylesheet'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2135 |
if ( $post ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2136 |
$post_data['ID'] = $post->ID; |
9 | 2137 |
$r = wp_update_post( wp_slash( $post_data ), true ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2138 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2139 |
$r = wp_insert_post( wp_slash( $post_data ), true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2140 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2141 |
if ( ! is_wp_error( $r ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2142 |
if ( get_stylesheet() === $args['stylesheet'] ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2143 |
set_theme_mod( 'custom_css_post_id', $r ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2144 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2145 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2146 |
// Trigger creation of a revision. This should be removed once #30854 is resolved. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2147 |
$revisions = wp_get_latest_revision_id_and_total_count( $r ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2148 |
if ( ! is_wp_error( $revisions ) && 0 === $revisions['count'] ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2149 |
wp_save_post_revision( $r ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2150 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2151 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2152 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2153 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2154 |
if ( is_wp_error( $r ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2155 |
return $r; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2156 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2157 |
return get_post( $r ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2158 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2159 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2160 |
/** |
16 | 2161 |
* Adds callback for custom TinyMCE editor stylesheets. |
0 | 2162 |
* |
2163 |
* The parameter $stylesheet is the name of the stylesheet, relative to |
|
2164 |
* the theme root. It also accepts an array of stylesheets. |
|
2165 |
* It is optional and defaults to 'editor-style.css'. |
|
2166 |
* |
|
2167 |
* This function automatically adds another stylesheet with -rtl prefix, e.g. editor-style-rtl.css. |
|
2168 |
* If that file doesn't exist, it is removed before adding the stylesheet(s) to TinyMCE. |
|
2169 |
* If an array of stylesheets is passed to add_editor_style(), |
|
2170 |
* RTL is only added for the first stylesheet. |
|
2171 |
* |
|
2172 |
* Since version 3.4 the TinyMCE body has .rtl CSS class. |
|
2173 |
* It is a better option to use that class and add any RTL styles to the main stylesheet. |
|
2174 |
* |
|
2175 |
* @since 3.0.0 |
|
2176 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2177 |
* @global array $editor_styles |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2178 |
* |
5 | 2179 |
* @param array|string $stylesheet Optional. Stylesheet name or array thereof, relative to theme root. |
9 | 2180 |
* Defaults to 'editor-style.css' |
0 | 2181 |
*/ |
2182 |
function add_editor_style( $stylesheet = 'editor-style.css' ) { |
|
16 | 2183 |
global $editor_styles; |
2184 |
||
0 | 2185 |
add_theme_support( 'editor-style' ); |
2186 |
||
2187 |
$editor_styles = (array) $editor_styles; |
|
2188 |
$stylesheet = (array) $stylesheet; |
|
16 | 2189 |
|
0 | 2190 |
if ( is_rtl() ) { |
9 | 2191 |
$rtl_stylesheet = str_replace( '.css', '-rtl.css', $stylesheet[0] ); |
2192 |
$stylesheet[] = $rtl_stylesheet; |
|
0 | 2193 |
} |
2194 |
||
2195 |
$editor_styles = array_merge( $editor_styles, $stylesheet ); |
|
2196 |
} |
|
2197 |
||
2198 |
/** |
|
2199 |
* Removes all visual editor stylesheets. |
|
2200 |
* |
|
2201 |
* @since 3.1.0 |
|
2202 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2203 |
* @global array $editor_styles |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2204 |
* |
0 | 2205 |
* @return bool True on success, false if there were no stylesheets to remove. |
2206 |
*/ |
|
2207 |
function remove_editor_styles() { |
|
9 | 2208 |
if ( ! current_theme_supports( 'editor-style' ) ) { |
0 | 2209 |
return false; |
9 | 2210 |
} |
0 | 2211 |
_remove_theme_support( 'editor-style' ); |
9 | 2212 |
if ( is_admin() ) { |
0 | 2213 |
$GLOBALS['editor_styles'] = array(); |
9 | 2214 |
} |
0 | 2215 |
return true; |
2216 |
} |
|
2217 |
||
2218 |
/** |
|
16 | 2219 |
* Retrieves any registered editor stylesheet URLs. |
5 | 2220 |
* |
2221 |
* @since 4.0.0 |
|
2222 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2223 |
* @global array $editor_styles Registered editor stylesheets |
5 | 2224 |
* |
16 | 2225 |
* @return string[] If registered, a list of editor stylesheet URLs. |
5 | 2226 |
*/ |
2227 |
function get_editor_stylesheets() { |
|
2228 |
$stylesheets = array(); |
|
19 | 2229 |
// Load editor_style.css if the active theme supports it. |
5 | 2230 |
if ( ! empty( $GLOBALS['editor_styles'] ) && is_array( $GLOBALS['editor_styles'] ) ) { |
2231 |
$editor_styles = $GLOBALS['editor_styles']; |
|
2232 |
||
2233 |
$editor_styles = array_unique( array_filter( $editor_styles ) ); |
|
9 | 2234 |
$style_uri = get_stylesheet_directory_uri(); |
2235 |
$style_dir = get_stylesheet_directory(); |
|
5 | 2236 |
|
2237 |
// Support externally referenced styles (like, say, fonts). |
|
2238 |
foreach ( $editor_styles as $key => $file ) { |
|
2239 |
if ( preg_match( '~^(https?:)?//~', $file ) ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2240 |
$stylesheets[] = sanitize_url( $file ); |
5 | 2241 |
unset( $editor_styles[ $key ] ); |
2242 |
} |
|
2243 |
} |
|
2244 |
||
2245 |
// Look in a parent theme first, that way child theme CSS overrides. |
|
2246 |
if ( is_child_theme() ) { |
|
2247 |
$template_uri = get_template_directory_uri(); |
|
2248 |
$template_dir = get_template_directory(); |
|
2249 |
||
2250 |
foreach ( $editor_styles as $key => $file ) { |
|
2251 |
if ( $file && file_exists( "$template_dir/$file" ) ) { |
|
2252 |
$stylesheets[] = "$template_uri/$file"; |
|
2253 |
} |
|
2254 |
} |
|
2255 |
} |
|
2256 |
||
2257 |
foreach ( $editor_styles as $file ) { |
|
2258 |
if ( $file && file_exists( "$style_dir/$file" ) ) { |
|
2259 |
$stylesheets[] = "$style_uri/$file"; |
|
2260 |
} |
|
2261 |
} |
|
2262 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2263 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2264 |
/** |
16 | 2265 |
* Filters the array of URLs of stylesheets applied to the editor. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2266 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2267 |
* @since 4.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2268 |
* |
16 | 2269 |
* @param string[] $stylesheets Array of URLs of stylesheets to be applied to the editor. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2270 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2271 |
return apply_filters( 'editor_stylesheets', $stylesheets ); |
5 | 2272 |
} |
2273 |
||
2274 |
/** |
|
16 | 2275 |
* Expands a theme's starter content configuration using core-provided data. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2276 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2277 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2278 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2279 |
* @return array Array of starter content. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2280 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2281 |
function get_theme_starter_content() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2282 |
$theme_support = get_theme_support( 'starter-content' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2283 |
if ( is_array( $theme_support ) && ! empty( $theme_support[0] ) && is_array( $theme_support[0] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2284 |
$config = $theme_support[0]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2285 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2286 |
$config = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2287 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2288 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2289 |
$core_content = array( |
9 | 2290 |
'widgets' => array( |
2291 |
'text_business_info' => array( |
|
2292 |
'text', |
|
2293 |
array( |
|
2294 |
'title' => _x( 'Find Us', 'Theme starter content' ), |
|
18 | 2295 |
'text' => implode( |
9 | 2296 |
'', |
2297 |
array( |
|
2298 |
'<strong>' . _x( 'Address', 'Theme starter content' ) . "</strong>\n", |
|
19 | 2299 |
_x( '123 Main Street', 'Theme starter content' ) . "\n", |
2300 |
_x( 'New York, NY 10001', 'Theme starter content' ) . "\n\n", |
|
9 | 2301 |
'<strong>' . _x( 'Hours', 'Theme starter content' ) . "</strong>\n", |
19 | 2302 |
_x( 'Monday–Friday: 9:00AM–5:00PM', 'Theme starter content' ) . "\n", |
2303 |
_x( 'Saturday & Sunday: 11:00AM–3:00PM', 'Theme starter content' ), |
|
9 | 2304 |
) |
2305 |
), |
|
2306 |
'filter' => true, |
|
2307 |
'visual' => true, |
|
2308 |
), |
|
2309 |
), |
|
2310 |
'text_about' => array( |
|
2311 |
'text', |
|
2312 |
array( |
|
2313 |
'title' => _x( 'About This Site', 'Theme starter content' ), |
|
2314 |
'text' => _x( 'This may be a good place to introduce yourself and your site or include some credits.', 'Theme starter content' ), |
|
2315 |
'filter' => true, |
|
2316 |
'visual' => true, |
|
2317 |
), |
|
2318 |
), |
|
2319 |
'archives' => array( |
|
2320 |
'archives', |
|
2321 |
array( |
|
2322 |
'title' => _x( 'Archives', 'Theme starter content' ), |
|
2323 |
), |
|
2324 |
), |
|
2325 |
'calendar' => array( |
|
2326 |
'calendar', |
|
2327 |
array( |
|
2328 |
'title' => _x( 'Calendar', 'Theme starter content' ), |
|
2329 |
), |
|
2330 |
), |
|
2331 |
'categories' => array( |
|
2332 |
'categories', |
|
2333 |
array( |
|
2334 |
'title' => _x( 'Categories', 'Theme starter content' ), |
|
2335 |
), |
|
2336 |
), |
|
2337 |
'meta' => array( |
|
2338 |
'meta', |
|
2339 |
array( |
|
2340 |
'title' => _x( 'Meta', 'Theme starter content' ), |
|
2341 |
), |
|
2342 |
), |
|
2343 |
'recent-comments' => array( |
|
2344 |
'recent-comments', |
|
2345 |
array( |
|
2346 |
'title' => _x( 'Recent Comments', 'Theme starter content' ), |
|
2347 |
), |
|
2348 |
), |
|
2349 |
'recent-posts' => array( |
|
2350 |
'recent-posts', |
|
2351 |
array( |
|
2352 |
'title' => _x( 'Recent Posts', 'Theme starter content' ), |
|
2353 |
), |
|
2354 |
), |
|
2355 |
'search' => array( |
|
2356 |
'search', |
|
2357 |
array( |
|
2358 |
'title' => _x( 'Search', 'Theme starter content' ), |
|
2359 |
), |
|
2360 |
), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2361 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2362 |
'nav_menus' => array( |
9 | 2363 |
'link_home' => array( |
2364 |
'type' => 'custom', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2365 |
'title' => _x( 'Home', 'Theme starter content' ), |
9 | 2366 |
'url' => home_url( '/' ), |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2367 |
), |
16 | 2368 |
'page_home' => array( // Deprecated in favor of 'link_home'. |
9 | 2369 |
'type' => 'post_type', |
2370 |
'object' => 'page', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2371 |
'object_id' => '{{home}}', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2372 |
), |
9 | 2373 |
'page_about' => array( |
2374 |
'type' => 'post_type', |
|
2375 |
'object' => 'page', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2376 |
'object_id' => '{{about}}', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2377 |
), |
9 | 2378 |
'page_blog' => array( |
2379 |
'type' => 'post_type', |
|
2380 |
'object' => 'page', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2381 |
'object_id' => '{{blog}}', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2382 |
), |
9 | 2383 |
'page_news' => array( |
2384 |
'type' => 'post_type', |
|
2385 |
'object' => 'page', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2386 |
'object_id' => '{{news}}', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2387 |
), |
9 | 2388 |
'page_contact' => array( |
2389 |
'type' => 'post_type', |
|
2390 |
'object' => 'page', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2391 |
'object_id' => '{{contact}}', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2392 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2393 |
|
9 | 2394 |
'link_email' => array( |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2395 |
'title' => _x( 'Email', 'Theme starter content' ), |
9 | 2396 |
'url' => 'mailto:wordpress@example.com', |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2397 |
), |
9 | 2398 |
'link_facebook' => array( |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2399 |
'title' => _x( 'Facebook', 'Theme starter content' ), |
9 | 2400 |
'url' => 'https://www.facebook.com/wordpress', |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2401 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2402 |
'link_foursquare' => array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2403 |
'title' => _x( 'Foursquare', 'Theme starter content' ), |
9 | 2404 |
'url' => 'https://foursquare.com/', |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2405 |
), |
9 | 2406 |
'link_github' => array( |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2407 |
'title' => _x( 'GitHub', 'Theme starter content' ), |
9 | 2408 |
'url' => 'https://github.com/wordpress/', |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2409 |
), |
9 | 2410 |
'link_instagram' => array( |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2411 |
'title' => _x( 'Instagram', 'Theme starter content' ), |
9 | 2412 |
'url' => 'https://www.instagram.com/explore/tags/wordcamp/', |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2413 |
), |
9 | 2414 |
'link_linkedin' => array( |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2415 |
'title' => _x( 'LinkedIn', 'Theme starter content' ), |
9 | 2416 |
'url' => 'https://www.linkedin.com/company/1089783', |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2417 |
), |
9 | 2418 |
'link_pinterest' => array( |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2419 |
'title' => _x( 'Pinterest', 'Theme starter content' ), |
9 | 2420 |
'url' => 'https://www.pinterest.com/', |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2421 |
), |
9 | 2422 |
'link_twitter' => array( |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2423 |
'title' => _x( 'Twitter', 'Theme starter content' ), |
9 | 2424 |
'url' => 'https://twitter.com/wordpress', |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2425 |
), |
9 | 2426 |
'link_yelp' => array( |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2427 |
'title' => _x( 'Yelp', 'Theme starter content' ), |
9 | 2428 |
'url' => 'https://www.yelp.com', |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2429 |
), |
9 | 2430 |
'link_youtube' => array( |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2431 |
'title' => _x( 'YouTube', 'Theme starter content' ), |
9 | 2432 |
'url' => 'https://www.youtube.com/channel/UCdof4Ju7amm1chz1gi1T2ZA', |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2433 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2434 |
), |
9 | 2435 |
'posts' => array( |
2436 |
'home' => array( |
|
2437 |
'post_type' => 'page', |
|
2438 |
'post_title' => _x( 'Home', 'Theme starter content' ), |
|
16 | 2439 |
'post_content' => sprintf( |
2440 |
"<!-- wp:paragraph -->\n<p>%s</p>\n<!-- /wp:paragraph -->", |
|
2441 |
_x( 'Welcome to your site! This is your homepage, which is what most visitors will see when they come to your site for the first time.', 'Theme starter content' ) |
|
2442 |
), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2443 |
), |
9 | 2444 |
'about' => array( |
2445 |
'post_type' => 'page', |
|
2446 |
'post_title' => _x( 'About', 'Theme starter content' ), |
|
16 | 2447 |
'post_content' => sprintf( |
2448 |
"<!-- wp:paragraph -->\n<p>%s</p>\n<!-- /wp:paragraph -->", |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2449 |
_x( 'You might be an artist who would like to introduce yourself and your work here or maybe you are a business with a mission to describe.', 'Theme starter content' ) |
16 | 2450 |
), |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2451 |
), |
9 | 2452 |
'contact' => array( |
2453 |
'post_type' => 'page', |
|
2454 |
'post_title' => _x( 'Contact', 'Theme starter content' ), |
|
16 | 2455 |
'post_content' => sprintf( |
2456 |
"<!-- wp:paragraph -->\n<p>%s</p>\n<!-- /wp:paragraph -->", |
|
2457 |
_x( 'This is a page with some basic contact information, such as an address and phone number. You might also try a plugin to add a contact form.', 'Theme starter content' ) |
|
2458 |
), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2459 |
), |
9 | 2460 |
'blog' => array( |
2461 |
'post_type' => 'page', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2462 |
'post_title' => _x( 'Blog', 'Theme starter content' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2463 |
), |
9 | 2464 |
'news' => array( |
2465 |
'post_type' => 'page', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2466 |
'post_title' => _x( 'News', 'Theme starter content' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2467 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2468 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2469 |
'homepage-section' => array( |
9 | 2470 |
'post_type' => 'page', |
2471 |
'post_title' => _x( 'A homepage section', 'Theme starter content' ), |
|
16 | 2472 |
'post_content' => sprintf( |
2473 |
"<!-- wp:paragraph -->\n<p>%s</p>\n<!-- /wp:paragraph -->", |
|
2474 |
_x( 'This is an example of a homepage section. Homepage sections can be any page other than the homepage itself, including the page that shows your latest blog posts.', 'Theme starter content' ) |
|
2475 |
), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2476 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2477 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2478 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2479 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2480 |
$content = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2481 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2482 |
foreach ( $config as $type => $args ) { |
9 | 2483 |
switch ( $type ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2484 |
// Use options and theme_mods as-is. |
9 | 2485 |
case 'options': |
2486 |
case 'theme_mods': |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2487 |
$content[ $type ] = $config[ $type ]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2488 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2489 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2490 |
// Widgets are grouped into sidebars. |
9 | 2491 |
case 'widgets': |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2492 |
foreach ( $config[ $type ] as $sidebar_id => $widgets ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2493 |
foreach ( $widgets as $id => $widget ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2494 |
if ( is_array( $widget ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2495 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2496 |
// Item extends core content. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2497 |
if ( ! empty( $core_content[ $type ][ $id ] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2498 |
$widget = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2499 |
$core_content[ $type ][ $id ][0], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2500 |
array_merge( $core_content[ $type ][ $id ][1], $widget ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2501 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2502 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2503 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2504 |
$content[ $type ][ $sidebar_id ][] = $widget; |
19 | 2505 |
} elseif ( is_string( $widget ) |
2506 |
&& ! empty( $core_content[ $type ] ) |
|
2507 |
&& ! empty( $core_content[ $type ][ $widget ] ) |
|
2508 |
) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2509 |
$content[ $type ][ $sidebar_id ][] = $core_content[ $type ][ $widget ]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2510 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2511 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2512 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2513 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2514 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2515 |
// And nav menu items are grouped into nav menus. |
9 | 2516 |
case 'nav_menus': |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2517 |
foreach ( $config[ $type ] as $nav_menu_location => $nav_menu ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2518 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2519 |
// Ensure nav menus get a name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2520 |
if ( empty( $nav_menu['name'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2521 |
$nav_menu['name'] = $nav_menu_location; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2522 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2523 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2524 |
$content[ $type ][ $nav_menu_location ]['name'] = $nav_menu['name']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2525 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2526 |
foreach ( $nav_menu['items'] as $id => $nav_menu_item ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2527 |
if ( is_array( $nav_menu_item ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2528 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2529 |
// Item extends core content. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2530 |
if ( ! empty( $core_content[ $type ][ $id ] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2531 |
$nav_menu_item = array_merge( $core_content[ $type ][ $id ], $nav_menu_item ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2532 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2533 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2534 |
$content[ $type ][ $nav_menu_location ]['items'][] = $nav_menu_item; |
19 | 2535 |
} elseif ( is_string( $nav_menu_item ) |
2536 |
&& ! empty( $core_content[ $type ] ) |
|
2537 |
&& ! empty( $core_content[ $type ][ $nav_menu_item ] ) |
|
2538 |
) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2539 |
$content[ $type ][ $nav_menu_location ]['items'][] = $core_content[ $type ][ $nav_menu_item ]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2540 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2541 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2542 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2543 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2544 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2545 |
// Attachments are posts but have special treatment. |
9 | 2546 |
case 'attachments': |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2547 |
foreach ( $config[ $type ] as $id => $item ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2548 |
if ( ! empty( $item['file'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2549 |
$content[ $type ][ $id ] = $item; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2550 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2551 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2552 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2553 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2554 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2555 |
* All that's left now are posts (besides attachments). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2556 |
* Not a default case for the sake of clarity and future work. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2557 |
*/ |
9 | 2558 |
case 'posts': |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2559 |
foreach ( $config[ $type ] as $id => $item ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2560 |
if ( is_array( $item ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2561 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2562 |
// Item extends core content. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2563 |
if ( ! empty( $core_content[ $type ][ $id ] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2564 |
$item = array_merge( $core_content[ $type ][ $id ], $item ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2565 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2566 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2567 |
// Enforce a subset of fields. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2568 |
$content[ $type ][ $id ] = wp_array_slice_assoc( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2569 |
$item, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2570 |
array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2571 |
'post_type', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2572 |
'post_title', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2573 |
'post_excerpt', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2574 |
'post_name', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2575 |
'post_content', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2576 |
'menu_order', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2577 |
'comment_status', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2578 |
'thumbnail', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2579 |
'template', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2580 |
) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2581 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2582 |
} elseif ( is_string( $item ) && ! empty( $core_content[ $type ][ $item ] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2583 |
$content[ $type ][ $item ] = $core_content[ $type ][ $item ]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2584 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2585 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2586 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2587 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2588 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2589 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2590 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2591 |
* Filters the expanded array of starter content. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2592 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2593 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2594 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2595 |
* @param array $content Array of starter content. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2596 |
* @param array $config Array of theme-specific starter content configuration. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2597 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2598 |
return apply_filters( 'get_theme_starter_content', $content, $config ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2599 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2600 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2601 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2602 |
* Registers theme support for a given feature. |
0 | 2603 |
* |
2604 |
* Must be called in the theme's functions.php file to work. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2605 |
* If attached to a hook, it must be {@see 'after_setup_theme'}. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2606 |
* The {@see 'init'} hook may be too late for some features. |
0 | 2607 |
* |
16 | 2608 |
* Example usage: |
2609 |
* |
|
2610 |
* add_theme_support( 'title-tag' ); |
|
2611 |
* add_theme_support( 'custom-logo', array( |
|
2612 |
* 'height' => 480, |
|
2613 |
* 'width' => 720, |
|
2614 |
* ) ); |
|
2615 |
* |
|
0 | 2616 |
* @since 2.9.0 |
16 | 2617 |
* @since 3.4.0 The `custom-header-uploads` feature was deprecated. |
2618 |
* @since 3.6.0 The `html5` feature was added. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2619 |
* @since 3.6.1 The `html5` feature requires an array of types to be passed. Defaults to |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2620 |
* 'comment-list', 'comment-form', 'search-form' for backward compatibility. |
16 | 2621 |
* @since 3.9.0 The `html5` feature now also accepts 'gallery' and 'caption'. |
2622 |
* @since 4.1.0 The `title-tag` feature was added. |
|
2623 |
* @since 4.5.0 The `customize-selective-refresh-widgets` feature was added. |
|
2624 |
* @since 4.7.0 The `starter-content` feature was added. |
|
9 | 2625 |
* @since 5.0.0 The `responsive-embeds`, `align-wide`, `dark-editor-style`, `disable-custom-colors`, |
16 | 2626 |
* `disable-custom-font-sizes`, `editor-color-palette`, `editor-font-sizes`, |
9 | 2627 |
* `editor-styles`, and `wp-block-styles` features were added. |
16 | 2628 |
* @since 5.3.0 The `html5` feature now also accepts 'script' and 'style'. |
2629 |
* @since 5.3.0 Formalized the existing and already documented `...$args` parameter |
|
2630 |
* by adding it to the function signature. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2631 |
* @since 5.4.0 The `disable-custom-gradients` feature limits to default gradients or gradients added |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2632 |
* through `editor-gradient-presets` theme support. |
16 | 2633 |
* @since 5.5.0 The `core-block-patterns` feature was added and is enabled by default. |
2634 |
* @since 5.5.0 The `custom-logo` feature now also accepts 'unlink-homepage-logo'. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2635 |
* @since 5.6.0 The `post-formats` feature warns if no array is passed as the second parameter. |
18 | 2636 |
* @since 5.8.0 The `widgets-block-editor` feature enables the Widgets block editor. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2637 |
* @since 5.8.0 The `block-templates` feature indicates whether a theme uses block-based templates. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2638 |
* @since 6.0.0 The `html5` feature warns if no array is passed as the second parameter. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2639 |
* @since 6.1.0 The `block-template-parts` feature allows to edit any reusable template part from site editor. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2640 |
* @since 6.1.0 The `disable-layout-styles` feature disables the default layout styles. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2641 |
* @since 6.3.0 The `link-color` feature allows to enable the link color setting. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2642 |
* @since 6.3.0 The `border` feature allows themes without theme.json to add border styles to blocks. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2643 |
* @since 6.5.0 The `appearance-tools` feature enables a few design tools for blocks, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2644 |
* see `WP_Theme_JSON::APPEARANCE_TOOLS_OPT_INS` for a complete list. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2645 |
* @since 6.6.0 The `editor-spacing-sizes` feature was added. |
5 | 2646 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2647 |
* @global array $_wp_theme_features |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2648 |
* |
18 | 2649 |
* @param string $feature The feature being added. Likely core values include: |
2650 |
* - 'admin-bar' |
|
2651 |
* - 'align-wide' |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2652 |
* - 'appearance-tools' |
18 | 2653 |
* - 'automatic-feed-links' |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2654 |
* - 'block-templates' |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2655 |
* - 'block-template-parts' |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2656 |
* - 'border' |
18 | 2657 |
* - 'core-block-patterns' |
2658 |
* - 'custom-background' |
|
2659 |
* - 'custom-header' |
|
2660 |
* - 'custom-line-height' |
|
2661 |
* - 'custom-logo' |
|
2662 |
* - 'customize-selective-refresh-widgets' |
|
2663 |
* - 'custom-spacing' |
|
2664 |
* - 'custom-units' |
|
2665 |
* - 'dark-editor-style' |
|
2666 |
* - 'disable-custom-colors' |
|
2667 |
* - 'disable-custom-font-sizes' |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2668 |
* - 'disable-custom-gradients' |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2669 |
* - 'disable-layout-styles' |
18 | 2670 |
* - 'editor-color-palette' |
2671 |
* - 'editor-gradient-presets' |
|
2672 |
* - 'editor-font-sizes' |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2673 |
* - 'editor-spacing-sizes' |
18 | 2674 |
* - 'editor-styles' |
2675 |
* - 'featured-content' |
|
2676 |
* - 'html5' |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2677 |
* - 'link-color' |
18 | 2678 |
* - 'menus' |
2679 |
* - 'post-formats' |
|
2680 |
* - 'post-thumbnails' |
|
2681 |
* - 'responsive-embeds' |
|
2682 |
* - 'starter-content' |
|
2683 |
* - 'title-tag' |
|
2684 |
* - 'widgets' |
|
2685 |
* - 'widgets-block-editor' |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2686 |
* - 'wp-block-styles' |
16 | 2687 |
* @param mixed ...$args Optional extra arguments to pass along with certain features. |
18 | 2688 |
* @return void|false Void on success, false on failure. |
0 | 2689 |
*/ |
16 | 2690 |
function add_theme_support( $feature, ...$args ) { |
0 | 2691 |
global $_wp_theme_features; |
2692 |
||
16 | 2693 |
if ( ! $args ) { |
0 | 2694 |
$args = true; |
9 | 2695 |
} |
0 | 2696 |
|
2697 |
switch ( $feature ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2698 |
case 'post-thumbnails': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2699 |
// All post types are already supported. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2700 |
if ( true === get_theme_support( 'post-thumbnails' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2701 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2702 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2703 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2704 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2705 |
* Merge post types with any that already declared their support |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2706 |
* for post thumbnails. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2707 |
*/ |
16 | 2708 |
if ( isset( $args[0] ) && is_array( $args[0] ) && isset( $_wp_theme_features['post-thumbnails'] ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2709 |
$args[0] = array_unique( array_merge( $_wp_theme_features['post-thumbnails'][0], $args[0] ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2710 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2711 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2712 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2713 |
|
9 | 2714 |
case 'post-formats': |
16 | 2715 |
if ( isset( $args[0] ) && is_array( $args[0] ) ) { |
5 | 2716 |
$post_formats = get_post_format_slugs(); |
2717 |
unset( $post_formats['standard'] ); |
|
2718 |
||
2719 |
$args[0] = array_intersect( $args[0], array_keys( $post_formats ) ); |
|
18 | 2720 |
} else { |
19 | 2721 |
_doing_it_wrong( |
2722 |
"add_theme_support( 'post-formats' )", |
|
2723 |
__( 'You need to pass an array of post formats.' ), |
|
2724 |
'5.6.0' |
|
2725 |
); |
|
18 | 2726 |
return false; |
5 | 2727 |
} |
0 | 2728 |
break; |
2729 |
||
9 | 2730 |
case 'html5': |
0 | 2731 |
// You can't just pass 'html5', you need to pass an array of types. |
19 | 2732 |
if ( empty( $args[0] ) || ! is_array( $args[0] ) ) { |
2733 |
_doing_it_wrong( |
|
2734 |
"add_theme_support( 'html5' )", |
|
2735 |
__( 'You need to pass an array of types.' ), |
|
2736 |
'3.6.1' |
|
2737 |
); |
|
2738 |
||
2739 |
if ( ! empty( $args[0] ) && ! is_array( $args[0] ) ) { |
|
2740 |
return false; |
|
2741 |
} |
|
2742 |
||
5 | 2743 |
// Build an array of types for back-compat. |
0 | 2744 |
$args = array( 0 => array( 'comment-list', 'comment-form', 'search-form' ) ); |
2745 |
} |
|
2746 |
||
2747 |
// Calling 'html5' again merges, rather than overwrites. |
|
9 | 2748 |
if ( isset( $_wp_theme_features['html5'] ) ) { |
0 | 2749 |
$args[0] = array_merge( $_wp_theme_features['html5'][0], $args[0] ); |
9 | 2750 |
} |
0 | 2751 |
break; |
2752 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2753 |
case 'custom-logo': |
16 | 2754 |
if ( true === $args ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2755 |
$args = array( 0 => array() ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2756 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2757 |
$defaults = array( |
16 | 2758 |
'width' => null, |
2759 |
'height' => null, |
|
2760 |
'flex-width' => false, |
|
2761 |
'flex-height' => false, |
|
2762 |
'header-text' => '', |
|
2763 |
'unlink-homepage-logo' => false, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2764 |
); |
9 | 2765 |
$args[0] = wp_parse_args( array_intersect_key( $args[0], $defaults ), $defaults ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2766 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2767 |
// Allow full flexibility if no size is specified. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2768 |
if ( is_null( $args[0]['width'] ) && is_null( $args[0]['height'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2769 |
$args[0]['flex-width'] = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2770 |
$args[0]['flex-height'] = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2771 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2772 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2773 |
|
9 | 2774 |
case 'custom-header-uploads': |
0 | 2775 |
return add_theme_support( 'custom-header', array( 'uploads' => true ) ); |
2776 |
||
9 | 2777 |
case 'custom-header': |
16 | 2778 |
if ( true === $args ) { |
0 | 2779 |
$args = array( 0 => array() ); |
9 | 2780 |
} |
0 | 2781 |
|
2782 |
$defaults = array( |
|
9 | 2783 |
'default-image' => '', |
2784 |
'random-default' => false, |
|
2785 |
'width' => 0, |
|
2786 |
'height' => 0, |
|
2787 |
'flex-height' => false, |
|
2788 |
'flex-width' => false, |
|
2789 |
'default-text-color' => '', |
|
2790 |
'header-text' => true, |
|
2791 |
'uploads' => true, |
|
2792 |
'wp-head-callback' => '', |
|
2793 |
'admin-head-callback' => '', |
|
0 | 2794 |
'admin-preview-callback' => '', |
9 | 2795 |
'video' => false, |
2796 |
'video-active-callback' => 'is_front_page', |
|
0 | 2797 |
); |
2798 |
||
2799 |
$jit = isset( $args[0]['__jit'] ); |
|
2800 |
unset( $args[0]['__jit'] ); |
|
2801 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2802 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2803 |
* Merge in data from previous add_theme_support() calls. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2804 |
* The first value registered wins. (A child theme is set up first.) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2805 |
*/ |
9 | 2806 |
if ( isset( $_wp_theme_features['custom-header'] ) ) { |
0 | 2807 |
$args[0] = wp_parse_args( $_wp_theme_features['custom-header'][0], $args[0] ); |
9 | 2808 |
} |
0 | 2809 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2810 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2811 |
* Load in the defaults at the end, as we need to insure first one wins. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2812 |
* This will cause all constants to be defined, as each arg will then be set to the default. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2813 |
*/ |
9 | 2814 |
if ( $jit ) { |
0 | 2815 |
$args[0] = wp_parse_args( $args[0], $defaults ); |
9 | 2816 |
} |
0 | 2817 |
|
16 | 2818 |
/* |
2819 |
* If a constant was defined, use that value. Otherwise, define the constant to ensure |
|
2820 |
* the constant is always accurate (and is not defined later, overriding our value). |
|
2821 |
* As stated above, the first value wins. |
|
2822 |
* Once we get to wp_loaded (just-in-time), define any constants we haven't already. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2823 |
* Constants should be avoided. Don't reference them. This is just for backward compatibility. |
16 | 2824 |
*/ |
0 | 2825 |
|
9 | 2826 |
if ( defined( 'NO_HEADER_TEXT' ) ) { |
0 | 2827 |
$args[0]['header-text'] = ! NO_HEADER_TEXT; |
9 | 2828 |
} elseif ( isset( $args[0]['header-text'] ) ) { |
0 | 2829 |
define( 'NO_HEADER_TEXT', empty( $args[0]['header-text'] ) ); |
9 | 2830 |
} |
2831 |
||
2832 |
if ( defined( 'HEADER_IMAGE_WIDTH' ) ) { |
|
0 | 2833 |
$args[0]['width'] = (int) HEADER_IMAGE_WIDTH; |
9 | 2834 |
} elseif ( isset( $args[0]['width'] ) ) { |
0 | 2835 |
define( 'HEADER_IMAGE_WIDTH', (int) $args[0]['width'] ); |
9 | 2836 |
} |
2837 |
||
2838 |
if ( defined( 'HEADER_IMAGE_HEIGHT' ) ) { |
|
0 | 2839 |
$args[0]['height'] = (int) HEADER_IMAGE_HEIGHT; |
9 | 2840 |
} elseif ( isset( $args[0]['height'] ) ) { |
0 | 2841 |
define( 'HEADER_IMAGE_HEIGHT', (int) $args[0]['height'] ); |
9 | 2842 |
} |
2843 |
||
2844 |
if ( defined( 'HEADER_TEXTCOLOR' ) ) { |
|
0 | 2845 |
$args[0]['default-text-color'] = HEADER_TEXTCOLOR; |
9 | 2846 |
} elseif ( isset( $args[0]['default-text-color'] ) ) { |
0 | 2847 |
define( 'HEADER_TEXTCOLOR', $args[0]['default-text-color'] ); |
9 | 2848 |
} |
2849 |
||
2850 |
if ( defined( 'HEADER_IMAGE' ) ) { |
|
0 | 2851 |
$args[0]['default-image'] = HEADER_IMAGE; |
9 | 2852 |
} elseif ( isset( $args[0]['default-image'] ) ) { |
0 | 2853 |
define( 'HEADER_IMAGE', $args[0]['default-image'] ); |
9 | 2854 |
} |
2855 |
||
2856 |
if ( $jit && ! empty( $args[0]['default-image'] ) ) { |
|
0 | 2857 |
$args[0]['random-default'] = false; |
9 | 2858 |
} |
0 | 2859 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2860 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2861 |
* If headers are supported, and we still don't have a defined width or height, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2862 |
* we have implicit flex sizes. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2863 |
*/ |
0 | 2864 |
if ( $jit ) { |
9 | 2865 |
if ( empty( $args[0]['width'] ) && empty( $args[0]['flex-width'] ) ) { |
0 | 2866 |
$args[0]['flex-width'] = true; |
9 | 2867 |
} |
2868 |
if ( empty( $args[0]['height'] ) && empty( $args[0]['flex-height'] ) ) { |
|
0 | 2869 |
$args[0]['flex-height'] = true; |
9 | 2870 |
} |
0 | 2871 |
} |
2872 |
||
2873 |
break; |
|
2874 |
||
9 | 2875 |
case 'custom-background': |
16 | 2876 |
if ( true === $args ) { |
0 | 2877 |
$args = array( 0 => array() ); |
9 | 2878 |
} |
0 | 2879 |
|
2880 |
$defaults = array( |
|
5 | 2881 |
'default-image' => '', |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2882 |
'default-preset' => 'default', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2883 |
'default-position-x' => 'left', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2884 |
'default-position-y' => 'top', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2885 |
'default-size' => 'auto', |
5 | 2886 |
'default-repeat' => 'repeat', |
2887 |
'default-attachment' => 'scroll', |
|
2888 |
'default-color' => '', |
|
2889 |
'wp-head-callback' => '_custom_background_cb', |
|
2890 |
'admin-head-callback' => '', |
|
0 | 2891 |
'admin-preview-callback' => '', |
2892 |
); |
|
2893 |
||
2894 |
$jit = isset( $args[0]['__jit'] ); |
|
2895 |
unset( $args[0]['__jit'] ); |
|
2896 |
||
2897 |
// Merge in data from previous add_theme_support() calls. The first value registered wins. |
|
9 | 2898 |
if ( isset( $_wp_theme_features['custom-background'] ) ) { |
0 | 2899 |
$args[0] = wp_parse_args( $_wp_theme_features['custom-background'][0], $args[0] ); |
9 | 2900 |
} |
2901 |
||
2902 |
if ( $jit ) { |
|
0 | 2903 |
$args[0] = wp_parse_args( $args[0], $defaults ); |
9 | 2904 |
} |
2905 |
||
2906 |
if ( defined( 'BACKGROUND_COLOR' ) ) { |
|
0 | 2907 |
$args[0]['default-color'] = BACKGROUND_COLOR; |
9 | 2908 |
} elseif ( isset( $args[0]['default-color'] ) || $jit ) { |
0 | 2909 |
define( 'BACKGROUND_COLOR', $args[0]['default-color'] ); |
9 | 2910 |
} |
2911 |
||
2912 |
if ( defined( 'BACKGROUND_IMAGE' ) ) { |
|
0 | 2913 |
$args[0]['default-image'] = BACKGROUND_IMAGE; |
9 | 2914 |
} elseif ( isset( $args[0]['default-image'] ) || $jit ) { |
0 | 2915 |
define( 'BACKGROUND_IMAGE', $args[0]['default-image'] ); |
9 | 2916 |
} |
0 | 2917 |
|
2918 |
break; |
|
5 | 2919 |
|
2920 |
// Ensure that 'title-tag' is accessible in the admin. |
|
9 | 2921 |
case 'title-tag': |
5 | 2922 |
// Can be called in functions.php but must happen before wp_loaded, i.e. not in header.php. |
2923 |
if ( did_action( 'wp_loaded' ) ) { |
|
9 | 2924 |
_doing_it_wrong( |
2925 |
"add_theme_support( 'title-tag' )", |
|
2926 |
sprintf( |
|
16 | 2927 |
/* translators: 1: title-tag, 2: wp_loaded */ |
9 | 2928 |
__( 'Theme support for %1$s should be registered before the %2$s hook.' ), |
2929 |
'<code>title-tag</code>', |
|
2930 |
'<code>wp_loaded</code>' |
|
2931 |
), |
|
2932 |
'4.1.0' |
|
2933 |
); |
|
5 | 2934 |
|
2935 |
return false; |
|
2936 |
} |
|
0 | 2937 |
} |
2938 |
||
2939 |
$_wp_theme_features[ $feature ] = $args; |
|
2940 |
} |
|
2941 |
||
2942 |
/** |
|
2943 |
* Registers the internal custom header and background routines. |
|
2944 |
* |
|
2945 |
* @since 3.4.0 |
|
2946 |
* @access private |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2947 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2948 |
* @global Custom_Image_Header $custom_image_header |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2949 |
* @global Custom_Background $custom_background |
0 | 2950 |
*/ |
2951 |
function _custom_header_background_just_in_time() { |
|
2952 |
global $custom_image_header, $custom_background; |
|
2953 |
||
2954 |
if ( current_theme_supports( 'custom-header' ) ) { |
|
2955 |
// In case any constants were defined after an add_custom_image_header() call, re-run. |
|
2956 |
add_theme_support( 'custom-header', array( '__jit' => true ) ); |
|
2957 |
||
2958 |
$args = get_theme_support( 'custom-header' ); |
|
9 | 2959 |
if ( $args[0]['wp-head-callback'] ) { |
0 | 2960 |
add_action( 'wp_head', $args[0]['wp-head-callback'] ); |
9 | 2961 |
} |
0 | 2962 |
|
2963 |
if ( is_admin() ) { |
|
16 | 2964 |
require_once ABSPATH . 'wp-admin/includes/class-custom-image-header.php'; |
0 | 2965 |
$custom_image_header = new Custom_Image_Header( $args[0]['admin-head-callback'], $args[0]['admin-preview-callback'] ); |
2966 |
} |
|
2967 |
} |
|
2968 |
||
2969 |
if ( current_theme_supports( 'custom-background' ) ) { |
|
2970 |
// In case any constants were defined after an add_custom_background() call, re-run. |
|
2971 |
add_theme_support( 'custom-background', array( '__jit' => true ) ); |
|
2972 |
||
2973 |
$args = get_theme_support( 'custom-background' ); |
|
2974 |
add_action( 'wp_head', $args[0]['wp-head-callback'] ); |
|
2975 |
||
2976 |
if ( is_admin() ) { |
|
16 | 2977 |
require_once ABSPATH . 'wp-admin/includes/class-custom-background.php'; |
0 | 2978 |
$custom_background = new Custom_Background( $args[0]['admin-head-callback'], $args[0]['admin-preview-callback'] ); |
2979 |
} |
|
2980 |
} |
|
2981 |
} |
|
2982 |
||
2983 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2984 |
* Adds CSS to hide header text for custom logo, based on Customizer setting. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2985 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2986 |
* @since 4.5.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2987 |
* @access private |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2988 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2989 |
function _custom_logo_header_styles() { |
19 | 2990 |
if ( ! current_theme_supports( 'custom-header', 'header-text' ) |
2991 |
&& get_theme_support( 'custom-logo', 'header-text' ) |
|
2992 |
&& ! get_theme_mod( 'header_text', true ) |
|
2993 |
) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2994 |
$classes = (array) get_theme_support( 'custom-logo', 'header-text' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2995 |
$classes = array_map( 'sanitize_html_class', $classes ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2996 |
$classes = '.' . implode( ', .', $classes ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2997 |
|
16 | 2998 |
$type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2999 |
?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3000 |
<!-- Custom Logo: hide header text --> |
16 | 3001 |
<style id="custom-logo-css"<?php echo $type_attr; ?>> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3002 |
<?php echo $classes; ?> { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3003 |
position: absolute; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3004 |
clip: rect(1px, 1px, 1px, 1px); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3005 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3006 |
</style> |
9 | 3007 |
<?php |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3008 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3009 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3010 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3011 |
/** |
16 | 3012 |
* Gets the theme support arguments passed when registering that support. |
3013 |
* |
|
3014 |
* Example usage: |
|
3015 |
* |
|
3016 |
* get_theme_support( 'custom-logo' ); |
|
3017 |
* get_theme_support( 'custom-header', 'width' ); |
|
0 | 3018 |
* |
5 | 3019 |
* @since 3.1.0 |
16 | 3020 |
* @since 5.3.0 Formalized the existing and already documented `...$args` parameter |
3021 |
* by adding it to the function signature. |
|
5 | 3022 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3023 |
* @global array $_wp_theme_features |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3024 |
* |
16 | 3025 |
* @param string $feature The feature to check. See add_theme_support() for the list |
3026 |
* of possible values. |
|
3027 |
* @param mixed ...$args Optional extra arguments to be checked against certain features. |
|
5 | 3028 |
* @return mixed The array of extra arguments or the value for the registered feature. |
0 | 3029 |
*/ |
16 | 3030 |
function get_theme_support( $feature, ...$args ) { |
0 | 3031 |
global $_wp_theme_features; |
19 | 3032 |
|
9 | 3033 |
if ( ! isset( $_wp_theme_features[ $feature ] ) ) { |
0 | 3034 |
return false; |
9 | 3035 |
} |
3036 |
||
16 | 3037 |
if ( ! $args ) { |
0 | 3038 |
return $_wp_theme_features[ $feature ]; |
9 | 3039 |
} |
0 | 3040 |
|
3041 |
switch ( $feature ) { |
|
9 | 3042 |
case 'custom-logo': |
3043 |
case 'custom-header': |
|
3044 |
case 'custom-background': |
|
3045 |
if ( isset( $_wp_theme_features[ $feature ][0][ $args[0] ] ) ) { |
|
0 | 3046 |
return $_wp_theme_features[ $feature ][0][ $args[0] ]; |
9 | 3047 |
} |
0 | 3048 |
return false; |
5 | 3049 |
|
9 | 3050 |
default: |
0 | 3051 |
return $_wp_theme_features[ $feature ]; |
3052 |
} |
|
3053 |
} |
|
3054 |
||
3055 |
/** |
|
3056 |
* Allows a theme to de-register its support of a certain feature |
|
3057 |
* |
|
3058 |
* Should be called in the theme's functions.php file. Generally would |
|
3059 |
* be used for child themes to override support from the parent theme. |
|
3060 |
* |
|
3061 |
* @since 3.0.0 |
|
16 | 3062 |
* |
0 | 3063 |
* @see add_theme_support() |
16 | 3064 |
* |
3065 |
* @param string $feature The feature being removed. See add_theme_support() for the list |
|
3066 |
* of possible values. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3067 |
* @return bool|void Whether feature was removed. |
0 | 3068 |
*/ |
3069 |
function remove_theme_support( $feature ) { |
|
16 | 3070 |
// Do not remove internal registrations that are not used directly by themes. |
3071 |
if ( in_array( $feature, array( 'editor-style', 'widgets', 'menus' ), true ) ) { |
|
0 | 3072 |
return false; |
9 | 3073 |
} |
0 | 3074 |
|
3075 |
return _remove_theme_support( $feature ); |
|
3076 |
} |
|
3077 |
||
3078 |
/** |
|
16 | 3079 |
* Do not use. Removes theme support internally without knowledge of those not used |
3080 |
* by themes directly. |
|
0 | 3081 |
* |
3082 |
* @access private |
|
3083 |
* @since 3.1.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3084 |
* @global array $_wp_theme_features |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3085 |
* @global Custom_Image_Header $custom_image_header |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3086 |
* @global Custom_Background $custom_background |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3087 |
* |
16 | 3088 |
* @param string $feature The feature being removed. See add_theme_support() for the list |
3089 |
* of possible values. |
|
3090 |
* @return bool True if support was removed, false if the feature was not registered. |
|
0 | 3091 |
*/ |
3092 |
function _remove_theme_support( $feature ) { |
|
3093 |
global $_wp_theme_features; |
|
3094 |
||
3095 |
switch ( $feature ) { |
|
9 | 3096 |
case 'custom-header-uploads': |
3097 |
if ( ! isset( $_wp_theme_features['custom-header'] ) ) { |
|
0 | 3098 |
return false; |
9 | 3099 |
} |
0 | 3100 |
add_theme_support( 'custom-header', array( 'uploads' => false ) ); |
3101 |
return; // Do not continue - custom-header-uploads no longer exists. |
|
3102 |
} |
|
3103 |
||
9 | 3104 |
if ( ! isset( $_wp_theme_features[ $feature ] ) ) { |
0 | 3105 |
return false; |
9 | 3106 |
} |
0 | 3107 |
|
3108 |
switch ( $feature ) { |
|
9 | 3109 |
case 'custom-header': |
3110 |
if ( ! did_action( 'wp_loaded' ) ) { |
|
0 | 3111 |
break; |
9 | 3112 |
} |
0 | 3113 |
$support = get_theme_support( 'custom-header' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3114 |
if ( isset( $support[0]['wp-head-callback'] ) ) { |
0 | 3115 |
remove_action( 'wp_head', $support[0]['wp-head-callback'] ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3116 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3117 |
if ( isset( $GLOBALS['custom_image_header'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3118 |
remove_action( 'admin_menu', array( $GLOBALS['custom_image_header'], 'init' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3119 |
unset( $GLOBALS['custom_image_header'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3120 |
} |
0 | 3121 |
break; |
3122 |
||
9 | 3123 |
case 'custom-background': |
3124 |
if ( ! did_action( 'wp_loaded' ) ) { |
|
0 | 3125 |
break; |
9 | 3126 |
} |
0 | 3127 |
$support = get_theme_support( 'custom-background' ); |
9 | 3128 |
if ( isset( $support[0]['wp-head-callback'] ) ) { |
3129 |
remove_action( 'wp_head', $support[0]['wp-head-callback'] ); |
|
3130 |
} |
|
0 | 3131 |
remove_action( 'admin_menu', array( $GLOBALS['custom_background'], 'init' ) ); |
3132 |
unset( $GLOBALS['custom_background'] ); |
|
3133 |
break; |
|
3134 |
} |
|
3135 |
||
3136 |
unset( $_wp_theme_features[ $feature ] ); |
|
16 | 3137 |
|
0 | 3138 |
return true; |
3139 |
} |
|
3140 |
||
3141 |
/** |
|
9 | 3142 |
* Checks a theme's support for a given feature. |
0 | 3143 |
* |
16 | 3144 |
* Example usage: |
3145 |
* |
|
3146 |
* current_theme_supports( 'custom-logo' ); |
|
3147 |
* current_theme_supports( 'html5', 'comment-form' ); |
|
3148 |
* |
|
0 | 3149 |
* @since 2.9.0 |
16 | 3150 |
* @since 5.3.0 Formalized the existing and already documented `...$args` parameter |
3151 |
* by adding it to the function signature. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3152 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3153 |
* @global array $_wp_theme_features |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3154 |
* |
16 | 3155 |
* @param string $feature The feature being checked. See add_theme_support() for the list |
3156 |
* of possible values. |
|
3157 |
* @param mixed ...$args Optional extra arguments to be checked against certain features. |
|
19 | 3158 |
* @return bool True if the active theme supports the feature, false otherwise. |
0 | 3159 |
*/ |
16 | 3160 |
function current_theme_supports( $feature, ...$args ) { |
0 | 3161 |
global $_wp_theme_features; |
3162 |
||
16 | 3163 |
if ( 'custom-header-uploads' === $feature ) { |
0 | 3164 |
return current_theme_supports( 'custom-header', 'uploads' ); |
9 | 3165 |
} |
3166 |
||
3167 |
if ( ! isset( $_wp_theme_features[ $feature ] ) ) { |
|
0 | 3168 |
return false; |
9 | 3169 |
} |
0 | 3170 |
|
19 | 3171 |
// If no args passed then no extra checks need to be performed. |
16 | 3172 |
if ( ! $args ) { |
19 | 3173 |
/** This filter is documented in wp-includes/theme.php */ |
3174 |
return apply_filters( "current_theme_supports-{$feature}", true, $args, $_wp_theme_features[ $feature ] ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
9 | 3175 |
} |
0 | 3176 |
|
3177 |
switch ( $feature ) { |
|
3178 |
case 'post-thumbnails': |
|
16 | 3179 |
/* |
3180 |
* post-thumbnails can be registered for only certain content/post types |
|
3181 |
* by passing an array of types to add_theme_support(). |
|
3182 |
* If no array was passed, then any type is accepted. |
|
3183 |
*/ |
|
3184 |
if ( true === $_wp_theme_features[ $feature ] ) { // Registered for all types. |
|
0 | 3185 |
return true; |
9 | 3186 |
} |
0 | 3187 |
$content_type = $args[0]; |
16 | 3188 |
return in_array( $content_type, $_wp_theme_features[ $feature ][0], true ); |
0 | 3189 |
|
3190 |
case 'html5': |
|
3191 |
case 'post-formats': |
|
16 | 3192 |
/* |
3193 |
* Specific post formats can be registered by passing an array of types |
|
3194 |
* to add_theme_support(). |
|
3195 |
* |
|
3196 |
* Specific areas of HTML5 support *must* be passed via an array to add_theme_support(). |
|
3197 |
*/ |
|
0 | 3198 |
$type = $args[0]; |
16 | 3199 |
return in_array( $type, $_wp_theme_features[ $feature ][0], true ); |
0 | 3200 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3201 |
case 'custom-logo': |
0 | 3202 |
case 'custom-header': |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3203 |
case 'custom-background': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3204 |
// Specific capabilities can be registered by passing an array to add_theme_support(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3205 |
return ( isset( $_wp_theme_features[ $feature ][0][ $args[0] ] ) && $_wp_theme_features[ $feature ][0][ $args[0] ] ); |
0 | 3206 |
} |
3207 |
||
5 | 3208 |
/** |
19 | 3209 |
* Filters whether the active theme supports a specific feature. |
5 | 3210 |
* |
16 | 3211 |
* The dynamic portion of the hook name, `$feature`, refers to the specific |
3212 |
* theme feature. See add_theme_support() for the list of possible values. |
|
5 | 3213 |
* |
3214 |
* @since 3.4.0 |
|
3215 |
* |
|
19 | 3216 |
* @param bool $supports Whether the active theme supports the given feature. Default true. |
16 | 3217 |
* @param array $args Array of arguments for the feature. |
3218 |
* @param string $feature The theme feature. |
|
5 | 3219 |
*/ |
16 | 3220 |
return apply_filters( "current_theme_supports-{$feature}", true, $args, $_wp_theme_features[ $feature ] ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
0 | 3221 |
} |
3222 |
||
3223 |
/** |
|
3224 |
* Checks a theme's support for a given feature before loading the functions which implement it. |
|
3225 |
* |
|
3226 |
* @since 2.9.0 |
|
5 | 3227 |
* |
16 | 3228 |
* @param string $feature The feature being checked. See add_theme_support() for the list |
3229 |
* of possible values. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3230 |
* @param string $file Path to the file. |
19 | 3231 |
* @return bool True if the active theme supports the supplied feature, false otherwise. |
0 | 3232 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3233 |
function require_if_theme_supports( $feature, $file ) { |
5 | 3234 |
if ( current_theme_supports( $feature ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3235 |
require $file; |
5 | 3236 |
return true; |
3237 |
} |
|
3238 |
return false; |
|
0 | 3239 |
} |
3240 |
||
3241 |
/** |
|
16 | 3242 |
* Registers a theme feature for use in add_theme_support(). |
3243 |
* |
|
19 | 3244 |
* This does not indicate that the active theme supports the feature, it only describes |
16 | 3245 |
* the feature's supported options. |
3246 |
* |
|
3247 |
* @since 5.5.0 |
|
3248 |
* |
|
3249 |
* @see add_theme_support() |
|
3250 |
* |
|
3251 |
* @global array $_wp_registered_theme_features |
|
3252 |
* |
|
3253 |
* @param string $feature The name uniquely identifying the feature. See add_theme_support() |
|
3254 |
* for the list of possible values. |
|
3255 |
* @param array $args { |
|
3256 |
* Data used to describe the theme. |
|
3257 |
* |
|
3258 |
* @type string $type The type of data associated with this feature. |
|
3259 |
* Valid values are 'string', 'boolean', 'integer', |
|
3260 |
* 'number', 'array', and 'object'. Defaults to 'boolean'. |
|
19 | 3261 |
* @type bool $variadic Does this feature utilize the variadic support |
16 | 3262 |
* of add_theme_support(), or are all arguments specified |
3263 |
* as the second parameter. Must be used with the "array" type. |
|
3264 |
* @type string $description A short description of the feature. Included in |
|
3265 |
* the Themes REST API schema. Intended for developers. |
|
3266 |
* @type bool|array $show_in_rest { |
|
3267 |
* Whether this feature should be included in the Themes REST API endpoint. |
|
3268 |
* Defaults to not being included. When registering an 'array' or 'object' type, |
|
3269 |
* this argument must be an array with the 'schema' key. |
|
3270 |
* |
|
3271 |
* @type array $schema Specifies the JSON Schema definition describing |
|
3272 |
* the feature. If any objects in the schema do not include |
|
3273 |
* the 'additionalProperties' keyword, it is set to false. |
|
3274 |
* @type string $name An alternate name to be used as the property name |
|
3275 |
* in the REST API. |
|
3276 |
* @type callable $prepare_callback A function used to format the theme support in the REST API. |
|
3277 |
* Receives the raw theme support value. |
|
3278 |
* } |
|
3279 |
* } |
|
3280 |
* @return true|WP_Error True if the theme feature was successfully registered, a WP_Error object if not. |
|
3281 |
*/ |
|
3282 |
function register_theme_feature( $feature, $args = array() ) { |
|
3283 |
global $_wp_registered_theme_features; |
|
3284 |
||
3285 |
if ( ! is_array( $_wp_registered_theme_features ) ) { |
|
3286 |
$_wp_registered_theme_features = array(); |
|
3287 |
} |
|
3288 |
||
3289 |
$defaults = array( |
|
3290 |
'type' => 'boolean', |
|
3291 |
'variadic' => false, |
|
3292 |
'description' => '', |
|
3293 |
'show_in_rest' => false, |
|
3294 |
); |
|
3295 |
||
3296 |
$args = wp_parse_args( $args, $defaults ); |
|
3297 |
||
3298 |
if ( true === $args['show_in_rest'] ) { |
|
3299 |
$args['show_in_rest'] = array(); |
|
3300 |
} |
|
3301 |
||
3302 |
if ( is_array( $args['show_in_rest'] ) ) { |
|
3303 |
$args['show_in_rest'] = wp_parse_args( |
|
3304 |
$args['show_in_rest'], |
|
3305 |
array( |
|
3306 |
'schema' => array(), |
|
3307 |
'name' => $feature, |
|
3308 |
'prepare_callback' => null, |
|
3309 |
) |
|
3310 |
); |
|
3311 |
} |
|
3312 |
||
3313 |
if ( ! in_array( $args['type'], array( 'string', 'boolean', 'integer', 'number', 'array', 'object' ), true ) ) { |
|
3314 |
return new WP_Error( |
|
3315 |
'invalid_type', |
|
3316 |
__( 'The feature "type" is not valid JSON Schema type.' ) |
|
3317 |
); |
|
3318 |
} |
|
3319 |
||
3320 |
if ( true === $args['variadic'] && 'array' !== $args['type'] ) { |
|
3321 |
return new WP_Error( |
|
3322 |
'variadic_must_be_array', |
|
3323 |
__( 'When registering a "variadic" theme feature, the "type" must be an "array".' ) |
|
3324 |
); |
|
3325 |
} |
|
3326 |
||
3327 |
if ( false !== $args['show_in_rest'] && in_array( $args['type'], array( 'array', 'object' ), true ) ) { |
|
3328 |
if ( ! is_array( $args['show_in_rest'] ) || empty( $args['show_in_rest']['schema'] ) ) { |
|
3329 |
return new WP_Error( |
|
3330 |
'missing_schema', |
|
3331 |
__( 'When registering an "array" or "object" feature to show in the REST API, the feature\'s schema must also be defined.' ) |
|
3332 |
); |
|
3333 |
} |
|
3334 |
||
3335 |
if ( 'array' === $args['type'] && ! isset( $args['show_in_rest']['schema']['items'] ) ) { |
|
3336 |
return new WP_Error( |
|
3337 |
'missing_schema_items', |
|
3338 |
__( 'When registering an "array" feature, the feature\'s schema must include the "items" keyword.' ) |
|
3339 |
); |
|
3340 |
} |
|
3341 |
||
3342 |
if ( 'object' === $args['type'] && ! isset( $args['show_in_rest']['schema']['properties'] ) ) { |
|
3343 |
return new WP_Error( |
|
3344 |
'missing_schema_properties', |
|
3345 |
__( 'When registering an "object" feature, the feature\'s schema must include the "properties" keyword.' ) |
|
3346 |
); |
|
3347 |
} |
|
3348 |
} |
|
3349 |
||
3350 |
if ( is_array( $args['show_in_rest'] ) ) { |
|
19 | 3351 |
if ( isset( $args['show_in_rest']['prepare_callback'] ) |
3352 |
&& ! is_callable( $args['show_in_rest']['prepare_callback'] ) |
|
3353 |
) { |
|
16 | 3354 |
return new WP_Error( |
3355 |
'invalid_rest_prepare_callback', |
|
3356 |
sprintf( |
|
3357 |
/* translators: %s: prepare_callback */ |
|
3358 |
__( 'The "%s" must be a callable function.' ), |
|
3359 |
'prepare_callback' |
|
3360 |
) |
|
3361 |
); |
|
3362 |
} |
|
3363 |
||
3364 |
$args['show_in_rest']['schema'] = wp_parse_args( |
|
3365 |
$args['show_in_rest']['schema'], |
|
3366 |
array( |
|
3367 |
'description' => $args['description'], |
|
3368 |
'type' => $args['type'], |
|
3369 |
'default' => false, |
|
3370 |
) |
|
3371 |
); |
|
3372 |
||
3373 |
if ( is_bool( $args['show_in_rest']['schema']['default'] ) |
|
3374 |
&& ! in_array( 'boolean', (array) $args['show_in_rest']['schema']['type'], true ) |
|
3375 |
) { |
|
3376 |
// Automatically include the "boolean" type when the default value is a boolean. |
|
3377 |
$args['show_in_rest']['schema']['type'] = (array) $args['show_in_rest']['schema']['type']; |
|
3378 |
array_unshift( $args['show_in_rest']['schema']['type'], 'boolean' ); |
|
3379 |
} |
|
3380 |
||
3381 |
$args['show_in_rest']['schema'] = rest_default_additional_properties_to_false( $args['show_in_rest']['schema'] ); |
|
3382 |
} |
|
3383 |
||
3384 |
$_wp_registered_theme_features[ $feature ] = $args; |
|
3385 |
||
3386 |
return true; |
|
3387 |
} |
|
3388 |
||
3389 |
/** |
|
3390 |
* Gets the list of registered theme features. |
|
3391 |
* |
|
3392 |
* @since 5.5.0 |
|
3393 |
* |
|
3394 |
* @global array $_wp_registered_theme_features |
|
3395 |
* |
|
3396 |
* @return array[] List of theme features, keyed by their name. |
|
3397 |
*/ |
|
3398 |
function get_registered_theme_features() { |
|
3399 |
global $_wp_registered_theme_features; |
|
3400 |
||
3401 |
if ( ! is_array( $_wp_registered_theme_features ) ) { |
|
3402 |
return array(); |
|
3403 |
} |
|
3404 |
||
3405 |
return $_wp_registered_theme_features; |
|
3406 |
} |
|
3407 |
||
3408 |
/** |
|
3409 |
* Gets the registration config for a theme feature. |
|
3410 |
* |
|
3411 |
* @since 5.5.0 |
|
3412 |
* |
|
3413 |
* @global array $_wp_registered_theme_features |
|
3414 |
* |
|
3415 |
* @param string $feature The feature name. See add_theme_support() for the list |
|
3416 |
* of possible values. |
|
3417 |
* @return array|null The registration args, or null if the feature was not registered. |
|
3418 |
*/ |
|
3419 |
function get_registered_theme_feature( $feature ) { |
|
3420 |
global $_wp_registered_theme_features; |
|
3421 |
||
3422 |
if ( ! is_array( $_wp_registered_theme_features ) ) { |
|
3423 |
return null; |
|
3424 |
} |
|
3425 |
||
3426 |
return isset( $_wp_registered_theme_features[ $feature ] ) ? $_wp_registered_theme_features[ $feature ] : null; |
|
3427 |
} |
|
3428 |
||
3429 |
/** |
|
0 | 3430 |
* Checks an attachment being deleted to see if it's a header or background image. |
3431 |
* |
|
3432 |
* If true it removes the theme modification which would be pointing at the deleted |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3433 |
* attachment. |
0 | 3434 |
* |
3435 |
* @access private |
|
3436 |
* @since 3.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3437 |
* @since 4.3.0 Also removes `header_image_data`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3438 |
* @since 4.5.0 Also removes custom logo theme mods. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3439 |
* @since 6.6.0 Also removes `site_logo` option set by the site logo block. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3440 |
* |
16 | 3441 |
* @param int $id The attachment ID. |
0 | 3442 |
*/ |
3443 |
function _delete_attachment_theme_mod( $id ) { |
|
3444 |
$attachment_image = wp_get_attachment_url( $id ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3445 |
$header_image = get_header_image(); |
0 | 3446 |
$background_image = get_background_image(); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3447 |
$custom_logo_id = (int) get_theme_mod( 'custom_logo' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3448 |
$site_logo_id = (int) get_option( 'site_logo' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3449 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3450 |
if ( $custom_logo_id && $custom_logo_id === $id ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3451 |
remove_theme_mod( 'custom_logo' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3452 |
remove_theme_mod( 'header_text' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3453 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3454 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3455 |
if ( $site_logo_id && $site_logo_id === $id ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3456 |
delete_option( 'site_logo' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3457 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3458 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3459 |
if ( $header_image && $header_image === $attachment_image ) { |
0 | 3460 |
remove_theme_mod( 'header_image' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3461 |
remove_theme_mod( 'header_image_data' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3462 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3463 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3464 |
if ( $background_image && $background_image === $attachment_image ) { |
0 | 3465 |
remove_theme_mod( 'background_image' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3466 |
} |
0 | 3467 |
} |
3468 |
||
3469 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3470 |
* Checks if a theme has been changed and runs 'after_switch_theme' hook on the next WP load. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3471 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3472 |
* See {@see 'after_switch_theme'}. |
0 | 3473 |
* |
3474 |
* @since 3.3.0 |
|
3475 |
*/ |
|
3476 |
function check_theme_switched() { |
|
16 | 3477 |
$stylesheet = get_option( 'theme_switched' ); |
19 | 3478 |
|
16 | 3479 |
if ( $stylesheet ) { |
0 | 3480 |
$old_theme = wp_get_theme( $stylesheet ); |
3481 |
||
16 | 3482 |
// Prevent widget & menu mapping from running since Customizer already called it up front. |
5 | 3483 |
if ( get_option( 'theme_switched_via_customizer' ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3484 |
remove_action( 'after_switch_theme', '_wp_menus_changed' ); |
5 | 3485 |
remove_action( 'after_switch_theme', '_wp_sidebars_changed' ); |
3486 |
update_option( 'theme_switched_via_customizer', false ); |
|
3487 |
} |
|
3488 |
||
3489 |
if ( $old_theme->exists() ) { |
|
3490 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3491 |
* Fires on the next WP load after the theme has been switched. |
5 | 3492 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3493 |
* The parameters differ according to whether the old theme exists or not. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3494 |
* If the old theme is missing, the old name will instead be the slug |
5 | 3495 |
* of the old theme. |
3496 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3497 |
* See {@see 'switch_theme'}. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3498 |
* |
5 | 3499 |
* @since 3.3.0 |
3500 |
* |
|
3501 |
* @param string $old_name Old theme name. |
|
3502 |
* @param WP_Theme $old_theme WP_Theme instance of the old theme. |
|
3503 |
*/ |
|
3504 |
do_action( 'after_switch_theme', $old_theme->get( 'Name' ), $old_theme ); |
|
3505 |
} else { |
|
3506 |
/** This action is documented in wp-includes/theme.php */ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3507 |
do_action( 'after_switch_theme', $stylesheet, $old_theme ); |
5 | 3508 |
} |
19 | 3509 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3510 |
flush_rewrite_rules(); |
0 | 3511 |
|
3512 |
update_option( 'theme_switched', false ); |
|
3513 |
} |
|
3514 |
} |
|
3515 |
||
3516 |
/** |
|
3517 |
* Includes and instantiates the WP_Customize_Manager class. |
|
3518 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3519 |
* Loads the Customizer at plugins_loaded when accessing the customize.php admin |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3520 |
* page or when any request includes a wp_customize=on param or a customize_changeset |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3521 |
* param (a UUID). This param is a signal for whether to bootstrap the Customizer when |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3522 |
* WordPress is loading, especially in the Customizer preview |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3523 |
* or when making Customizer Ajax requests for widgets or menus. |
0 | 3524 |
* |
3525 |
* @since 3.4.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3526 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3527 |
* @global WP_Customize_Manager $wp_customize |
0 | 3528 |
*/ |
3529 |
function _wp_customize_include() { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3530 |
|
16 | 3531 |
$is_customize_admin_page = ( is_admin() && 'customize.php' === basename( $_SERVER['PHP_SELF'] ) ); |
9 | 3532 |
$should_include = ( |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3533 |
$is_customize_admin_page |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3534 |
|| |
16 | 3535 |
( isset( $_REQUEST['wp_customize'] ) && 'on' === $_REQUEST['wp_customize'] ) |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3536 |
|| |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3537 |
( ! empty( $_GET['customize_changeset_uuid'] ) || ! empty( $_POST['customize_changeset_uuid'] ) ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3538 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3539 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3540 |
if ( ! $should_include ) { |
0 | 3541 |
return; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3542 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3543 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3544 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3545 |
* Note that wp_unslash() is not being used on the input vars because it is |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3546 |
* called before wp_magic_quotes() gets called. Besides this fact, none of |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3547 |
* the values should contain any characters needing slashes anyway. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3548 |
*/ |
19 | 3549 |
$keys = array( |
3550 |
'changeset_uuid', |
|
3551 |
'customize_changeset_uuid', |
|
3552 |
'customize_theme', |
|
3553 |
'theme', |
|
3554 |
'customize_messenger_channel', |
|
3555 |
'customize_autosaved', |
|
3556 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3557 |
$input_vars = array_merge( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3558 |
wp_array_slice_assoc( $_GET, $keys ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3559 |
wp_array_slice_assoc( $_POST, $keys ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3560 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3561 |
|
9 | 3562 |
$theme = null; |
16 | 3563 |
$autosaved = null; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3564 |
$messenger_channel = null; |
16 | 3565 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3566 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3567 |
* Value false indicates UUID should be determined after_setup_theme |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3568 |
* to either re-use existing saved changeset or else generate a new UUID if none exists. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3569 |
*/ |
16 | 3570 |
$changeset_uuid = false; |
3571 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3572 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3573 |
* Set initially to false since defaults to true for back-compat; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3574 |
* can be overridden via the customize_changeset_branching filter. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3575 |
*/ |
16 | 3576 |
$branching = false; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3577 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3578 |
if ( $is_customize_admin_page && isset( $input_vars['changeset_uuid'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3579 |
$changeset_uuid = sanitize_key( $input_vars['changeset_uuid'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3580 |
} elseif ( ! empty( $input_vars['customize_changeset_uuid'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3581 |
$changeset_uuid = sanitize_key( $input_vars['customize_changeset_uuid'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3582 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3583 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3584 |
// Note that theme will be sanitized via WP_Theme. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3585 |
if ( $is_customize_admin_page && isset( $input_vars['theme'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3586 |
$theme = $input_vars['theme']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3587 |
} elseif ( isset( $input_vars['customize_theme'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3588 |
$theme = $input_vars['customize_theme']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3589 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3590 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3591 |
if ( ! empty( $input_vars['customize_autosaved'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3592 |
$autosaved = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3593 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3594 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3595 |
if ( isset( $input_vars['customize_messenger_channel'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3596 |
$messenger_channel = sanitize_key( $input_vars['customize_messenger_channel'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3597 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3598 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3599 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3600 |
* Note that settings must be previewed even outside the customizer preview |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3601 |
* and also in the customizer pane itself. This is to enable loading an existing |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3602 |
* changeset into the customizer. Previewing the settings only has to be prevented |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3603 |
* here in the case of a customize_save action because this will cause WP to think |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3604 |
* there is nothing changed that needs to be saved. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3605 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3606 |
$is_customize_save_action = ( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3607 |
wp_doing_ajax() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3608 |
&& |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3609 |
isset( $_REQUEST['action'] ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3610 |
&& |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3611 |
'customize_save' === wp_unslash( $_REQUEST['action'] ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3612 |
); |
9 | 3613 |
$settings_previewed = ! $is_customize_save_action; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3614 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3615 |
require_once ABSPATH . WPINC . '/class-wp-customize-manager.php'; |
19 | 3616 |
$GLOBALS['wp_customize'] = new WP_Customize_Manager( |
3617 |
compact( |
|
3618 |
'changeset_uuid', |
|
3619 |
'theme', |
|
3620 |
'messenger_channel', |
|
3621 |
'settings_previewed', |
|
3622 |
'autosaved', |
|
3623 |
'branching' |
|
3624 |
) |
|
3625 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3626 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3627 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3628 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3629 |
* Publishes a snapshot's changes. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3630 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3631 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3632 |
* @access private |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3633 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3634 |
* @global WP_Customize_Manager $wp_customize Customizer instance. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3635 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3636 |
* @param string $new_status New post status. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3637 |
* @param string $old_status Old post status. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3638 |
* @param WP_Post $changeset_post Changeset post object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3639 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3640 |
function _wp_customize_publish_changeset( $new_status, $old_status, $changeset_post ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3641 |
global $wp_customize; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3642 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3643 |
$is_publishing_changeset = ( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3644 |
'customize_changeset' === $changeset_post->post_type |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3645 |
&& |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3646 |
'publish' === $new_status |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3647 |
&& |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3648 |
'publish' !== $old_status |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3649 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3650 |
if ( ! $is_publishing_changeset ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3651 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3652 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3653 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3654 |
if ( empty( $wp_customize ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3655 |
require_once ABSPATH . WPINC . '/class-wp-customize-manager.php'; |
9 | 3656 |
$wp_customize = new WP_Customize_Manager( |
3657 |
array( |
|
3658 |
'changeset_uuid' => $changeset_post->post_name, |
|
3659 |
'settings_previewed' => false, |
|
3660 |
) |
|
3661 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3662 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3663 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3664 |
if ( ! did_action( 'customize_register' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3665 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3666 |
* When running from CLI or Cron, the customize_register action will need |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3667 |
* to be triggered in order for core, themes, and plugins to register their |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3668 |
* settings. Normally core will add_action( 'customize_register' ) at |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3669 |
* priority 10 to register the core settings, and if any themes/plugins |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3670 |
* also add_action( 'customize_register' ) at the same priority, they |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3671 |
* will have a $wp_customize with those settings registered since they |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3672 |
* call add_action() afterward, normally. However, when manually doing |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3673 |
* the customize_register action after the setup_theme, then the order |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3674 |
* will be reversed for two actions added at priority 10, resulting in |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3675 |
* the core settings no longer being available as expected to themes/plugins. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3676 |
* So the following manually calls the method that registers the core |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3677 |
* settings up front before doing the action. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3678 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3679 |
remove_action( 'customize_register', array( $wp_customize, 'register_controls' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3680 |
$wp_customize->register_controls(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3681 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3682 |
/** This filter is documented in wp-includes/class-wp-customize-manager.php */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3683 |
do_action( 'customize_register', $wp_customize ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3684 |
} |
9 | 3685 |
$wp_customize->_publish_changeset_values( $changeset_post->ID ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3686 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3687 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3688 |
* Trash the changeset post if revisions are not enabled. Unpublished |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3689 |
* changesets by default get garbage collected due to the auto-draft status. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3690 |
* When a changeset post is published, however, it would no longer get cleaned |
9 | 3691 |
* out. This is a problem when the changeset posts are never displayed anywhere, |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3692 |
* since they would just be endlessly piling up. So here we use the revisions |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3693 |
* feature to indicate whether or not a published changeset should get trashed |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3694 |
* and thus garbage collected. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3695 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3696 |
if ( ! wp_revisions_enabled( $changeset_post ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3697 |
$wp_customize->trash_changeset_post( $changeset_post->ID ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3698 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3699 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3700 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3701 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3702 |
* Filters changeset post data upon insert to ensure post_name is intact. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3703 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3704 |
* This is needed to prevent the post_name from being dropped when the post is |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3705 |
* transitioned into pending status by a contributor. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3706 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3707 |
* @since 4.7.0 |
16 | 3708 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3709 |
* @see wp_insert_post() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3710 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3711 |
* @param array $post_data An array of slashed post data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3712 |
* @param array $supplied_post_data An array of sanitized, but otherwise unmodified post data. |
16 | 3713 |
* @return array Filtered data. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3714 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3715 |
function _wp_customize_changeset_filter_insert_post_data( $post_data, $supplied_post_data ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3716 |
if ( isset( $post_data['post_type'] ) && 'customize_changeset' === $post_data['post_type'] ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3717 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3718 |
// Prevent post_name from being dropped, such as when contributor saves a changeset post as pending. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3719 |
if ( empty( $post_data['post_name'] ) && ! empty( $supplied_post_data['post_name'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3720 |
$post_data['post_name'] = $supplied_post_data['post_name']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3721 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3722 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3723 |
return $post_data; |
0 | 3724 |
} |
3725 |
||
3726 |
/** |
|
3727 |
* Adds settings for the customize-loader script. |
|
3728 |
* |
|
3729 |
* @since 3.4.0 |
|
3730 |
*/ |
|
3731 |
function _wp_customize_loader_settings() { |
|
3732 |
$admin_origin = parse_url( admin_url() ); |
|
3733 |
$home_origin = parse_url( home_url() ); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3734 |
$cross_domain = ( strtolower( $admin_origin['host'] ) !== strtolower( $home_origin['host'] ) ); |
0 | 3735 |
|
3736 |
$browser = array( |
|
3737 |
'mobile' => wp_is_mobile(), |
|
3738 |
'ios' => wp_is_mobile() && preg_match( '/iPad|iPod|iPhone/', $_SERVER['HTTP_USER_AGENT'] ), |
|
3739 |
); |
|
3740 |
||
3741 |
$settings = array( |
|
3742 |
'url' => esc_url( admin_url( 'customize.php' ) ), |
|
3743 |
'isCrossDomain' => $cross_domain, |
|
3744 |
'browser' => $browser, |
|
5 | 3745 |
'l10n' => array( |
3746 |
'saveAlert' => __( 'The changes you made will be lost if you navigate away from this page.' ), |
|
3747 |
'mainIframeTitle' => __( 'Customizer' ), |
|
3748 |
), |
|
0 | 3749 |
); |
3750 |
||
5 | 3751 |
$script = 'var _wpCustomizeLoaderSettings = ' . wp_json_encode( $settings ) . ';'; |
0 | 3752 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3753 |
$wp_scripts = wp_scripts(); |
9 | 3754 |
$data = $wp_scripts->get_data( 'customize-loader', 'data' ); |
3755 |
if ( $data ) { |
|
0 | 3756 |
$script = "$data\n$script"; |
9 | 3757 |
} |
0 | 3758 |
|
3759 |
$wp_scripts->add_data( 'customize-loader', 'data', $script ); |
|
3760 |
} |
|
3761 |
||
3762 |
/** |
|
5 | 3763 |
* Returns a URL to load the Customizer. |
0 | 3764 |
* |
3765 |
* @since 3.4.0 |
|
3766 |
* |
|
19 | 3767 |
* @param string $stylesheet Optional. Theme to customize. Defaults to active theme. |
9 | 3768 |
* The theme's stylesheet will be urlencoded if necessary. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3769 |
* @return string |
0 | 3770 |
*/ |
16 | 3771 |
function wp_customize_url( $stylesheet = '' ) { |
0 | 3772 |
$url = admin_url( 'customize.php' ); |
9 | 3773 |
if ( $stylesheet ) { |
0 | 3774 |
$url .= '?theme=' . urlencode( $stylesheet ); |
9 | 3775 |
} |
0 | 3776 |
return esc_url( $url ); |
3777 |
} |
|
3778 |
||
3779 |
/** |
|
5 | 3780 |
* Prints a script to check whether or not the Customizer is supported, |
0 | 3781 |
* and apply either the no-customize-support or customize-support class |
3782 |
* to the body. |
|
3783 |
* |
|
3784 |
* This function MUST be called inside the body tag. |
|
3785 |
* |
|
3786 |
* Ideally, call this function immediately after the body tag is opened. |
|
3787 |
* This prevents a flash of unstyled content. |
|
3788 |
* |
|
3789 |
* It is also recommended that you add the "no-customize-support" class |
|
3790 |
* to the body tag by default. |
|
3791 |
* |
|
3792 |
* @since 3.4.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3793 |
* @since 4.7.0 Support for IE8 and below is explicitly removed via conditional comments. |
16 | 3794 |
* @since 5.5.0 IE8 and older are no longer supported. |
0 | 3795 |
*/ |
3796 |
function wp_customize_support_script() { |
|
3797 |
$admin_origin = parse_url( admin_url() ); |
|
3798 |
$home_origin = parse_url( home_url() ); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3799 |
$cross_domain = ( strtolower( $admin_origin['host'] ) !== strtolower( $home_origin['host'] ) ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3800 |
ob_start(); |
0 | 3801 |
?> |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3802 |
<script> |
16 | 3803 |
(function() { |
3804 |
var request, b = document.body, c = 'className', cs = 'customize-support', rcs = new RegExp('(^|\\s+)(no-)?'+cs+'(\\s+|$)'); |
|
3805 |
||
3806 |
<?php if ( $cross_domain ) : ?> |
|
3807 |
request = (function(){ var xhr = new XMLHttpRequest(); return ('withCredentials' in xhr); })(); |
|
3808 |
<?php else : ?> |
|
3809 |
request = true; |
|
3810 |
<?php endif; ?> |
|
3811 |
||
3812 |
b[c] = b[c].replace( rcs, ' ' ); |
|
3813 |
// The customizer requires postMessage and CORS (if the site is cross domain). |
|
3814 |
b[c] += ( window.postMessage && request ? ' ' : ' no-' ) + cs; |
|
3815 |
}()); |
|
3816 |
</script> |
|
0 | 3817 |
<?php |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3818 |
wp_print_inline_script_tag( wp_remove_surrounding_empty_script_tags( ob_get_clean() ) ); |
5 | 3819 |
} |
3820 |
||
3821 |
/** |
|
3822 |
* Whether the site is being previewed in the Customizer. |
|
3823 |
* |
|
3824 |
* @since 4.0.0 |
|
3825 |
* |
|
3826 |
* @global WP_Customize_Manager $wp_customize Customizer instance. |
|
3827 |
* |
|
3828 |
* @return bool True if the site is being previewed in the Customizer, false otherwise. |
|
3829 |
*/ |
|
3830 |
function is_customize_preview() { |
|
3831 |
global $wp_customize; |
|
3832 |
||
3833 |
return ( $wp_customize instanceof WP_Customize_Manager ) && $wp_customize->is_preview(); |
|
3834 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3835 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3836 |
/** |
19 | 3837 |
* Makes sure that auto-draft posts get their post_date bumped or status changed |
3838 |
* to draft to prevent premature garbage-collection. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3839 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3840 |
* When a changeset is updated but remains an auto-draft, ensure the post_date |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3841 |
* for the auto-draft posts remains the same so that it will be |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3842 |
* garbage-collected at the same time by `wp_delete_auto_drafts()`. Otherwise, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3843 |
* if the changeset is updated to be a draft then update the posts |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3844 |
* to have a far-future post_date so that they will never be garbage collected |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3845 |
* unless the changeset post itself is deleted. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3846 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3847 |
* When a changeset is updated to be a persistent draft or to be scheduled for |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3848 |
* publishing, then transition any dependent auto-drafts to a draft status so |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3849 |
* that they likewise will not be garbage-collected but also so that they can |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3850 |
* be edited in the admin before publishing since there is not yet a post/page |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3851 |
* editing flow in the Customizer. See #39752. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3852 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3853 |
* @link https://core.trac.wordpress.org/ticket/39752 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3854 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3855 |
* @since 4.8.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3856 |
* @access private |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3857 |
* @see wp_delete_auto_drafts() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3858 |
* |
16 | 3859 |
* @global wpdb $wpdb WordPress database abstraction object. |
3860 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3861 |
* @param string $new_status Transition to this post status. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3862 |
* @param string $old_status Previous post status. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3863 |
* @param \WP_Post $post Post data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3864 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3865 |
function _wp_keep_alive_customize_changeset_dependent_auto_drafts( $new_status, $old_status, $post ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3866 |
global $wpdb; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3867 |
unset( $old_status ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3868 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3869 |
// Short-circuit if not a changeset or if the changeset was published. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3870 |
if ( 'customize_changeset' !== $post->post_type || 'publish' === $new_status ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3871 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3872 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3873 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3874 |
$data = json_decode( $post->post_content, true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3875 |
if ( empty( $data['nav_menus_created_posts']['value'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3876 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3877 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3878 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3879 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3880 |
* Actually, in lieu of keeping alive, trash any customization drafts here if the changeset itself is |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3881 |
* getting trashed. This is needed because when a changeset transitions to a draft, then any of the |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3882 |
* dependent auto-draft post/page stubs will also get transitioned to customization drafts which |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3883 |
* are then visible in the WP Admin. We cannot wait for the deletion of the changeset in which |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3884 |
* _wp_delete_customize_changeset_dependent_auto_drafts() will be called, since they need to be |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3885 |
* trashed to remove from visibility immediately. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3886 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3887 |
if ( 'trash' === $new_status ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3888 |
foreach ( $data['nav_menus_created_posts']['value'] as $post_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3889 |
if ( ! empty( $post_id ) && 'draft' === get_post_status( $post_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3890 |
wp_trash_post( $post_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3891 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3892 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3893 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3894 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3895 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3896 |
$post_args = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3897 |
if ( 'auto-draft' === $new_status ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3898 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3899 |
* Keep the post date for the post matching the changeset |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3900 |
* so that it will not be garbage-collected before the changeset. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3901 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3902 |
$post_args['post_date'] = $post->post_date; // Note wp_delete_auto_drafts() only looks at this date. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3903 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3904 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3905 |
* Since the changeset no longer has an auto-draft (and it is not published) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3906 |
* it is now a persistent changeset, a long-lived draft, and so any |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3907 |
* associated auto-draft posts should likewise transition into having a draft |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3908 |
* status. These drafts will be treated differently than regular drafts in |
9 | 3909 |
* that they will be tied to the given changeset. The publish meta box is |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3910 |
* replaced with a notice about how the post is part of a set of customized changes |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3911 |
* which will be published when the changeset is published. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3912 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3913 |
$post_args['post_status'] = 'draft'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3914 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3915 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3916 |
foreach ( $data['nav_menus_created_posts']['value'] as $post_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3917 |
if ( empty( $post_id ) || 'auto-draft' !== get_post_status( $post_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3918 |
continue; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3919 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3920 |
$wpdb->update( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3921 |
$wpdb->posts, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3922 |
$post_args, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3923 |
array( 'ID' => $post_id ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3924 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3925 |
clean_post_cache( $post_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3926 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3927 |
} |
16 | 3928 |
|
3929 |
/** |
|
3930 |
* Creates the initial theme features when the 'setup_theme' action is fired. |
|
3931 |
* |
|
3932 |
* See {@see 'setup_theme'}. |
|
3933 |
* |
|
3934 |
* @since 5.5.0 |
|
19 | 3935 |
* @since 6.0.1 The `block-templates` feature was added. |
16 | 3936 |
*/ |
3937 |
function create_initial_theme_features() { |
|
3938 |
register_theme_feature( |
|
3939 |
'align-wide', |
|
3940 |
array( |
|
3941 |
'description' => __( 'Whether theme opts in to wide alignment CSS class.' ), |
|
3942 |
'show_in_rest' => true, |
|
3943 |
) |
|
3944 |
); |
|
3945 |
register_theme_feature( |
|
3946 |
'automatic-feed-links', |
|
3947 |
array( |
|
3948 |
'description' => __( 'Whether posts and comments RSS feed links are added to head.' ), |
|
3949 |
'show_in_rest' => true, |
|
3950 |
) |
|
3951 |
); |
|
3952 |
register_theme_feature( |
|
19 | 3953 |
'block-templates', |
3954 |
array( |
|
3955 |
'description' => __( 'Whether a theme uses block-based templates.' ), |
|
3956 |
'show_in_rest' => true, |
|
3957 |
) |
|
3958 |
); |
|
3959 |
register_theme_feature( |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3960 |
'block-template-parts', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3961 |
array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3962 |
'description' => __( 'Whether a theme uses block-based template parts.' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3963 |
'show_in_rest' => true, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3964 |
) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3965 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3966 |
register_theme_feature( |
16 | 3967 |
'custom-background', |
3968 |
array( |
|
3969 |
'description' => __( 'Custom background if defined by the theme.' ), |
|
3970 |
'type' => 'object', |
|
3971 |
'show_in_rest' => array( |
|
3972 |
'schema' => array( |
|
3973 |
'properties' => array( |
|
3974 |
'default-image' => array( |
|
3975 |
'type' => 'string', |
|
3976 |
'format' => 'uri', |
|
3977 |
), |
|
3978 |
'default-preset' => array( |
|
3979 |
'type' => 'string', |
|
3980 |
'enum' => array( |
|
3981 |
'default', |
|
3982 |
'fill', |
|
3983 |
'fit', |
|
3984 |
'repeat', |
|
3985 |
'custom', |
|
3986 |
), |
|
3987 |
), |
|
3988 |
'default-position-x' => array( |
|
3989 |
'type' => 'string', |
|
3990 |
'enum' => array( |
|
3991 |
'left', |
|
3992 |
'center', |
|
3993 |
'right', |
|
3994 |
), |
|
3995 |
), |
|
3996 |
'default-position-y' => array( |
|
3997 |
'type' => 'string', |
|
3998 |
'enum' => array( |
|
3999 |
'left', |
|
4000 |
'center', |
|
4001 |
'right', |
|
4002 |
), |
|
4003 |
), |
|
4004 |
'default-size' => array( |
|
4005 |
'type' => 'string', |
|
4006 |
'enum' => array( |
|
4007 |
'auto', |
|
4008 |
'contain', |
|
4009 |
'cover', |
|
4010 |
), |
|
4011 |
), |
|
4012 |
'default-repeat' => array( |
|
4013 |
'type' => 'string', |
|
4014 |
'enum' => array( |
|
4015 |
'repeat-x', |
|
4016 |
'repeat-y', |
|
4017 |
'repeat', |
|
4018 |
'no-repeat', |
|
4019 |
), |
|
4020 |
), |
|
4021 |
'default-attachment' => array( |
|
4022 |
'type' => 'string', |
|
4023 |
'enum' => array( |
|
4024 |
'scroll', |
|
4025 |
'fixed', |
|
4026 |
), |
|
4027 |
), |
|
4028 |
'default-color' => array( |
|
4029 |
'type' => 'string', |
|
4030 |
), |
|
4031 |
), |
|
4032 |
), |
|
4033 |
), |
|
4034 |
) |
|
4035 |
); |
|
4036 |
register_theme_feature( |
|
4037 |
'custom-header', |
|
4038 |
array( |
|
4039 |
'description' => __( 'Custom header if defined by the theme.' ), |
|
4040 |
'type' => 'object', |
|
4041 |
'show_in_rest' => array( |
|
4042 |
'schema' => array( |
|
4043 |
'properties' => array( |
|
4044 |
'default-image' => array( |
|
4045 |
'type' => 'string', |
|
4046 |
'format' => 'uri', |
|
4047 |
), |
|
4048 |
'random-default' => array( |
|
4049 |
'type' => 'boolean', |
|
4050 |
), |
|
4051 |
'width' => array( |
|
4052 |
'type' => 'integer', |
|
4053 |
), |
|
4054 |
'height' => array( |
|
4055 |
'type' => 'integer', |
|
4056 |
), |
|
4057 |
'flex-height' => array( |
|
4058 |
'type' => 'boolean', |
|
4059 |
), |
|
4060 |
'flex-width' => array( |
|
4061 |
'type' => 'boolean', |
|
4062 |
), |
|
4063 |
'default-text-color' => array( |
|
4064 |
'type' => 'string', |
|
4065 |
), |
|
4066 |
'header-text' => array( |
|
4067 |
'type' => 'boolean', |
|
4068 |
), |
|
4069 |
'uploads' => array( |
|
4070 |
'type' => 'boolean', |
|
4071 |
), |
|
4072 |
'video' => array( |
|
4073 |
'type' => 'boolean', |
|
4074 |
), |
|
4075 |
), |
|
4076 |
), |
|
4077 |
), |
|
4078 |
) |
|
4079 |
); |
|
4080 |
register_theme_feature( |
|
4081 |
'custom-logo', |
|
4082 |
array( |
|
4083 |
'type' => 'object', |
|
4084 |
'description' => __( 'Custom logo if defined by the theme.' ), |
|
4085 |
'show_in_rest' => array( |
|
4086 |
'schema' => array( |
|
4087 |
'properties' => array( |
|
4088 |
'width' => array( |
|
4089 |
'type' => 'integer', |
|
4090 |
), |
|
4091 |
'height' => array( |
|
4092 |
'type' => 'integer', |
|
4093 |
), |
|
4094 |
'flex-width' => array( |
|
4095 |
'type' => 'boolean', |
|
4096 |
), |
|
4097 |
'flex-height' => array( |
|
4098 |
'type' => 'boolean', |
|
4099 |
), |
|
4100 |
'header-text' => array( |
|
4101 |
'type' => 'array', |
|
4102 |
'items' => array( |
|
4103 |
'type' => 'string', |
|
4104 |
), |
|
4105 |
), |
|
4106 |
'unlink-homepage-logo' => array( |
|
4107 |
'type' => 'boolean', |
|
4108 |
), |
|
4109 |
), |
|
4110 |
), |
|
4111 |
), |
|
4112 |
) |
|
4113 |
); |
|
4114 |
register_theme_feature( |
|
4115 |
'customize-selective-refresh-widgets', |
|
4116 |
array( |
|
4117 |
'description' => __( 'Whether the theme enables Selective Refresh for Widgets being managed with the Customizer.' ), |
|
4118 |
'show_in_rest' => true, |
|
4119 |
) |
|
4120 |
); |
|
4121 |
register_theme_feature( |
|
4122 |
'dark-editor-style', |
|
4123 |
array( |
|
4124 |
'description' => __( 'Whether theme opts in to the dark editor style UI.' ), |
|
4125 |
'show_in_rest' => true, |
|
4126 |
) |
|
4127 |
); |
|
4128 |
register_theme_feature( |
|
4129 |
'disable-custom-colors', |
|
4130 |
array( |
|
4131 |
'description' => __( 'Whether the theme disables custom colors.' ), |
|
4132 |
'show_in_rest' => true, |
|
4133 |
) |
|
4134 |
); |
|
4135 |
register_theme_feature( |
|
4136 |
'disable-custom-font-sizes', |
|
4137 |
array( |
|
4138 |
'description' => __( 'Whether the theme disables custom font sizes.' ), |
|
4139 |
'show_in_rest' => true, |
|
4140 |
) |
|
4141 |
); |
|
4142 |
register_theme_feature( |
|
4143 |
'disable-custom-gradients', |
|
4144 |
array( |
|
4145 |
'description' => __( 'Whether the theme disables custom gradients.' ), |
|
4146 |
'show_in_rest' => true, |
|
4147 |
) |
|
4148 |
); |
|
4149 |
register_theme_feature( |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4150 |
'disable-layout-styles', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4151 |
array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4152 |
'description' => __( 'Whether the theme disables generated layout styles.' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4153 |
'show_in_rest' => true, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4154 |
) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4155 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4156 |
register_theme_feature( |
16 | 4157 |
'editor-color-palette', |
4158 |
array( |
|
4159 |
'type' => 'array', |
|
4160 |
'description' => __( 'Custom color palette if defined by the theme.' ), |
|
4161 |
'show_in_rest' => array( |
|
4162 |
'schema' => array( |
|
4163 |
'items' => array( |
|
4164 |
'type' => 'object', |
|
4165 |
'properties' => array( |
|
4166 |
'name' => array( |
|
4167 |
'type' => 'string', |
|
4168 |
), |
|
4169 |
'slug' => array( |
|
4170 |
'type' => 'string', |
|
4171 |
), |
|
4172 |
'color' => array( |
|
4173 |
'type' => 'string', |
|
4174 |
), |
|
4175 |
), |
|
4176 |
), |
|
4177 |
), |
|
4178 |
), |
|
4179 |
) |
|
4180 |
); |
|
4181 |
register_theme_feature( |
|
4182 |
'editor-font-sizes', |
|
4183 |
array( |
|
4184 |
'type' => 'array', |
|
4185 |
'description' => __( 'Custom font sizes if defined by the theme.' ), |
|
4186 |
'show_in_rest' => array( |
|
4187 |
'schema' => array( |
|
4188 |
'items' => array( |
|
4189 |
'type' => 'object', |
|
4190 |
'properties' => array( |
|
4191 |
'name' => array( |
|
4192 |
'type' => 'string', |
|
4193 |
), |
|
4194 |
'size' => array( |
|
4195 |
'type' => 'number', |
|
4196 |
), |
|
4197 |
'slug' => array( |
|
4198 |
'type' => 'string', |
|
4199 |
), |
|
4200 |
), |
|
4201 |
), |
|
4202 |
), |
|
4203 |
), |
|
4204 |
) |
|
4205 |
); |
|
4206 |
register_theme_feature( |
|
4207 |
'editor-gradient-presets', |
|
4208 |
array( |
|
4209 |
'type' => 'array', |
|
4210 |
'description' => __( 'Custom gradient presets if defined by the theme.' ), |
|
4211 |
'show_in_rest' => array( |
|
4212 |
'schema' => array( |
|
4213 |
'items' => array( |
|
4214 |
'type' => 'object', |
|
4215 |
'properties' => array( |
|
4216 |
'name' => array( |
|
4217 |
'type' => 'string', |
|
4218 |
), |
|
4219 |
'gradient' => array( |
|
4220 |
'type' => 'string', |
|
4221 |
), |
|
4222 |
'slug' => array( |
|
4223 |
'type' => 'string', |
|
4224 |
), |
|
4225 |
), |
|
4226 |
), |
|
4227 |
), |
|
4228 |
), |
|
4229 |
) |
|
4230 |
); |
|
4231 |
register_theme_feature( |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4232 |
'editor-spacing-sizes', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4233 |
array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4234 |
'type' => 'array', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4235 |
'description' => __( 'Custom spacing sizes if defined by the theme.' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4236 |
'show_in_rest' => array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4237 |
'schema' => array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4238 |
'items' => array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4239 |
'type' => 'object', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4240 |
'properties' => array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4241 |
'name' => array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4242 |
'type' => 'string', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4243 |
), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4244 |
'size' => array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4245 |
'type' => 'string', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4246 |
), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4247 |
'slug' => array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4248 |
'type' => 'string', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4249 |
), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4250 |
), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4251 |
), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4252 |
), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4253 |
), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4254 |
) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4255 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4256 |
register_theme_feature( |
16 | 4257 |
'editor-styles', |
4258 |
array( |
|
4259 |
'description' => __( 'Whether theme opts in to the editor styles CSS wrapper.' ), |
|
4260 |
'show_in_rest' => true, |
|
4261 |
) |
|
4262 |
); |
|
4263 |
register_theme_feature( |
|
4264 |
'html5', |
|
4265 |
array( |
|
4266 |
'type' => 'array', |
|
4267 |
'description' => __( 'Allows use of HTML5 markup for search forms, comment forms, comment lists, gallery, and caption.' ), |
|
4268 |
'show_in_rest' => array( |
|
4269 |
'schema' => array( |
|
4270 |
'items' => array( |
|
4271 |
'type' => 'string', |
|
4272 |
'enum' => array( |
|
4273 |
'search-form', |
|
4274 |
'comment-form', |
|
4275 |
'comment-list', |
|
4276 |
'gallery', |
|
4277 |
'caption', |
|
4278 |
'script', |
|
4279 |
'style', |
|
4280 |
), |
|
4281 |
), |
|
4282 |
), |
|
4283 |
), |
|
4284 |
) |
|
4285 |
); |
|
4286 |
register_theme_feature( |
|
4287 |
'post-formats', |
|
4288 |
array( |
|
4289 |
'type' => 'array', |
|
4290 |
'description' => __( 'Post formats supported.' ), |
|
4291 |
'show_in_rest' => array( |
|
4292 |
'name' => 'formats', |
|
4293 |
'schema' => array( |
|
4294 |
'items' => array( |
|
4295 |
'type' => 'string', |
|
4296 |
'enum' => get_post_format_slugs(), |
|
4297 |
), |
|
4298 |
'default' => array( 'standard' ), |
|
4299 |
), |
|
4300 |
'prepare_callback' => static function ( $formats ) { |
|
4301 |
$formats = is_array( $formats ) ? array_values( $formats[0] ) : array(); |
|
4302 |
$formats = array_merge( array( 'standard' ), $formats ); |
|
4303 |
||
4304 |
return $formats; |
|
4305 |
}, |
|
4306 |
), |
|
4307 |
) |
|
4308 |
); |
|
4309 |
register_theme_feature( |
|
4310 |
'post-thumbnails', |
|
4311 |
array( |
|
4312 |
'type' => 'array', |
|
4313 |
'description' => __( 'The post types that support thumbnails or true if all post types are supported.' ), |
|
4314 |
'show_in_rest' => array( |
|
4315 |
'type' => array( 'boolean', 'array' ), |
|
4316 |
'schema' => array( |
|
4317 |
'items' => array( |
|
4318 |
'type' => 'string', |
|
4319 |
), |
|
4320 |
), |
|
4321 |
), |
|
4322 |
) |
|
4323 |
); |
|
4324 |
register_theme_feature( |
|
4325 |
'responsive-embeds', |
|
4326 |
array( |
|
4327 |
'description' => __( 'Whether the theme supports responsive embedded content.' ), |
|
4328 |
'show_in_rest' => true, |
|
4329 |
) |
|
4330 |
); |
|
4331 |
register_theme_feature( |
|
4332 |
'title-tag', |
|
4333 |
array( |
|
4334 |
'description' => __( 'Whether the theme can manage the document title tag.' ), |
|
4335 |
'show_in_rest' => true, |
|
4336 |
) |
|
4337 |
); |
|
4338 |
register_theme_feature( |
|
4339 |
'wp-block-styles', |
|
4340 |
array( |
|
4341 |
'description' => __( 'Whether theme opts in to default WordPress block styles for viewing.' ), |
|
4342 |
'show_in_rest' => true, |
|
4343 |
) |
|
4344 |
); |
|
4345 |
} |
|
19 | 4346 |
|
4347 |
/** |
|
4348 |
* Returns whether the active theme is a block-based theme or not. |
|
4349 |
* |
|
4350 |
* @since 5.9.0 |
|
4351 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4352 |
* @return bool Whether the active theme is a block-based theme or not. |
19 | 4353 |
*/ |
4354 |
function wp_is_block_theme() { |
|
4355 |
return wp_get_theme()->is_block_theme(); |
|
4356 |
} |
|
4357 |
||
4358 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4359 |
* Given an element name, returns a class name. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4360 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4361 |
* Alias of WP_Theme_JSON::get_element_class_name. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4362 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4363 |
* @since 6.1.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4364 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4365 |
* @param string $element The name of the element. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4366 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4367 |
* @return string The name of the class. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4368 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4369 |
function wp_theme_get_element_class_name( $element ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4370 |
return WP_Theme_JSON::get_element_class_name( $element ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4371 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4372 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4373 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4374 |
* Adds default theme supports for block themes when the 'after_setup_theme' action fires. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4375 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4376 |
* See {@see 'after_setup_theme'}. |
19 | 4377 |
* |
4378 |
* @since 5.9.0 |
|
4379 |
* @access private |
|
4380 |
*/ |
|
4381 |
function _add_default_theme_supports() { |
|
4382 |
if ( ! wp_is_block_theme() ) { |
|
4383 |
return; |
|
4384 |
} |
|
4385 |
||
4386 |
add_theme_support( 'post-thumbnails' ); |
|
4387 |
add_theme_support( 'responsive-embeds' ); |
|
4388 |
add_theme_support( 'editor-styles' ); |
|
4389 |
/* |
|
4390 |
* Makes block themes support HTML5 by default for the comment block and search form |
|
4391 |
* (which use default template functions) and `[caption]` and `[gallery]` shortcodes. |
|
4392 |
* Other blocks contain their own HTML5 markup. |
|
4393 |
*/ |
|
4394 |
add_theme_support( 'html5', array( 'comment-form', 'comment-list', 'search-form', 'gallery', 'caption', 'style', 'script' ) ); |
|
4395 |
add_theme_support( 'automatic-feed-links' ); |
|
4396 |
||
4397 |
add_filter( 'should_load_separate_core_block_assets', '__return_true' ); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4398 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4399 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4400 |
* Remove the Customizer's Menus panel when block theme is active. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4401 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4402 |
add_filter( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4403 |
'customize_panel_active', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4404 |
static function ( $active, WP_Customize_Panel $panel ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4405 |
if ( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4406 |
'nav_menus' === $panel->id && |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4407 |
! current_theme_supports( 'menus' ) && |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4408 |
! current_theme_supports( 'widgets' ) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4409 |
) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4410 |
$active = false; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4411 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4412 |
return $active; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4413 |
}, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4414 |
10, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4415 |
2 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
4416 |
); |
19 | 4417 |
} |