author | ymh <ymh.work@gmail.com> |
Mon, 14 Oct 2019 17:39:30 +0200 | |
changeset 7 | cf61fcea0001 |
parent 5 | 5e2f62d02dcd |
child 9 | 177826044cd9 |
permissions | -rw-r--r-- |
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 |
* @staticvar array $_themes |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
19 |
* |
0 | 20 |
* @param array $args The search arguments. Optional. |
21 |
* - errors mixed True to return themes with errors, false to return themes without errors, null |
|
22 |
* to return all themes. Defaults to false. |
|
23 |
* - allowed mixed (Multisite) True to return only allowed themes for a site. False to return only |
|
24 |
* disallowed themes for a site. 'site' to return only site-allowed themes. 'network' |
|
25 |
* to return only network-allowed themes. Null to return all themes. Defaults to null. |
|
26 |
* - blog_id int (Multisite) The blog ID used to calculate which themes are allowed. Defaults to 0, |
|
27 |
* synonymous for the current blog. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
28 |
* @return array Array of WP_Theme objects. |
0 | 29 |
*/ |
30 |
function wp_get_themes( $args = array() ) { |
|
31 |
global $wp_theme_directories; |
|
32 |
||
33 |
$defaults = array( 'errors' => false, 'allowed' => null, 'blog_id' => 0 ); |
|
34 |
$args = wp_parse_args( $args, $defaults ); |
|
35 |
||
36 |
$theme_directories = search_theme_directories(); |
|
37 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
38 |
if ( is_array( $wp_theme_directories ) && count( $wp_theme_directories ) > 1 ) { |
0 | 39 |
// Make sure the current theme wins out, in case search_theme_directories() picks the wrong |
40 |
// one in the case of a conflict. (Normally, last registered theme root wins.) |
|
41 |
$current_theme = get_stylesheet(); |
|
42 |
if ( isset( $theme_directories[ $current_theme ] ) ) { |
|
43 |
$root_of_current_theme = get_raw_theme_root( $current_theme ); |
|
44 |
if ( ! in_array( $root_of_current_theme, $wp_theme_directories ) ) |
|
45 |
$root_of_current_theme = WP_CONTENT_DIR . $root_of_current_theme; |
|
46 |
$theme_directories[ $current_theme ]['theme_root'] = $root_of_current_theme; |
|
47 |
} |
|
48 |
} |
|
49 |
||
50 |
if ( empty( $theme_directories ) ) |
|
51 |
return array(); |
|
52 |
||
53 |
if ( is_multisite() && null !== $args['allowed'] ) { |
|
54 |
$allowed = $args['allowed']; |
|
55 |
if ( 'network' === $allowed ) |
|
56 |
$theme_directories = array_intersect_key( $theme_directories, WP_Theme::get_allowed_on_network() ); |
|
57 |
elseif ( 'site' === $allowed ) |
|
58 |
$theme_directories = array_intersect_key( $theme_directories, WP_Theme::get_allowed_on_site( $args['blog_id'] ) ); |
|
59 |
elseif ( $allowed ) |
|
60 |
$theme_directories = array_intersect_key( $theme_directories, WP_Theme::get_allowed( $args['blog_id'] ) ); |
|
61 |
else |
|
62 |
$theme_directories = array_diff_key( $theme_directories, WP_Theme::get_allowed( $args['blog_id'] ) ); |
|
63 |
} |
|
64 |
||
65 |
$themes = array(); |
|
66 |
static $_themes = array(); |
|
67 |
||
68 |
foreach ( $theme_directories as $theme => $theme_root ) { |
|
69 |
if ( isset( $_themes[ $theme_root['theme_root'] . '/' . $theme ] ) ) |
|
70 |
$themes[ $theme ] = $_themes[ $theme_root['theme_root'] . '/' . $theme ]; |
|
71 |
else |
|
72 |
$themes[ $theme ] = $_themes[ $theme_root['theme_root'] . '/' . $theme ] = new WP_Theme( $theme, $theme_root['theme_root'] ); |
|
73 |
} |
|
74 |
||
75 |
if ( null !== $args['errors'] ) { |
|
76 |
foreach ( $themes as $theme => $wp_theme ) { |
|
77 |
if ( $wp_theme->errors() != $args['errors'] ) |
|
78 |
unset( $themes[ $theme ] ); |
|
79 |
} |
|
80 |
} |
|
81 |
||
82 |
return $themes; |
|
83 |
} |
|
84 |
||
85 |
/** |
|
86 |
* Gets a WP_Theme object for a theme. |
|
87 |
* |
|
88 |
* @since 3.4.0 |
|
89 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
90 |
* @global array $wp_theme_directories |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
91 |
* |
0 | 92 |
* @param string $stylesheet Directory name for the theme. Optional. Defaults to current theme. |
93 |
* @param string $theme_root Absolute path of the theme root to look in. Optional. If not specified, get_raw_theme_root() |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
94 |
* is used to calculate the theme root for the $stylesheet provided (or current theme). |
0 | 95 |
* @return WP_Theme Theme object. Be sure to check the object's exists() method if you need to confirm the theme's existence. |
96 |
*/ |
|
97 |
function wp_get_theme( $stylesheet = null, $theme_root = null ) { |
|
98 |
global $wp_theme_directories; |
|
99 |
||
100 |
if ( empty( $stylesheet ) ) |
|
101 |
$stylesheet = get_stylesheet(); |
|
102 |
||
103 |
if ( empty( $theme_root ) ) { |
|
104 |
$theme_root = get_raw_theme_root( $stylesheet ); |
|
105 |
if ( false === $theme_root ) |
|
106 |
$theme_root = WP_CONTENT_DIR . '/themes'; |
|
107 |
elseif ( ! in_array( $theme_root, (array) $wp_theme_directories ) ) |
|
108 |
$theme_root = WP_CONTENT_DIR . $theme_root; |
|
109 |
} |
|
110 |
||
111 |
return new WP_Theme( $stylesheet, $theme_root ); |
|
112 |
} |
|
113 |
||
114 |
/** |
|
115 |
* Clears the cache held by get_theme_roots() and WP_Theme. |
|
116 |
* |
|
117 |
* @since 3.5.0 |
|
118 |
* @param bool $clear_update_cache Whether to clear the Theme updates cache |
|
119 |
*/ |
|
120 |
function wp_clean_themes_cache( $clear_update_cache = true ) { |
|
121 |
if ( $clear_update_cache ) |
|
122 |
delete_site_transient( 'update_themes' ); |
|
123 |
search_theme_directories( true ); |
|
124 |
foreach ( wp_get_themes( array( 'errors' => null ) ) as $theme ) |
|
125 |
$theme->cache_delete(); |
|
126 |
} |
|
127 |
||
128 |
/** |
|
129 |
* Whether a child theme is in use. |
|
130 |
* |
|
131 |
* @since 3.0.0 |
|
132 |
* |
|
133 |
* @return bool true if a child theme is in use, false otherwise. |
|
134 |
**/ |
|
135 |
function is_child_theme() { |
|
136 |
return ( TEMPLATEPATH !== STYLESHEETPATH ); |
|
137 |
} |
|
138 |
||
139 |
/** |
|
140 |
* Retrieve name of the current stylesheet. |
|
141 |
* |
|
142 |
* The theme name that the administrator has currently set the front end theme |
|
143 |
* as. |
|
144 |
* |
|
5 | 145 |
* For all intents and purposes, the template name and the stylesheet name are |
0 | 146 |
* going to be the same for most cases. |
147 |
* |
|
148 |
* @since 1.5.0 |
|
149 |
* |
|
150 |
* @return string Stylesheet name. |
|
151 |
*/ |
|
152 |
function get_stylesheet() { |
|
5 | 153 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
154 |
* Filters the name of current stylesheet. |
5 | 155 |
* |
156 |
* @since 1.5.0 |
|
157 |
* |
|
158 |
* @param string $stylesheet Name of the current stylesheet. |
|
159 |
*/ |
|
160 |
return apply_filters( 'stylesheet', get_option( 'stylesheet' ) ); |
|
0 | 161 |
} |
162 |
||
163 |
/** |
|
164 |
* Retrieve stylesheet directory path for current theme. |
|
165 |
* |
|
166 |
* @since 1.5.0 |
|
167 |
* |
|
168 |
* @return string Path to current theme directory. |
|
169 |
*/ |
|
170 |
function get_stylesheet_directory() { |
|
171 |
$stylesheet = get_stylesheet(); |
|
172 |
$theme_root = get_theme_root( $stylesheet ); |
|
173 |
$stylesheet_dir = "$theme_root/$stylesheet"; |
|
174 |
||
5 | 175 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
176 |
* Filters the stylesheet directory path for current theme. |
5 | 177 |
* |
178 |
* @since 1.5.0 |
|
179 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
180 |
* @param string $stylesheet_dir Absolute path to the current theme. |
5 | 181 |
* @param string $stylesheet Directory name of the current theme. |
182 |
* @param string $theme_root Absolute path to themes directory. |
|
183 |
*/ |
|
0 | 184 |
return apply_filters( 'stylesheet_directory', $stylesheet_dir, $stylesheet, $theme_root ); |
185 |
} |
|
186 |
||
187 |
/** |
|
188 |
* Retrieve stylesheet directory URI. |
|
189 |
* |
|
190 |
* @since 1.5.0 |
|
191 |
* |
|
192 |
* @return string |
|
193 |
*/ |
|
194 |
function get_stylesheet_directory_uri() { |
|
5 | 195 |
$stylesheet = str_replace( '%2F', '/', rawurlencode( get_stylesheet() ) ); |
0 | 196 |
$theme_root_uri = get_theme_root_uri( $stylesheet ); |
197 |
$stylesheet_dir_uri = "$theme_root_uri/$stylesheet"; |
|
198 |
||
5 | 199 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
200 |
* Filters the stylesheet directory URI. |
5 | 201 |
* |
202 |
* @since 1.5.0 |
|
203 |
* |
|
204 |
* @param string $stylesheet_dir_uri Stylesheet directory URI. |
|
205 |
* @param string $stylesheet Name of the activated theme's directory. |
|
206 |
* @param string $theme_root_uri Themes root URI. |
|
207 |
*/ |
|
0 | 208 |
return apply_filters( 'stylesheet_directory_uri', $stylesheet_dir_uri, $stylesheet, $theme_root_uri ); |
209 |
} |
|
210 |
||
211 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
212 |
* Retrieves the URI of current theme stylesheet. |
0 | 213 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
214 |
* 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
|
215 |
* See get_stylesheet_directory_uri(). |
0 | 216 |
* |
217 |
* @since 1.5.0 |
|
218 |
* |
|
219 |
* @return string |
|
220 |
*/ |
|
221 |
function get_stylesheet_uri() { |
|
222 |
$stylesheet_dir_uri = get_stylesheet_directory_uri(); |
|
223 |
$stylesheet_uri = $stylesheet_dir_uri . '/style.css'; |
|
5 | 224 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
225 |
* Filters the URI of the current theme stylesheet. |
5 | 226 |
* |
227 |
* @since 1.5.0 |
|
228 |
* |
|
229 |
* @param string $stylesheet_uri Stylesheet URI for the current theme/child theme. |
|
230 |
* @param string $stylesheet_dir_uri Stylesheet directory URI for the current theme/child theme. |
|
231 |
*/ |
|
232 |
return apply_filters( 'stylesheet_uri', $stylesheet_uri, $stylesheet_dir_uri ); |
|
0 | 233 |
} |
234 |
||
235 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
236 |
* Retrieves the localized stylesheet URI. |
0 | 237 |
* |
238 |
* The stylesheet directory for the localized stylesheet files are located, by |
|
239 |
* default, in the base theme directory. The name of the locale file will be the |
|
240 |
* locale followed by '.css'. If that does not exist, then the text direction |
|
241 |
* stylesheet will be checked for existence, for example 'ltr.css'. |
|
242 |
* |
|
243 |
* 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
|
244 |
* 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
|
245 |
* |
0 | 246 |
* If you want to change the location of the stylesheet files for the entire |
247 |
* WordPress workflow, then change the former. If you just have the locale in a |
|
248 |
* separate folder, then change the latter. |
|
249 |
* |
|
250 |
* @since 2.1.0 |
|
251 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
252 |
* @global WP_Locale $wp_locale |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
253 |
* |
0 | 254 |
* @return string |
255 |
*/ |
|
256 |
function get_locale_stylesheet_uri() { |
|
257 |
global $wp_locale; |
|
258 |
$stylesheet_dir_uri = get_stylesheet_directory_uri(); |
|
259 |
$dir = get_stylesheet_directory(); |
|
260 |
$locale = get_locale(); |
|
261 |
if ( file_exists("$dir/$locale.css") ) |
|
262 |
$stylesheet_uri = "$stylesheet_dir_uri/$locale.css"; |
|
263 |
elseif ( !empty($wp_locale->text_direction) && file_exists("$dir/{$wp_locale->text_direction}.css") ) |
|
264 |
$stylesheet_uri = "$stylesheet_dir_uri/{$wp_locale->text_direction}.css"; |
|
265 |
else |
|
266 |
$stylesheet_uri = ''; |
|
5 | 267 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
268 |
* Filters the localized stylesheet URI. |
5 | 269 |
* |
270 |
* @since 2.1.0 |
|
271 |
* |
|
272 |
* @param string $stylesheet_uri Localized stylesheet URI. |
|
273 |
* @param string $stylesheet_dir_uri Stylesheet directory URI. |
|
274 |
*/ |
|
275 |
return apply_filters( 'locale_stylesheet_uri', $stylesheet_uri, $stylesheet_dir_uri ); |
|
0 | 276 |
} |
277 |
||
278 |
/** |
|
279 |
* Retrieve name of the current theme. |
|
280 |
* |
|
281 |
* @since 1.5.0 |
|
282 |
* |
|
283 |
* @return string Template name. |
|
284 |
*/ |
|
285 |
function get_template() { |
|
5 | 286 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
287 |
* Filters the name of the current theme. |
5 | 288 |
* |
289 |
* @since 1.5.0 |
|
290 |
* |
|
291 |
* @param string $template Current theme's directory name. |
|
292 |
*/ |
|
293 |
return apply_filters( 'template', get_option( 'template' ) ); |
|
0 | 294 |
} |
295 |
||
296 |
/** |
|
297 |
* Retrieve current theme directory. |
|
298 |
* |
|
299 |
* @since 1.5.0 |
|
300 |
* |
|
301 |
* @return string Template directory path. |
|
302 |
*/ |
|
303 |
function get_template_directory() { |
|
304 |
$template = get_template(); |
|
305 |
$theme_root = get_theme_root( $template ); |
|
306 |
$template_dir = "$theme_root/$template"; |
|
307 |
||
5 | 308 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
309 |
* Filters the current theme directory path. |
5 | 310 |
* |
311 |
* @since 1.5.0 |
|
312 |
* |
|
313 |
* @param string $template_dir The URI of the current theme directory. |
|
314 |
* @param string $template Directory name of the current theme. |
|
315 |
* @param string $theme_root Absolute path to the themes directory. |
|
316 |
*/ |
|
0 | 317 |
return apply_filters( 'template_directory', $template_dir, $template, $theme_root ); |
318 |
} |
|
319 |
||
320 |
/** |
|
321 |
* Retrieve theme directory URI. |
|
322 |
* |
|
323 |
* @since 1.5.0 |
|
324 |
* |
|
325 |
* @return string Template directory URI. |
|
326 |
*/ |
|
327 |
function get_template_directory_uri() { |
|
5 | 328 |
$template = str_replace( '%2F', '/', rawurlencode( get_template() ) ); |
0 | 329 |
$theme_root_uri = get_theme_root_uri( $template ); |
330 |
$template_dir_uri = "$theme_root_uri/$template"; |
|
331 |
||
5 | 332 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
333 |
* Filters the current theme directory URI. |
5 | 334 |
* |
335 |
* @since 1.5.0 |
|
336 |
* |
|
337 |
* @param string $template_dir_uri The URI of the current theme directory. |
|
338 |
* @param string $template Directory name of the current theme. |
|
339 |
* @param string $theme_root_uri The themes root URI. |
|
340 |
*/ |
|
0 | 341 |
return apply_filters( 'template_directory_uri', $template_dir_uri, $template, $theme_root_uri ); |
342 |
} |
|
343 |
||
344 |
/** |
|
345 |
* Retrieve theme roots. |
|
346 |
* |
|
347 |
* @since 2.9.0 |
|
348 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
349 |
* @global array $wp_theme_directories |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
350 |
* |
0 | 351 |
* @return array|string An array of theme roots keyed by template/stylesheet or a single theme root if all themes have the same root. |
352 |
*/ |
|
353 |
function get_theme_roots() { |
|
354 |
global $wp_theme_directories; |
|
355 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
356 |
if ( ! is_array( $wp_theme_directories ) || count( $wp_theme_directories ) <= 1 ) { |
0 | 357 |
return '/themes'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
358 |
} |
0 | 359 |
|
360 |
$theme_roots = get_site_transient( 'theme_roots' ); |
|
361 |
if ( false === $theme_roots ) { |
|
362 |
search_theme_directories( true ); // Regenerate the transient. |
|
363 |
$theme_roots = get_site_transient( 'theme_roots' ); |
|
364 |
} |
|
365 |
return $theme_roots; |
|
366 |
} |
|
367 |
||
368 |
/** |
|
369 |
* Register a directory that contains themes. |
|
370 |
* |
|
371 |
* @since 2.9.0 |
|
372 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
373 |
* @global array $wp_theme_directories |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
374 |
* |
0 | 375 |
* @param string $directory Either the full filesystem path to a theme folder or a folder within WP_CONTENT_DIR |
376 |
* @return bool |
|
377 |
*/ |
|
378 |
function register_theme_directory( $directory ) { |
|
379 |
global $wp_theme_directories; |
|
380 |
||
381 |
if ( ! file_exists( $directory ) ) { |
|
382 |
// Try prepending as the theme directory could be relative to the content directory |
|
383 |
$directory = WP_CONTENT_DIR . '/' . $directory; |
|
384 |
// If this directory does not exist, return and do not register |
|
5 | 385 |
if ( ! file_exists( $directory ) ) { |
0 | 386 |
return false; |
5 | 387 |
} |
0 | 388 |
} |
389 |
||
5 | 390 |
if ( ! is_array( $wp_theme_directories ) ) { |
391 |
$wp_theme_directories = array(); |
|
392 |
} |
|
393 |
||
394 |
$untrailed = untrailingslashit( $directory ); |
|
395 |
if ( ! empty( $untrailed ) && ! in_array( $untrailed, $wp_theme_directories ) ) { |
|
396 |
$wp_theme_directories[] = $untrailed; |
|
397 |
} |
|
0 | 398 |
|
399 |
return true; |
|
400 |
} |
|
401 |
||
402 |
/** |
|
403 |
* Search all registered theme directories for complete and valid themes. |
|
404 |
* |
|
405 |
* @since 2.9.0 |
|
406 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
407 |
* @global array $wp_theme_directories |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
408 |
* @staticvar array $found_themes |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
409 |
* |
0 | 410 |
* @param bool $force Optional. Whether to force a new directory scan. Defaults to false. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
411 |
* @return array|false Valid themes found |
0 | 412 |
*/ |
413 |
function search_theme_directories( $force = false ) { |
|
414 |
global $wp_theme_directories; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
415 |
static $found_themes = null; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
416 |
|
0 | 417 |
if ( empty( $wp_theme_directories ) ) |
418 |
return false; |
|
419 |
||
420 |
if ( ! $force && isset( $found_themes ) ) |
|
421 |
return $found_themes; |
|
422 |
||
423 |
$found_themes = array(); |
|
424 |
||
425 |
$wp_theme_directories = (array) $wp_theme_directories; |
|
5 | 426 |
$relative_theme_roots = array(); |
0 | 427 |
|
428 |
// Set up maybe-relative, maybe-absolute array of theme directories. |
|
429 |
// We always want to return absolute, but we need to cache relative |
|
430 |
// to use in get_theme_root(). |
|
431 |
foreach ( $wp_theme_directories as $theme_root ) { |
|
432 |
if ( 0 === strpos( $theme_root, WP_CONTENT_DIR ) ) |
|
433 |
$relative_theme_roots[ str_replace( WP_CONTENT_DIR, '', $theme_root ) ] = $theme_root; |
|
434 |
else |
|
435 |
$relative_theme_roots[ $theme_root ] = $theme_root; |
|
436 |
} |
|
437 |
||
5 | 438 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
439 |
* Filters whether to get the cache of the registered theme directories. |
5 | 440 |
* |
441 |
* @since 3.4.0 |
|
442 |
* |
|
443 |
* @param bool $cache_expiration Whether to get the cache of the theme directories. Default false. |
|
444 |
* @param string $cache_directory Directory to be searched for the cache. |
|
445 |
*/ |
|
0 | 446 |
if ( $cache_expiration = apply_filters( 'wp_cache_themes_persistently', false, 'search_theme_directories' ) ) { |
447 |
$cached_roots = get_site_transient( 'theme_roots' ); |
|
448 |
if ( is_array( $cached_roots ) ) { |
|
449 |
foreach ( $cached_roots as $theme_dir => $theme_root ) { |
|
450 |
// A cached theme root is no longer around, so skip it. |
|
451 |
if ( ! isset( $relative_theme_roots[ $theme_root ] ) ) |
|
452 |
continue; |
|
453 |
$found_themes[ $theme_dir ] = array( |
|
454 |
'theme_file' => $theme_dir . '/style.css', |
|
455 |
'theme_root' => $relative_theme_roots[ $theme_root ], // Convert relative to absolute. |
|
456 |
); |
|
457 |
} |
|
458 |
return $found_themes; |
|
459 |
} |
|
460 |
if ( ! is_int( $cache_expiration ) ) |
|
461 |
$cache_expiration = 1800; // half hour |
|
462 |
} else { |
|
463 |
$cache_expiration = 1800; // half hour |
|
464 |
} |
|
465 |
||
466 |
/* Loop the registered theme directories and extract all themes */ |
|
467 |
foreach ( $wp_theme_directories as $theme_root ) { |
|
468 |
||
469 |
// Start with directories in the root of the current theme directory. |
|
470 |
$dirs = @ scandir( $theme_root ); |
|
471 |
if ( ! $dirs ) { |
|
472 |
trigger_error( "$theme_root is not readable", E_USER_NOTICE ); |
|
473 |
continue; |
|
474 |
} |
|
475 |
foreach ( $dirs as $dir ) { |
|
476 |
if ( ! is_dir( $theme_root . '/' . $dir ) || $dir[0] == '.' || $dir == 'CVS' ) |
|
477 |
continue; |
|
478 |
if ( file_exists( $theme_root . '/' . $dir . '/style.css' ) ) { |
|
479 |
// wp-content/themes/a-single-theme |
|
480 |
// wp-content/themes is $theme_root, a-single-theme is $dir |
|
481 |
$found_themes[ $dir ] = array( |
|
482 |
'theme_file' => $dir . '/style.css', |
|
483 |
'theme_root' => $theme_root, |
|
484 |
); |
|
485 |
} else { |
|
486 |
$found_theme = false; |
|
487 |
// wp-content/themes/a-folder-of-themes/* |
|
488 |
// wp-content/themes is $theme_root, a-folder-of-themes is $dir, then themes are $sub_dirs |
|
489 |
$sub_dirs = @ scandir( $theme_root . '/' . $dir ); |
|
490 |
if ( ! $sub_dirs ) { |
|
491 |
trigger_error( "$theme_root/$dir is not readable", E_USER_NOTICE ); |
|
492 |
continue; |
|
493 |
} |
|
494 |
foreach ( $sub_dirs as $sub_dir ) { |
|
495 |
if ( ! is_dir( $theme_root . '/' . $dir . '/' . $sub_dir ) || $dir[0] == '.' || $dir == 'CVS' ) |
|
496 |
continue; |
|
497 |
if ( ! file_exists( $theme_root . '/' . $dir . '/' . $sub_dir . '/style.css' ) ) |
|
498 |
continue; |
|
499 |
$found_themes[ $dir . '/' . $sub_dir ] = array( |
|
500 |
'theme_file' => $dir . '/' . $sub_dir . '/style.css', |
|
501 |
'theme_root' => $theme_root, |
|
502 |
); |
|
503 |
$found_theme = true; |
|
504 |
} |
|
505 |
// Never mind the above, it's just a theme missing a style.css. |
|
506 |
// Return it; WP_Theme will catch the error. |
|
507 |
if ( ! $found_theme ) |
|
508 |
$found_themes[ $dir ] = array( |
|
509 |
'theme_file' => $dir . '/style.css', |
|
510 |
'theme_root' => $theme_root, |
|
511 |
); |
|
512 |
} |
|
513 |
} |
|
514 |
} |
|
515 |
||
516 |
asort( $found_themes ); |
|
517 |
||
518 |
$theme_roots = array(); |
|
519 |
$relative_theme_roots = array_flip( $relative_theme_roots ); |
|
520 |
||
521 |
foreach ( $found_themes as $theme_dir => $theme_data ) { |
|
522 |
$theme_roots[ $theme_dir ] = $relative_theme_roots[ $theme_data['theme_root'] ]; // Convert absolute to relative. |
|
523 |
} |
|
524 |
||
525 |
if ( $theme_roots != get_site_transient( 'theme_roots' ) ) |
|
526 |
set_site_transient( 'theme_roots', $theme_roots, $cache_expiration ); |
|
527 |
||
528 |
return $found_themes; |
|
529 |
} |
|
530 |
||
531 |
/** |
|
532 |
* Retrieve path to themes directory. |
|
533 |
* |
|
534 |
* Does not have trailing slash. |
|
535 |
* |
|
536 |
* @since 1.5.0 |
|
537 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
538 |
* @global array $wp_theme_directories |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
539 |
* |
0 | 540 |
* @param string $stylesheet_or_template The stylesheet or template name of the theme |
541 |
* @return string Theme path. |
|
542 |
*/ |
|
543 |
function get_theme_root( $stylesheet_or_template = false ) { |
|
544 |
global $wp_theme_directories; |
|
545 |
||
546 |
if ( $stylesheet_or_template && $theme_root = get_raw_theme_root( $stylesheet_or_template ) ) { |
|
547 |
// Always prepend WP_CONTENT_DIR unless the root currently registered as a theme directory. |
|
548 |
// This gives relative theme roots the benefit of the doubt when things go haywire. |
|
549 |
if ( ! in_array( $theme_root, (array) $wp_theme_directories ) ) |
|
550 |
$theme_root = WP_CONTENT_DIR . $theme_root; |
|
551 |
} else { |
|
552 |
$theme_root = WP_CONTENT_DIR . '/themes'; |
|
553 |
} |
|
554 |
||
5 | 555 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
556 |
* Filters the absolute path to the themes directory. |
5 | 557 |
* |
558 |
* @since 1.5.0 |
|
559 |
* |
|
560 |
* @param string $theme_root Absolute path to themes directory. |
|
561 |
*/ |
|
0 | 562 |
return apply_filters( 'theme_root', $theme_root ); |
563 |
} |
|
564 |
||
565 |
/** |
|
566 |
* Retrieve URI for themes directory. |
|
567 |
* |
|
568 |
* Does not have trailing slash. |
|
569 |
* |
|
570 |
* @since 1.5.0 |
|
571 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
572 |
* @global array $wp_theme_directories |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
573 |
* |
0 | 574 |
* @param string $stylesheet_or_template Optional. The stylesheet or template name of the theme. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
575 |
* Default is to leverage the main theme root. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
576 |
* @param string $theme_root Optional. The theme root for which calculations will be based, preventing |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
577 |
* the need for a get_raw_theme_root() call. |
0 | 578 |
* @return string Themes URI. |
579 |
*/ |
|
580 |
function get_theme_root_uri( $stylesheet_or_template = false, $theme_root = false ) { |
|
581 |
global $wp_theme_directories; |
|
582 |
||
583 |
if ( $stylesheet_or_template && ! $theme_root ) |
|
584 |
$theme_root = get_raw_theme_root( $stylesheet_or_template ); |
|
585 |
||
586 |
if ( $stylesheet_or_template && $theme_root ) { |
|
587 |
if ( in_array( $theme_root, (array) $wp_theme_directories ) ) { |
|
588 |
// Absolute path. Make an educated guess. YMMV -- but note the filter below. |
|
589 |
if ( 0 === strpos( $theme_root, WP_CONTENT_DIR ) ) |
|
590 |
$theme_root_uri = content_url( str_replace( WP_CONTENT_DIR, '', $theme_root ) ); |
|
591 |
elseif ( 0 === strpos( $theme_root, ABSPATH ) ) |
|
592 |
$theme_root_uri = site_url( str_replace( ABSPATH, '', $theme_root ) ); |
|
593 |
elseif ( 0 === strpos( $theme_root, WP_PLUGIN_DIR ) || 0 === strpos( $theme_root, WPMU_PLUGIN_DIR ) ) |
|
594 |
$theme_root_uri = plugins_url( basename( $theme_root ), $theme_root ); |
|
595 |
else |
|
596 |
$theme_root_uri = $theme_root; |
|
597 |
} else { |
|
598 |
$theme_root_uri = content_url( $theme_root ); |
|
599 |
} |
|
600 |
} else { |
|
601 |
$theme_root_uri = content_url( 'themes' ); |
|
602 |
} |
|
603 |
||
5 | 604 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
605 |
* Filters the URI for themes directory. |
5 | 606 |
* |
607 |
* @since 1.5.0 |
|
608 |
* |
|
609 |
* @param string $theme_root_uri The URI for themes directory. |
|
610 |
* @param string $siteurl WordPress web address which is set in General Options. |
|
611 |
* @param string $stylesheet_or_template Stylesheet or template name of the theme. |
|
612 |
*/ |
|
613 |
return apply_filters( 'theme_root_uri', $theme_root_uri, get_option( 'siteurl' ), $stylesheet_or_template ); |
|
0 | 614 |
} |
615 |
||
616 |
/** |
|
617 |
* Get the raw theme root relative to the content directory with no filters applied. |
|
618 |
* |
|
619 |
* @since 3.1.0 |
|
620 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
621 |
* @global array $wp_theme_directories |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
622 |
* |
0 | 623 |
* @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
|
624 |
* @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
|
625 |
* Defaults to false, meaning the cache is used. |
0 | 626 |
* @return string Theme root |
627 |
*/ |
|
628 |
function get_raw_theme_root( $stylesheet_or_template, $skip_cache = false ) { |
|
629 |
global $wp_theme_directories; |
|
630 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
631 |
if ( ! is_array( $wp_theme_directories ) || count( $wp_theme_directories ) <= 1 ) { |
0 | 632 |
return '/themes'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
633 |
} |
0 | 634 |
|
635 |
$theme_root = false; |
|
636 |
||
637 |
// If requesting the root for the current theme, consult options to avoid calling get_theme_roots() |
|
638 |
if ( ! $skip_cache ) { |
|
639 |
if ( get_option('stylesheet') == $stylesheet_or_template ) |
|
640 |
$theme_root = get_option('stylesheet_root'); |
|
641 |
elseif ( get_option('template') == $stylesheet_or_template ) |
|
642 |
$theme_root = get_option('template_root'); |
|
643 |
} |
|
644 |
||
645 |
if ( empty($theme_root) ) { |
|
646 |
$theme_roots = get_theme_roots(); |
|
647 |
if ( !empty($theme_roots[$stylesheet_or_template]) ) |
|
648 |
$theme_root = $theme_roots[$stylesheet_or_template]; |
|
649 |
} |
|
650 |
||
651 |
return $theme_root; |
|
652 |
} |
|
653 |
||
654 |
/** |
|
655 |
* Display localized stylesheet link element. |
|
656 |
* |
|
657 |
* @since 2.1.0 |
|
658 |
*/ |
|
659 |
function locale_stylesheet() { |
|
660 |
$stylesheet = get_locale_stylesheet_uri(); |
|
661 |
if ( empty($stylesheet) ) |
|
662 |
return; |
|
663 |
echo '<link rel="stylesheet" href="' . $stylesheet . '" type="text/css" media="screen" />'; |
|
664 |
} |
|
665 |
||
666 |
/** |
|
667 |
* Switches the theme. |
|
668 |
* |
|
669 |
* 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
|
670 |
* of two arguments: $template then $stylesheet. This is for backward compatibility. |
0 | 671 |
* |
672 |
* @since 2.5.0 |
|
673 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
674 |
* @global array $wp_theme_directories |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
675 |
* @global WP_Customize_Manager $wp_customize |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
676 |
* @global array $sidebars_widgets |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
677 |
* |
0 | 678 |
* @param string $stylesheet Stylesheet name |
679 |
*/ |
|
680 |
function switch_theme( $stylesheet ) { |
|
5 | 681 |
global $wp_theme_directories, $wp_customize, $sidebars_widgets; |
0 | 682 |
|
5 | 683 |
$_sidebars_widgets = null; |
684 |
if ( 'wp_ajax_customize_save' === current_action() ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
685 |
$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
|
686 |
if ( $old_sidebars_widgets_data_setting ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
687 |
$_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
|
688 |
} |
5 | 689 |
} elseif ( is_array( $sidebars_widgets ) ) { |
690 |
$_sidebars_widgets = $sidebars_widgets; |
|
691 |
} |
|
692 |
||
693 |
if ( is_array( $_sidebars_widgets ) ) { |
|
694 |
set_theme_mod( 'sidebars_widgets', array( 'time' => time(), 'data' => $_sidebars_widgets ) ); |
|
695 |
} |
|
0 | 696 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
697 |
$nav_menu_locations = get_theme_mod( 'nav_menu_locations' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
698 |
update_option( 'theme_switch_menu_locations', $nav_menu_locations ); |
0 | 699 |
|
700 |
if ( func_num_args() > 1 ) { |
|
701 |
$stylesheet = func_get_arg( 1 ); |
|
702 |
} |
|
703 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
704 |
$old_theme = wp_get_theme(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
705 |
$new_theme = wp_get_theme( $stylesheet ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
706 |
$template = $new_theme->get_template(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
707 |
|
0 | 708 |
update_option( 'template', $template ); |
709 |
update_option( 'stylesheet', $stylesheet ); |
|
710 |
||
711 |
if ( count( $wp_theme_directories ) > 1 ) { |
|
712 |
update_option( 'template_root', get_raw_theme_root( $template, true ) ); |
|
713 |
update_option( 'stylesheet_root', get_raw_theme_root( $stylesheet, true ) ); |
|
714 |
} else { |
|
715 |
delete_option( 'template_root' ); |
|
716 |
delete_option( 'stylesheet_root' ); |
|
717 |
} |
|
718 |
||
719 |
$new_name = $new_theme->get('Name'); |
|
720 |
||
721 |
update_option( 'current_theme', $new_name ); |
|
722 |
||
5 | 723 |
// Migrate from the old mods_{name} option to theme_mods_{slug}. |
0 | 724 |
if ( is_admin() && false === get_option( 'theme_mods_' . $stylesheet ) ) { |
725 |
$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
|
726 |
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
|
727 |
$default_theme_mods['nav_menu_locations'] = $nav_menu_locations; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
728 |
} |
0 | 729 |
add_option( "theme_mods_$stylesheet", $default_theme_mods ); |
5 | 730 |
} else { |
731 |
/* |
|
732 |
* 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
|
733 |
* we need to remove the theme mods to avoid overwriting changes made via |
5 | 734 |
* the Customizer when accessing wp-admin/widgets.php. |
735 |
*/ |
|
736 |
if ( 'wp_ajax_customize_save' === current_action() ) { |
|
737 |
remove_theme_mod( 'sidebars_widgets' ); |
|
738 |
} |
|
0 | 739 |
} |
740 |
||
741 |
update_option( 'theme_switched', $old_theme->get_stylesheet() ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
742 |
|
5 | 743 |
/** |
744 |
* Fires after the theme is switched. |
|
745 |
* |
|
746 |
* @since 1.5.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
747 |
* @since 4.5.0 Introduced the `$old_theme` parameter. |
5 | 748 |
* |
749 |
* @param string $new_name Name of the new theme. |
|
750 |
* @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
|
751 |
* @param WP_Theme $old_theme WP_Theme instance of the old theme. |
5 | 752 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
753 |
do_action( 'switch_theme', $new_name, $new_theme, $old_theme ); |
0 | 754 |
} |
755 |
||
756 |
/** |
|
757 |
* Checks that current theme files 'index.php' and 'style.css' exists. |
|
758 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
759 |
* 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
|
760 |
* But if it doesn't exist, it'll fall back to the latest core default theme that does exist. |
0 | 761 |
* Will switch theme to the fallback theme if current theme does not validate. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
762 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
763 |
* You can use the {@see 'validate_current_theme'} filter to return false to |
0 | 764 |
* disable this functionality. |
765 |
* |
|
766 |
* @since 1.5.0 |
|
767 |
* @see WP_DEFAULT_THEME |
|
768 |
* |
|
769 |
* @return bool |
|
770 |
*/ |
|
771 |
function validate_current_theme() { |
|
5 | 772 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
773 |
* Filters whether to validate the current theme. |
5 | 774 |
* |
775 |
* @since 2.7.0 |
|
776 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
777 |
* @param bool $validate Whether to validate the current theme. Default true. |
5 | 778 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
779 |
if ( wp_installing() || ! apply_filters( 'validate_current_theme', true ) ) |
0 | 780 |
return true; |
781 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
782 |
if ( ! file_exists( get_template_directory() . '/index.php' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
783 |
// Invalid. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
784 |
} elseif ( ! file_exists( get_template_directory() . '/style.css' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
785 |
// Invalid. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
786 |
} 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
|
787 |
// Invalid. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
788 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
789 |
// Valid. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
790 |
return true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
791 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
792 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
793 |
$default = wp_get_theme( WP_DEFAULT_THEME ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
794 |
if ( $default->exists() ) { |
0 | 795 |
switch_theme( WP_DEFAULT_THEME ); |
796 |
return false; |
|
797 |
} |
|
798 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
799 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
800 |
* 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
|
801 |
* switch to the latest core default theme that's installed. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
802 |
* 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
|
803 |
* 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
|
804 |
* 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
|
805 |
* 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
|
806 |
* 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
|
807 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
808 |
$default = WP_Theme::get_core_default_theme(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
809 |
if ( false === $default || get_stylesheet() == $default->get_stylesheet() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
810 |
return true; |
0 | 811 |
} |
812 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
813 |
switch_theme( $default->get_stylesheet() ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
814 |
return false; |
0 | 815 |
} |
816 |
||
817 |
/** |
|
818 |
* Retrieve all theme modifications. |
|
819 |
* |
|
820 |
* @since 3.1.0 |
|
821 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
822 |
* @return array|void Theme modifications. |
0 | 823 |
*/ |
824 |
function get_theme_mods() { |
|
825 |
$theme_slug = get_option( 'stylesheet' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
826 |
$mods = get_option( "theme_mods_$theme_slug" ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
827 |
if ( false === $mods ) { |
0 | 828 |
$theme_name = get_option( 'current_theme' ); |
829 |
if ( false === $theme_name ) |
|
830 |
$theme_name = wp_get_theme()->get('Name'); |
|
831 |
$mods = get_option( "mods_$theme_name" ); // Deprecated location. |
|
832 |
if ( is_admin() && false !== $mods ) { |
|
833 |
update_option( "theme_mods_$theme_slug", $mods ); |
|
834 |
delete_option( "mods_$theme_name" ); |
|
835 |
} |
|
836 |
} |
|
837 |
return $mods; |
|
838 |
} |
|
839 |
||
840 |
/** |
|
841 |
* Retrieve theme modification value for the current theme. |
|
842 |
* |
|
843 |
* If the modification name does not exist, then the $default will be passed |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
844 |
* through {@link https://secure.php.net/sprintf sprintf()} PHP function with the first |
0 | 845 |
* string the template directory URI and the second string the stylesheet |
846 |
* directory URI. |
|
847 |
* |
|
848 |
* @since 2.1.0 |
|
849 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
850 |
* @param string $name Theme modification name. |
0 | 851 |
* @param bool|string $default |
852 |
* @return string |
|
853 |
*/ |
|
854 |
function get_theme_mod( $name, $default = false ) { |
|
855 |
$mods = get_theme_mods(); |
|
856 |
||
5 | 857 |
if ( isset( $mods[$name] ) ) { |
858 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
859 |
* Filters the theme modification, or 'theme_mod', value. |
5 | 860 |
* |
861 |
* The dynamic portion of the hook name, `$name`, refers to |
|
862 |
* the key name of the modification array. For example, |
|
863 |
* 'header_textcolor', 'header_image', and so on depending |
|
864 |
* on the theme options. |
|
865 |
* |
|
866 |
* @since 2.2.0 |
|
867 |
* |
|
868 |
* @param string $current_mod The value of the current theme modification. |
|
869 |
*/ |
|
870 |
return apply_filters( "theme_mod_{$name}", $mods[$name] ); |
|
871 |
} |
|
0 | 872 |
|
873 |
if ( is_string( $default ) ) |
|
874 |
$default = sprintf( $default, get_template_directory_uri(), get_stylesheet_directory_uri() ); |
|
875 |
||
5 | 876 |
/** This filter is documented in wp-includes/theme.php */ |
877 |
return apply_filters( "theme_mod_{$name}", $default ); |
|
0 | 878 |
} |
879 |
||
880 |
/** |
|
881 |
* Update theme modification value for the current theme. |
|
882 |
* |
|
883 |
* @since 2.1.0 |
|
884 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
885 |
* @param string $name Theme modification name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
886 |
* @param mixed $value Theme modification value. |
0 | 887 |
*/ |
888 |
function set_theme_mod( $name, $value ) { |
|
889 |
$mods = get_theme_mods(); |
|
5 | 890 |
$old_value = isset( $mods[ $name ] ) ? $mods[ $name ] : false; |
0 | 891 |
|
5 | 892 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
893 |
* Filters the theme mod value on save. |
5 | 894 |
* |
895 |
* The dynamic portion of the hook name, `$name`, refers to the key name of |
|
896 |
* the modification array. For example, 'header_textcolor', 'header_image', |
|
897 |
* and so on depending on the theme options. |
|
898 |
* |
|
899 |
* @since 3.9.0 |
|
900 |
* |
|
901 |
* @param string $value The new value of the theme mod. |
|
902 |
* @param string $old_value The current value of the theme mod. |
|
903 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
904 |
$mods[ $name ] = apply_filters( "pre_set_theme_mod_{$name}", $value, $old_value ); |
0 | 905 |
|
906 |
$theme = get_option( 'stylesheet' ); |
|
907 |
update_option( "theme_mods_$theme", $mods ); |
|
908 |
} |
|
909 |
||
910 |
/** |
|
911 |
* Remove theme modification name from current theme list. |
|
912 |
* |
|
913 |
* If removing the name also removes all elements, then the entire option will |
|
914 |
* be removed. |
|
915 |
* |
|
916 |
* @since 2.1.0 |
|
917 |
* |
|
918 |
* @param string $name Theme modification name. |
|
919 |
*/ |
|
920 |
function remove_theme_mod( $name ) { |
|
921 |
$mods = get_theme_mods(); |
|
922 |
||
923 |
if ( ! isset( $mods[ $name ] ) ) |
|
924 |
return; |
|
925 |
||
926 |
unset( $mods[ $name ] ); |
|
927 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
928 |
if ( empty( $mods ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
929 |
remove_theme_mods(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
930 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
931 |
} |
0 | 932 |
$theme = get_option( 'stylesheet' ); |
933 |
update_option( "theme_mods_$theme", $mods ); |
|
934 |
} |
|
935 |
||
936 |
/** |
|
937 |
* Remove theme modifications option for current theme. |
|
938 |
* |
|
939 |
* @since 2.1.0 |
|
940 |
*/ |
|
941 |
function remove_theme_mods() { |
|
942 |
delete_option( 'theme_mods_' . get_option( 'stylesheet' ) ); |
|
943 |
||
944 |
// Old style. |
|
945 |
$theme_name = get_option( 'current_theme' ); |
|
946 |
if ( false === $theme_name ) |
|
947 |
$theme_name = wp_get_theme()->get('Name'); |
|
948 |
delete_option( 'mods_' . $theme_name ); |
|
949 |
} |
|
950 |
||
951 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
952 |
* Retrieves the custom header text color in 3- or 6-digit hexadecimal form. |
0 | 953 |
* |
954 |
* @since 2.1.0 |
|
955 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
956 |
* @return string Header text color in 3- or 6-digit hexadecimal form (minus the hash symbol). |
0 | 957 |
*/ |
958 |
function get_header_textcolor() { |
|
959 |
return get_theme_mod('header_textcolor', get_theme_support( 'custom-header', 'default-text-color' ) ); |
|
960 |
} |
|
961 |
||
962 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
963 |
* Displays the custom header text color in 3- or 6-digit hexadecimal form (minus the hash symbol). |
0 | 964 |
* |
965 |
* @since 2.1.0 |
|
966 |
*/ |
|
967 |
function header_textcolor() { |
|
968 |
echo get_header_textcolor(); |
|
969 |
} |
|
970 |
||
971 |
/** |
|
972 |
* Whether to display the header text. |
|
973 |
* |
|
974 |
* @since 3.4.0 |
|
975 |
* |
|
976 |
* @return bool |
|
977 |
*/ |
|
978 |
function display_header_text() { |
|
979 |
if ( ! current_theme_supports( 'custom-header', 'header-text' ) ) |
|
980 |
return false; |
|
981 |
||
982 |
$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
|
983 |
return 'blank' !== $text_color; |
0 | 984 |
} |
985 |
||
986 |
/** |
|
5 | 987 |
* Check whether a header image is set or not. |
988 |
* |
|
989 |
* @since 4.2.0 |
|
990 |
* |
|
991 |
* @see get_header_image() |
|
992 |
* |
|
993 |
* @return bool Whether a header image is set or not. |
|
994 |
*/ |
|
995 |
function has_header_image() { |
|
996 |
return (bool) get_header_image(); |
|
997 |
} |
|
998 |
||
999 |
/** |
|
0 | 1000 |
* Retrieve header image for custom header. |
1001 |
* |
|
1002 |
* @since 2.1.0 |
|
1003 |
* |
|
5 | 1004 |
* @return string|false |
0 | 1005 |
*/ |
1006 |
function get_header_image() { |
|
1007 |
$url = get_theme_mod( 'header_image', get_theme_support( 'custom-header', 'default-image' ) ); |
|
1008 |
||
1009 |
if ( 'remove-header' == $url ) |
|
1010 |
return false; |
|
1011 |
||
1012 |
if ( is_random_header_image() ) |
|
1013 |
$url = get_random_header_image(); |
|
1014 |
||
1015 |
return esc_url_raw( set_url_scheme( $url ) ); |
|
1016 |
} |
|
1017 |
||
1018 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1019 |
* Create image tag markup for a custom header image. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1020 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1021 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1022 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1023 |
* @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
|
1024 |
* to override the default attributes. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1025 |
* @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
|
1026 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1027 |
function get_header_image_tag( $attr = array() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1028 |
$header = get_custom_header(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1029 |
$header->url = get_header_image(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1030 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1031 |
if ( ! $header->url ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1032 |
return ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1033 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1034 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1035 |
$width = absint( $header->width ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1036 |
$height = absint( $header->height ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1037 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1038 |
$attr = wp_parse_args( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1039 |
$attr, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1040 |
array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1041 |
'src' => $header->url, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1042 |
'width' => $width, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1043 |
'height' => $height, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1044 |
'alt' => get_bloginfo( 'name' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1045 |
) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1046 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1047 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1048 |
// Generate 'srcset' and 'sizes' if not already present. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1049 |
if ( empty( $attr['srcset'] ) && ! empty( $header->attachment_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1050 |
$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
|
1051 |
$size_array = array( $width, $height ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1052 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1053 |
if ( is_array( $image_meta ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1054 |
$srcset = wp_calculate_image_srcset( $size_array, $header->url, $image_meta, $header->attachment_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1055 |
$sizes = ! empty( $attr['sizes'] ) ? $attr['sizes'] : wp_calculate_image_sizes( $size_array, $header->url, $image_meta, $header->attachment_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1056 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1057 |
if ( $srcset && $sizes ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1058 |
$attr['srcset'] = $srcset; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1059 |
$attr['sizes'] = $sizes; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1060 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1061 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1062 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1063 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1064 |
$attr = array_map( 'esc_attr', $attr ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1065 |
$html = '<img'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1066 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1067 |
foreach ( $attr as $name => $value ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1068 |
$html .= ' ' . $name . '="' . $value . '"'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1069 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1070 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1071 |
$html .= ' />'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1072 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1073 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1074 |
* Filters the markup of header images. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1075 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1076 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1077 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1078 |
* @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
|
1079 |
* @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
|
1080 |
* @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
|
1081 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1082 |
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
|
1083 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1084 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1085 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1086 |
* Display the image markup for a custom header image. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1087 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1088 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1089 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1090 |
* @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
|
1091 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1092 |
function the_header_image_tag( $attr = array() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1093 |
echo get_header_image_tag( $attr ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1094 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1095 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1096 |
/** |
0 | 1097 |
* Get random header image data from registered images in theme. |
1098 |
* |
|
1099 |
* @since 3.4.0 |
|
1100 |
* |
|
1101 |
* @access private |
|
1102 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1103 |
* @global array $_wp_default_headers |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1104 |
* @staticvar object $_wp_random_header |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1105 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1106 |
* @return object |
0 | 1107 |
*/ |
1108 |
function _get_random_header_data() { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1109 |
static $_wp_random_header = null; |
0 | 1110 |
|
1111 |
if ( empty( $_wp_random_header ) ) { |
|
1112 |
global $_wp_default_headers; |
|
1113 |
$header_image_mod = get_theme_mod( 'header_image', '' ); |
|
1114 |
$headers = array(); |
|
1115 |
||
1116 |
if ( 'random-uploaded-image' == $header_image_mod ) |
|
1117 |
$headers = get_uploaded_header_images(); |
|
1118 |
elseif ( ! empty( $_wp_default_headers ) ) { |
|
1119 |
if ( 'random-default-image' == $header_image_mod ) { |
|
1120 |
$headers = $_wp_default_headers; |
|
1121 |
} else { |
|
1122 |
if ( current_theme_supports( 'custom-header', 'random-default' ) ) |
|
1123 |
$headers = $_wp_default_headers; |
|
1124 |
} |
|
1125 |
} |
|
1126 |
||
1127 |
if ( empty( $headers ) ) |
|
1128 |
return new stdClass; |
|
1129 |
||
1130 |
$_wp_random_header = (object) $headers[ array_rand( $headers ) ]; |
|
1131 |
||
1132 |
$_wp_random_header->url = sprintf( $_wp_random_header->url, get_template_directory_uri(), get_stylesheet_directory_uri() ); |
|
1133 |
$_wp_random_header->thumbnail_url = sprintf( $_wp_random_header->thumbnail_url, get_template_directory_uri(), get_stylesheet_directory_uri() ); |
|
1134 |
} |
|
1135 |
return $_wp_random_header; |
|
1136 |
} |
|
1137 |
||
1138 |
/** |
|
1139 |
* Get random header image url from registered images in theme. |
|
1140 |
* |
|
1141 |
* @since 3.2.0 |
|
1142 |
* |
|
1143 |
* @return string Path to header image |
|
1144 |
*/ |
|
1145 |
function get_random_header_image() { |
|
1146 |
$random_image = _get_random_header_data(); |
|
1147 |
if ( empty( $random_image->url ) ) |
|
1148 |
return ''; |
|
1149 |
return $random_image->url; |
|
1150 |
} |
|
1151 |
||
1152 |
/** |
|
1153 |
* Check if random header image is in use. |
|
1154 |
* |
|
1155 |
* Always true if user expressly chooses the option in Appearance > Header. |
|
1156 |
* Also true if theme has multiple header images registered, no specific header image |
|
1157 |
* is chosen, and theme turns on random headers with add_theme_support(). |
|
1158 |
* |
|
1159 |
* @since 3.2.0 |
|
1160 |
* |
|
1161 |
* @param string $type The random pool to use. any|default|uploaded |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1162 |
* @return bool |
0 | 1163 |
*/ |
1164 |
function is_random_header_image( $type = 'any' ) { |
|
1165 |
$header_image_mod = get_theme_mod( 'header_image', get_theme_support( 'custom-header', 'default-image' ) ); |
|
1166 |
||
1167 |
if ( 'any' == $type ) { |
|
1168 |
if ( 'random-default-image' == $header_image_mod || 'random-uploaded-image' == $header_image_mod || ( '' != get_random_header_image() && empty( $header_image_mod ) ) ) |
|
1169 |
return true; |
|
1170 |
} else { |
|
1171 |
if ( "random-$type-image" == $header_image_mod ) |
|
1172 |
return true; |
|
1173 |
elseif ( 'default' == $type && empty( $header_image_mod ) && '' != get_random_header_image() ) |
|
1174 |
return true; |
|
1175 |
} |
|
1176 |
||
1177 |
return false; |
|
1178 |
} |
|
1179 |
||
1180 |
/** |
|
1181 |
* Display header image URL. |
|
1182 |
* |
|
1183 |
* @since 2.1.0 |
|
1184 |
*/ |
|
1185 |
function header_image() { |
|
5 | 1186 |
$image = get_header_image(); |
1187 |
if ( $image ) { |
|
1188 |
echo esc_url( $image ); |
|
1189 |
} |
|
0 | 1190 |
} |
1191 |
||
1192 |
/** |
|
1193 |
* Get the header images uploaded for the current theme. |
|
1194 |
* |
|
1195 |
* @since 3.2.0 |
|
1196 |
* |
|
1197 |
* @return array |
|
1198 |
*/ |
|
1199 |
function get_uploaded_header_images() { |
|
1200 |
$header_images = array(); |
|
1201 |
||
1202 |
// @todo caching |
|
1203 |
$headers = get_posts( array( 'post_type' => 'attachment', 'meta_key' => '_wp_attachment_is_custom_header', 'meta_value' => get_option('stylesheet'), 'orderby' => 'none', 'nopaging' => true ) ); |
|
1204 |
||
1205 |
if ( empty( $headers ) ) |
|
1206 |
return array(); |
|
1207 |
||
1208 |
foreach ( (array) $headers as $header ) { |
|
5 | 1209 |
$url = esc_url_raw( wp_get_attachment_url( $header->ID ) ); |
0 | 1210 |
$header_data = wp_get_attachment_metadata( $header->ID ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1211 |
$header_index = $header->ID; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1212 |
|
0 | 1213 |
$header_images[$header_index] = array(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1214 |
$header_images[$header_index]['attachment_id'] = $header->ID; |
0 | 1215 |
$header_images[$header_index]['url'] = $url; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1216 |
$header_images[$header_index]['thumbnail_url'] = $url; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1217 |
$header_images[$header_index]['alt_text'] = get_post_meta( $header->ID, '_wp_attachment_image_alt', true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1218 |
$header_images[$header_index]['attachment_parent'] = isset( $header_data['attachment_parent'] ) ? $header_data['attachment_parent'] : ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1219 |
|
0 | 1220 |
if ( isset( $header_data['width'] ) ) |
1221 |
$header_images[$header_index]['width'] = $header_data['width']; |
|
1222 |
if ( isset( $header_data['height'] ) ) |
|
1223 |
$header_images[$header_index]['height'] = $header_data['height']; |
|
1224 |
} |
|
1225 |
||
1226 |
return $header_images; |
|
1227 |
} |
|
1228 |
||
1229 |
/** |
|
1230 |
* Get the header image data. |
|
1231 |
* |
|
1232 |
* @since 3.4.0 |
|
1233 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1234 |
* @global array $_wp_default_headers |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1235 |
* |
0 | 1236 |
* @return object |
1237 |
*/ |
|
1238 |
function get_custom_header() { |
|
1239 |
global $_wp_default_headers; |
|
1240 |
||
1241 |
if ( is_random_header_image() ) { |
|
1242 |
$data = _get_random_header_data(); |
|
1243 |
} else { |
|
1244 |
$data = get_theme_mod( 'header_image_data' ); |
|
1245 |
if ( ! $data && current_theme_supports( 'custom-header', 'default-image' ) ) { |
|
1246 |
$directory_args = array( get_template_directory_uri(), get_stylesheet_directory_uri() ); |
|
1247 |
$data = array(); |
|
1248 |
$data['url'] = $data['thumbnail_url'] = vsprintf( get_theme_support( 'custom-header', 'default-image' ), $directory_args ); |
|
1249 |
if ( ! empty( $_wp_default_headers ) ) { |
|
1250 |
foreach ( (array) $_wp_default_headers as $default_header ) { |
|
1251 |
$url = vsprintf( $default_header['url'], $directory_args ); |
|
1252 |
if ( $data['url'] == $url ) { |
|
1253 |
$data = $default_header; |
|
1254 |
$data['url'] = $url; |
|
1255 |
$data['thumbnail_url'] = vsprintf( $data['thumbnail_url'], $directory_args ); |
|
1256 |
break; |
|
1257 |
} |
|
1258 |
} |
|
1259 |
} |
|
1260 |
} |
|
1261 |
} |
|
1262 |
||
1263 |
$default = array( |
|
1264 |
'url' => '', |
|
1265 |
'thumbnail_url' => '', |
|
1266 |
'width' => get_theme_support( 'custom-header', 'width' ), |
|
1267 |
'height' => get_theme_support( 'custom-header', 'height' ), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1268 |
'video' => get_theme_support( 'custom-header', 'video' ), |
0 | 1269 |
); |
1270 |
return (object) wp_parse_args( $data, $default ); |
|
1271 |
} |
|
1272 |
||
1273 |
/** |
|
1274 |
* Register a selection of default headers to be displayed by the custom header admin UI. |
|
1275 |
* |
|
1276 |
* @since 3.0.0 |
|
1277 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1278 |
* @global array $_wp_default_headers |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1279 |
* |
0 | 1280 |
* @param array $headers Array of headers keyed by a string id. The ids point to arrays containing 'url', 'thumbnail_url', and 'description' keys. |
1281 |
*/ |
|
1282 |
function register_default_headers( $headers ) { |
|
1283 |
global $_wp_default_headers; |
|
1284 |
||
1285 |
$_wp_default_headers = array_merge( (array) $_wp_default_headers, (array) $headers ); |
|
1286 |
} |
|
1287 |
||
1288 |
/** |
|
1289 |
* Unregister default headers. |
|
1290 |
* |
|
1291 |
* This function must be called after register_default_headers() has already added the |
|
1292 |
* header you want to remove. |
|
1293 |
* |
|
1294 |
* @see register_default_headers() |
|
1295 |
* @since 3.0.0 |
|
1296 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1297 |
* @global array $_wp_default_headers |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1298 |
* |
0 | 1299 |
* @param string|array $header The header string id (key of array) to remove, or an array thereof. |
5 | 1300 |
* @return bool|void A single header returns true on success, false on failure. |
1301 |
* There is currently no return value for multiple headers. |
|
0 | 1302 |
*/ |
1303 |
function unregister_default_headers( $header ) { |
|
1304 |
global $_wp_default_headers; |
|
1305 |
if ( is_array( $header ) ) { |
|
1306 |
array_map( 'unregister_default_headers', $header ); |
|
1307 |
} elseif ( isset( $_wp_default_headers[ $header ] ) ) { |
|
1308 |
unset( $_wp_default_headers[ $header ] ); |
|
1309 |
return true; |
|
1310 |
} else { |
|
1311 |
return false; |
|
1312 |
} |
|
1313 |
} |
|
1314 |
||
1315 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1316 |
* Check whether a header video is set or not. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1317 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1318 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1319 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1320 |
* @see get_header_video_url() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1321 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1322 |
* @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
|
1323 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1324 |
function has_header_video() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1325 |
return (bool) get_header_video_url(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1326 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1327 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1328 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1329 |
* Retrieve header video URL for custom header. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1330 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1331 |
* 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
|
1332 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1333 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1334 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1335 |
* @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
|
1336 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1337 |
function get_header_video_url() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1338 |
$id = absint( get_theme_mod( 'header_video' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1339 |
$url = esc_url( get_theme_mod( 'external_header_video' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1340 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1341 |
if ( $id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1342 |
// Get the file URL from the attachment ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1343 |
$url = wp_get_attachment_url( $id ); |
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 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1346 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1347 |
* Filters the header video URL. |
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 |
* @since 4.7.3 |
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 |
* @param string $url Header video URL, if available. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1352 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1353 |
$url = apply_filters( 'get_header_video_url', $url ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1354 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1355 |
if ( ! $id && ! $url ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1356 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1357 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1358 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1359 |
return esc_url_raw( set_url_scheme( $url ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1360 |
} |
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 |
* Display header video URL. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1364 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1365 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1366 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1367 |
function the_header_video_url() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1368 |
$video = get_header_video_url(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1369 |
if ( $video ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1370 |
echo esc_url( $video ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1371 |
} |
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 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1375 |
* Retrieve header video settings. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1376 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1377 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1378 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1379 |
* @return array |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1380 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1381 |
function get_header_video_settings() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1382 |
$header = get_custom_header(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1383 |
$video_url = get_header_video_url(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1384 |
$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
|
1385 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1386 |
$settings = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1387 |
'mimeType' => '', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1388 |
'posterUrl' => get_header_image(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1389 |
'videoUrl' => $video_url, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1390 |
'width' => absint( $header->width ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1391 |
'height' => absint( $header->height ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1392 |
'minWidth' => 900, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1393 |
'minHeight' => 500, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1394 |
'l10n' => array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1395 |
'pause' => __( 'Pause' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1396 |
'play' => __( 'Play' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1397 |
'pauseSpeak' => __( 'Video is paused.'), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1398 |
'playSpeak' => __( 'Video is playing.'), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1399 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1400 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1401 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1402 |
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
|
1403 |
$settings['mimeType'] = 'video/x-youtube'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1404 |
} elseif ( ! empty( $video_type['type'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1405 |
$settings['mimeType'] = $video_type['type']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1406 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1407 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1408 |
return apply_filters( 'header_video_settings', $settings ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1409 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1410 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1411 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1412 |
* Check whether a custom header is set or not. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1413 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1414 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1415 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1416 |
* @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
|
1417 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1418 |
function has_custom_header() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1419 |
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
|
1420 |
return true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1421 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1422 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1423 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1424 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1425 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1426 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1427 |
* 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
|
1428 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1429 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1430 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1431 |
* @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
|
1432 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1433 |
function is_header_video_active() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1434 |
if ( ! get_theme_support( 'custom-header', 'video' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1435 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1436 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1437 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1438 |
$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
|
1439 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1440 |
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
|
1441 |
$show_video = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1442 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1443 |
$show_video = call_user_func( $video_active_cb ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1444 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1445 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1446 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1447 |
* Modify 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
|
1448 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1449 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1450 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1451 |
* @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
|
1452 |
* 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
|
1453 |
* 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
|
1454 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1455 |
return apply_filters( 'is_header_video_active', $show_video ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1456 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1457 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1458 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1459 |
* Retrieve the markup for a custom header. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1460 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1461 |
* 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
|
1462 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1463 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1464 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1465 |
* @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
|
1466 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1467 |
function get_custom_header_markup() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1468 |
if ( ! has_custom_header() && ! is_customize_preview() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1469 |
return ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1470 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1471 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1472 |
return sprintf( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1473 |
'<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
|
1474 |
get_header_image_tag() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1475 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1476 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1477 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1478 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1479 |
* Print the markup for a custom header. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1480 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1481 |
* 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
|
1482 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1483 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1484 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1485 |
function the_custom_header_markup() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1486 |
$custom_header = get_custom_header_markup(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1487 |
if ( empty( $custom_header ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1488 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1489 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1490 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1491 |
echo $custom_header; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1492 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1493 |
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
|
1494 |
wp_enqueue_script( 'wp-custom-header' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1495 |
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
|
1496 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1497 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1498 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1499 |
/** |
0 | 1500 |
* Retrieve background image for custom background. |
1501 |
* |
|
1502 |
* @since 3.0.0 |
|
1503 |
* |
|
1504 |
* @return string |
|
1505 |
*/ |
|
1506 |
function get_background_image() { |
|
1507 |
return get_theme_mod('background_image', get_theme_support( 'custom-background', 'default-image' ) ); |
|
1508 |
} |
|
1509 |
||
1510 |
/** |
|
1511 |
* Display background image path. |
|
1512 |
* |
|
1513 |
* @since 3.0.0 |
|
1514 |
*/ |
|
1515 |
function background_image() { |
|
1516 |
echo get_background_image(); |
|
1517 |
} |
|
1518 |
||
1519 |
/** |
|
1520 |
* Retrieve value for custom background color. |
|
1521 |
* |
|
1522 |
* @since 3.0.0 |
|
1523 |
* |
|
1524 |
* @return string |
|
1525 |
*/ |
|
1526 |
function get_background_color() { |
|
1527 |
return get_theme_mod('background_color', get_theme_support( 'custom-background', 'default-color' ) ); |
|
1528 |
} |
|
1529 |
||
1530 |
/** |
|
1531 |
* Display background color value. |
|
1532 |
* |
|
1533 |
* @since 3.0.0 |
|
1534 |
*/ |
|
1535 |
function background_color() { |
|
1536 |
echo get_background_color(); |
|
1537 |
} |
|
1538 |
||
1539 |
/** |
|
1540 |
* Default custom background callback. |
|
1541 |
* |
|
1542 |
* @since 3.0.0 |
|
1543 |
*/ |
|
1544 |
function _custom_background_cb() { |
|
1545 |
// $background is the saved custom image, or the default image. |
|
1546 |
$background = set_url_scheme( get_background_image() ); |
|
1547 |
||
1548 |
// $color is the saved custom color. |
|
1549 |
// A default has to be specified in style.css. It will not be printed here. |
|
5 | 1550 |
$color = get_background_color(); |
1551 |
||
1552 |
if ( $color === get_theme_support( 'custom-background', 'default-color' ) ) { |
|
1553 |
$color = false; |
|
1554 |
} |
|
0 | 1555 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1556 |
if ( ! $background && ! $color ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1557 |
if ( is_customize_preview() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1558 |
echo '<style type="text/css" id="custom-background-css"></style>'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1559 |
} |
0 | 1560 |
return; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1561 |
} |
0 | 1562 |
|
1563 |
$style = $color ? "background-color: #$color;" : ''; |
|
1564 |
||
1565 |
if ( $background ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1566 |
$image = ' background-image: url("' . esc_url_raw( $background ) . '");'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1567 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1568 |
// Background Position. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1569 |
$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
|
1570 |
$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
|
1571 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1572 |
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
|
1573 |
$position_x = 'left'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1574 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1575 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1576 |
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
|
1577 |
$position_y = 'top'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1578 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1579 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1580 |
$position = " background-position: $position_x $position_y;"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1581 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1582 |
// Background Size. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1583 |
$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
|
1584 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1585 |
if ( ! in_array( $size, array( 'auto', 'contain', 'cover' ), true ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1586 |
$size = 'auto'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1587 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1588 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1589 |
$size = " background-size: $size;"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1590 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1591 |
// Background Repeat. |
5 | 1592 |
$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
|
1593 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1594 |
if ( ! in_array( $repeat, array( 'repeat-x', 'repeat-y', 'repeat', 'no-repeat' ), true ) ) { |
0 | 1595 |
$repeat = 'repeat'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1596 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1597 |
|
0 | 1598 |
$repeat = " background-repeat: $repeat;"; |
1599 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1600 |
// Background Scroll. |
5 | 1601 |
$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
|
1602 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1603 |
if ( 'fixed' !== $attachment ) { |
0 | 1604 |
$attachment = 'scroll'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1605 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1606 |
|
0 | 1607 |
$attachment = " background-attachment: $attachment;"; |
1608 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1609 |
$style .= $image . $position . $size . $repeat . $attachment; |
0 | 1610 |
} |
1611 |
?> |
|
1612 |
<style type="text/css" id="custom-background-css"> |
|
1613 |
body.custom-background { <?php echo trim( $style ); ?> } |
|
1614 |
</style> |
|
1615 |
<?php |
|
1616 |
} |
|
1617 |
||
1618 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1619 |
* Render the Custom CSS style element. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1620 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1621 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1622 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1623 |
function wp_custom_css_cb() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1624 |
$styles = wp_get_custom_css(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1625 |
if ( $styles || is_customize_preview() ) : ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1626 |
<style type="text/css" id="wp-custom-css"> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1627 |
<?php echo strip_tags( $styles ); // Note that esc_html() cannot be used because `div > span` is not interpreted properly. ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1628 |
</style> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1629 |
<?php endif; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1630 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1631 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1632 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1633 |
* Fetch the `custom_css` post for a given theme. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1634 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1635 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1636 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1637 |
* @param string $stylesheet Optional. A theme object stylesheet name. Defaults to the current theme. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1638 |
* @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
|
1639 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1640 |
function wp_get_custom_css_post( $stylesheet = '' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1641 |
if ( empty( $stylesheet ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1642 |
$stylesheet = get_stylesheet(); |
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 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1645 |
$custom_css_query_vars = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1646 |
'post_type' => 'custom_css', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1647 |
'post_status' => get_post_stati(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1648 |
'name' => sanitize_title( $stylesheet ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1649 |
'posts_per_page' => 1, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1650 |
'no_found_rows' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1651 |
'cache_results' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1652 |
'update_post_meta_cache' => false, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1653 |
'update_post_term_cache' => false, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1654 |
'lazy_load_term_meta' => false, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1655 |
); |
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 |
$post = null; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1658 |
if ( get_stylesheet() === $stylesheet ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1659 |
$post_id = get_theme_mod( 'custom_css_post_id' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1660 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1661 |
if ( $post_id > 0 && get_post( $post_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1662 |
$post = get_post( $post_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1663 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1664 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1665 |
// `-1` indicates no post exists; no query necessary. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1666 |
if ( ! $post && -1 !== $post_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1667 |
$query = new WP_Query( $custom_css_query_vars ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1668 |
$post = $query->post; |
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 |
* Cache the lookup. See wp_update_custom_css_post(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1671 |
* @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
|
1672 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1673 |
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
|
1674 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1675 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1676 |
$query = new WP_Query( $custom_css_query_vars ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1677 |
$post = $query->post; |
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 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1680 |
return $post; |
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 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1684 |
* Fetch the saved Custom CSS content for rendering. |
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 |
* @param string $stylesheet Optional. A theme object stylesheet name. Defaults to the current theme. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1689 |
* @return string The Custom CSS Post content. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1690 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1691 |
function wp_get_custom_css( $stylesheet = '' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1692 |
$css = ''; |
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 |
if ( empty( $stylesheet ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1695 |
$stylesheet = get_stylesheet(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1696 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1697 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1698 |
$post = wp_get_custom_css_post( $stylesheet ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1699 |
if ( $post ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1700 |
$css = $post->post_content; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1701 |
} |
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 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1704 |
* Filters the Custom CSS Output into the <head>. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1705 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1706 |
* @since 4.7.0 |
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 |
* @param string $css CSS pulled in from the Custom CSS CPT. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1709 |
* @param string $stylesheet The theme stylesheet name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1710 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1711 |
$css = apply_filters( 'wp_get_custom_css', $css, $stylesheet ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1712 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1713 |
return $css; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1714 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1715 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1716 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1717 |
* Update the `custom_css` post for a given theme. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1718 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1719 |
* 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
|
1720 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1721 |
* @since 4.7.0 |
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 |
* @param string $css CSS, stored in `post_content`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1724 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1725 |
* Args. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1726 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1727 |
* @type string $preprocessed Pre-processed CSS, stored in `post_content_filtered`. Normally empty string. Optional. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1728 |
* @type string $stylesheet Stylesheet (child theme) to update. Optional, defaults to current theme/stylesheet. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1729 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1730 |
* @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
|
1731 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1732 |
function wp_update_custom_css_post( $css, $args = array() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1733 |
$args = wp_parse_args( $args, array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1734 |
'preprocessed' => '', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1735 |
'stylesheet' => get_stylesheet(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1736 |
) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1737 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1738 |
$data = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1739 |
'css' => $css, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1740 |
'preprocessed' => $args['preprocessed'], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1741 |
); |
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 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1744 |
* Filters the `css` (`post_content`) and `preprocessed` (`post_content_filtered`) args for a `custom_css` post being updated. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1745 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1746 |
* 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
|
1747 |
* 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
|
1748 |
* 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
|
1749 |
* 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
|
1750 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1751 |
* <code> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1752 |
* add_filter( 'customize_value_custom_css', function( $value, $setting ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1753 |
* $post = wp_get_custom_css_post( $setting->stylesheet ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1754 |
* if ( $post && ! empty( $post->post_content_filtered ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1755 |
* $css = $post->post_content_filtered; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1756 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1757 |
* return $css; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1758 |
* }, 10, 2 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1759 |
* </code> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1760 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1761 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1762 |
* @param array $data { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1763 |
* Custom CSS data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1764 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1765 |
* @type string $css CSS stored in `post_content`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1766 |
* @type string $preprocessed Pre-processed CSS stored in `post_content_filtered`. Normally empty string. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1767 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1768 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1769 |
* 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
|
1770 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1771 |
* @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
|
1772 |
* @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
|
1773 |
* @type string $stylesheet The stylesheet (theme) being updated. |
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 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1776 |
$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
|
1777 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1778 |
$post_data = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1779 |
'post_title' => $args['stylesheet'], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1780 |
'post_name' => sanitize_title( $args['stylesheet'] ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1781 |
'post_type' => 'custom_css', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1782 |
'post_status' => 'publish', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1783 |
'post_content' => $data['css'], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1784 |
'post_content_filtered' => $data['preprocessed'], |
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 |
// 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
|
1788 |
$post = wp_get_custom_css_post( $args['stylesheet'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1789 |
if ( $post ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1790 |
$post_data['ID'] = $post->ID; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1791 |
$r = wp_update_post( wp_slash( $post_data ), true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1792 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1793 |
$r = wp_insert_post( wp_slash( $post_data ), true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1794 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1795 |
if ( ! is_wp_error( $r ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1796 |
if ( get_stylesheet() === $args['stylesheet'] ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1797 |
set_theme_mod( 'custom_css_post_id', $r ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1798 |
} |
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 |
// Trigger creation of a revision. This should be removed once #30854 is resolved. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1801 |
if ( 0 === count( wp_get_post_revisions( $r ) ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1802 |
wp_save_post_revision( $r ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1803 |
} |
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 |
if ( is_wp_error( $r ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1808 |
return $r; |
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 |
return get_post( $r ); |
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 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1813 |
/** |
0 | 1814 |
* Add callback for custom TinyMCE editor stylesheets. |
1815 |
* |
|
1816 |
* The parameter $stylesheet is the name of the stylesheet, relative to |
|
1817 |
* the theme root. It also accepts an array of stylesheets. |
|
1818 |
* It is optional and defaults to 'editor-style.css'. |
|
1819 |
* |
|
1820 |
* This function automatically adds another stylesheet with -rtl prefix, e.g. editor-style-rtl.css. |
|
1821 |
* If that file doesn't exist, it is removed before adding the stylesheet(s) to TinyMCE. |
|
1822 |
* If an array of stylesheets is passed to add_editor_style(), |
|
1823 |
* RTL is only added for the first stylesheet. |
|
1824 |
* |
|
1825 |
* Since version 3.4 the TinyMCE body has .rtl CSS class. |
|
1826 |
* It is a better option to use that class and add any RTL styles to the main stylesheet. |
|
1827 |
* |
|
1828 |
* @since 3.0.0 |
|
1829 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1830 |
* @global array $editor_styles |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1831 |
* |
5 | 1832 |
* @param array|string $stylesheet Optional. Stylesheet name or array thereof, relative to theme root. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1833 |
* Defaults to 'editor-style.css' |
0 | 1834 |
*/ |
1835 |
function add_editor_style( $stylesheet = 'editor-style.css' ) { |
|
1836 |
add_theme_support( 'editor-style' ); |
|
1837 |
||
1838 |
if ( ! is_admin() ) |
|
1839 |
return; |
|
1840 |
||
1841 |
global $editor_styles; |
|
1842 |
$editor_styles = (array) $editor_styles; |
|
1843 |
$stylesheet = (array) $stylesheet; |
|
1844 |
if ( is_rtl() ) { |
|
1845 |
$rtl_stylesheet = str_replace('.css', '-rtl.css', $stylesheet[0]); |
|
1846 |
$stylesheet[] = $rtl_stylesheet; |
|
1847 |
} |
|
1848 |
||
1849 |
$editor_styles = array_merge( $editor_styles, $stylesheet ); |
|
1850 |
} |
|
1851 |
||
1852 |
/** |
|
1853 |
* Removes all visual editor stylesheets. |
|
1854 |
* |
|
1855 |
* @since 3.1.0 |
|
1856 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1857 |
* @global array $editor_styles |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1858 |
* |
0 | 1859 |
* @return bool True on success, false if there were no stylesheets to remove. |
1860 |
*/ |
|
1861 |
function remove_editor_styles() { |
|
1862 |
if ( ! current_theme_supports( 'editor-style' ) ) |
|
1863 |
return false; |
|
1864 |
_remove_theme_support( 'editor-style' ); |
|
1865 |
if ( is_admin() ) |
|
1866 |
$GLOBALS['editor_styles'] = array(); |
|
1867 |
return true; |
|
1868 |
} |
|
1869 |
||
1870 |
/** |
|
5 | 1871 |
* Retrieve any registered editor stylesheets |
1872 |
* |
|
1873 |
* @since 4.0.0 |
|
1874 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1875 |
* @global array $editor_styles Registered editor stylesheets |
5 | 1876 |
* |
1877 |
* @return array If registered, a list of editor stylesheet URLs. |
|
1878 |
*/ |
|
1879 |
function get_editor_stylesheets() { |
|
1880 |
$stylesheets = array(); |
|
1881 |
// load editor_style.css if the current theme supports it |
|
1882 |
if ( ! empty( $GLOBALS['editor_styles'] ) && is_array( $GLOBALS['editor_styles'] ) ) { |
|
1883 |
$editor_styles = $GLOBALS['editor_styles']; |
|
1884 |
||
1885 |
$editor_styles = array_unique( array_filter( $editor_styles ) ); |
|
1886 |
$style_uri = get_stylesheet_directory_uri(); |
|
1887 |
$style_dir = get_stylesheet_directory(); |
|
1888 |
||
1889 |
// Support externally referenced styles (like, say, fonts). |
|
1890 |
foreach ( $editor_styles as $key => $file ) { |
|
1891 |
if ( preg_match( '~^(https?:)?//~', $file ) ) { |
|
1892 |
$stylesheets[] = esc_url_raw( $file ); |
|
1893 |
unset( $editor_styles[ $key ] ); |
|
1894 |
} |
|
1895 |
} |
|
1896 |
||
1897 |
// Look in a parent theme first, that way child theme CSS overrides. |
|
1898 |
if ( is_child_theme() ) { |
|
1899 |
$template_uri = get_template_directory_uri(); |
|
1900 |
$template_dir = get_template_directory(); |
|
1901 |
||
1902 |
foreach ( $editor_styles as $key => $file ) { |
|
1903 |
if ( $file && file_exists( "$template_dir/$file" ) ) { |
|
1904 |
$stylesheets[] = "$template_uri/$file"; |
|
1905 |
} |
|
1906 |
} |
|
1907 |
} |
|
1908 |
||
1909 |
foreach ( $editor_styles as $file ) { |
|
1910 |
if ( $file && file_exists( "$style_dir/$file" ) ) { |
|
1911 |
$stylesheets[] = "$style_uri/$file"; |
|
1912 |
} |
|
1913 |
} |
|
1914 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1915 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1916 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1917 |
* Filters the array of stylesheets applied to the editor. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1918 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1919 |
* @since 4.3.0 |
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 |
* @param array $stylesheets Array of stylesheets to be applied to the editor. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1922 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1923 |
return apply_filters( 'editor_stylesheets', $stylesheets ); |
5 | 1924 |
} |
1925 |
||
1926 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1927 |
* Expand a theme's starter content configuration using core-provided data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1928 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1929 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1930 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1931 |
* @return array Array of starter content. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1932 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1933 |
function get_theme_starter_content() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1934 |
$theme_support = get_theme_support( 'starter-content' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1935 |
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
|
1936 |
$config = $theme_support[0]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1937 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1938 |
$config = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1939 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1940 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1941 |
$core_content = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1942 |
'widgets' => array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1943 |
'text_business_info' => array( 'text', array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1944 |
'title' => _x( 'Find Us', 'Theme starter content' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1945 |
'text' => join( '', array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1946 |
'<strong>' . _x( 'Address', 'Theme starter content' ) . "</strong>\n", |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1947 |
_x( '123 Main Street', 'Theme starter content' ) . "\n" . _x( 'New York, NY 10001', 'Theme starter content' ) . "\n\n", |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1948 |
'<strong>' . _x( 'Hours', 'Theme starter content' ) . "</strong>\n", |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1949 |
_x( 'Monday—Friday: 9:00AM–5:00PM', 'Theme starter content' ) . "\n" . _x( 'Saturday & Sunday: 11:00AM–3:00PM', 'Theme starter content' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1950 |
) ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1951 |
'filter' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1952 |
'visual' => true, |
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 |
'text_about' => array( 'text', array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1955 |
'title' => _x( 'About This Site', 'Theme starter content' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1956 |
'text' => _x( 'This may be a good place to introduce yourself and your site or include some credits.', 'Theme starter content' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1957 |
'filter' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1958 |
'visual' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1959 |
) ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1960 |
'archives' => array( 'archives', array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1961 |
'title' => _x( 'Archives', 'Theme starter content' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1962 |
) ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1963 |
'calendar' => array( 'calendar', array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1964 |
'title' => _x( 'Calendar', 'Theme starter content' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1965 |
) ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1966 |
'categories' => array( 'categories', array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1967 |
'title' => _x( 'Categories', 'Theme starter content' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1968 |
) ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1969 |
'meta' => array( 'meta', array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1970 |
'title' => _x( 'Meta', 'Theme starter content' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1971 |
) ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1972 |
'recent-comments' => array( 'recent-comments', array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1973 |
'title' => _x( 'Recent Comments', 'Theme starter content' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1974 |
) ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1975 |
'recent-posts' => array( 'recent-posts', array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1976 |
'title' => _x( 'Recent Posts', 'Theme starter content' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1977 |
) ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1978 |
'search' => array( 'search', array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1979 |
'title' => _x( 'Search', 'Theme starter content' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1980 |
) ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1981 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1982 |
'nav_menus' => array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1983 |
'link_home' => array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1984 |
'type' => 'custom', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1985 |
'title' => _x( 'Home', 'Theme starter content' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1986 |
'url' => home_url( '/' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1987 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1988 |
'page_home' => array( // Deprecated in favor of link_home. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1989 |
'type' => 'post_type', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1990 |
'object' => 'page', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1991 |
'object_id' => '{{home}}', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1992 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1993 |
'page_about' => array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1994 |
'type' => 'post_type', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1995 |
'object' => 'page', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1996 |
'object_id' => '{{about}}', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1997 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1998 |
'page_blog' => array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1999 |
'type' => 'post_type', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2000 |
'object' => 'page', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2001 |
'object_id' => '{{blog}}', |
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 |
'page_news' => array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2004 |
'type' => 'post_type', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2005 |
'object' => 'page', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2006 |
'object_id' => '{{news}}', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2007 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2008 |
'page_contact' => array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2009 |
'type' => 'post_type', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2010 |
'object' => 'page', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2011 |
'object_id' => '{{contact}}', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2012 |
), |
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 |
'link_email' => array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2015 |
'title' => _x( 'Email', 'Theme starter content' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2016 |
'url' => 'mailto:wordpress@example.com', |
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 |
'link_facebook' => array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2019 |
'title' => _x( 'Facebook', 'Theme starter content' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2020 |
'url' => 'https://www.facebook.com/wordpress', |
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 |
'link_foursquare' => array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2023 |
'title' => _x( 'Foursquare', 'Theme starter content' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2024 |
'url' => 'https://foursquare.com/', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2025 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2026 |
'link_github' => array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2027 |
'title' => _x( 'GitHub', 'Theme starter content' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2028 |
'url' => 'https://github.com/wordpress/', |
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 |
'link_instagram' => array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2031 |
'title' => _x( 'Instagram', 'Theme starter content' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2032 |
'url' => 'https://www.instagram.com/explore/tags/wordcamp/', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2033 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2034 |
'link_linkedin' => array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2035 |
'title' => _x( 'LinkedIn', 'Theme starter content' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2036 |
'url' => 'https://www.linkedin.com/company/1089783', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2037 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2038 |
'link_pinterest' => array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2039 |
'title' => _x( 'Pinterest', 'Theme starter content' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2040 |
'url' => 'https://www.pinterest.com/', |
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 |
'link_twitter' => array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2043 |
'title' => _x( 'Twitter', 'Theme starter content' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2044 |
'url' => 'https://twitter.com/wordpress', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2045 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2046 |
'link_yelp' => array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2047 |
'title' => _x( 'Yelp', 'Theme starter content' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2048 |
'url' => 'https://www.yelp.com', |
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 |
'link_youtube' => array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2051 |
'title' => _x( 'YouTube', 'Theme starter content' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2052 |
'url' => 'https://www.youtube.com/channel/UCdof4Ju7amm1chz1gi1T2ZA', |
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 |
'posts' => array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2056 |
'home' => array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2057 |
'post_type' => 'page', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2058 |
'post_title' => _x( 'Home', 'Theme starter content' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2059 |
'post_content' => _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' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2060 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2061 |
'about' => array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2062 |
'post_type' => 'page', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2063 |
'post_title' => _x( 'About', 'Theme starter content' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2064 |
'post_content' => _x( 'You might be an artist who would like to introduce yourself and your work here or maybe you’re a business with a mission to describe.', 'Theme starter content' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2065 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2066 |
'contact' => array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2067 |
'post_type' => 'page', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2068 |
'post_title' => _x( 'Contact', 'Theme starter content' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2069 |
'post_content' => _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' ), |
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 |
'blog' => array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2072 |
'post_type' => 'page', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2073 |
'post_title' => _x( 'Blog', 'Theme starter content' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2074 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2075 |
'news' => array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2076 |
'post_type' => 'page', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2077 |
'post_title' => _x( 'News', 'Theme starter content' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2078 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2079 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2080 |
'homepage-section' => array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2081 |
'post_type' => 'page', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2082 |
'post_title' => _x( 'A homepage section', 'Theme starter content' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2083 |
'post_content' => _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' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2084 |
), |
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 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2088 |
$content = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2089 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2090 |
foreach ( $config as $type => $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2091 |
switch( $type ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2092 |
// Use options and theme_mods as-is. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2093 |
case 'options' : |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2094 |
case 'theme_mods' : |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2095 |
$content[ $type ] = $config[ $type ]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2096 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2097 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2098 |
// Widgets are grouped into sidebars. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2099 |
case 'widgets' : |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2100 |
foreach ( $config[ $type ] as $sidebar_id => $widgets ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2101 |
foreach ( $widgets as $id => $widget ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2102 |
if ( is_array( $widget ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2103 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2104 |
// Item extends core content. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2105 |
if ( ! empty( $core_content[ $type ][ $id ] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2106 |
$widget = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2107 |
$core_content[ $type ][ $id ][0], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2108 |
array_merge( $core_content[ $type ][ $id ][1], $widget ), |
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 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2111 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2112 |
$content[ $type ][ $sidebar_id ][] = $widget; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2113 |
} elseif ( is_string( $widget ) && ! empty( $core_content[ $type ] ) && ! empty( $core_content[ $type ][ $widget ] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2114 |
$content[ $type ][ $sidebar_id ][] = $core_content[ $type ][ $widget ]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2115 |
} |
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 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2118 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2119 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2120 |
// And nav menu items are grouped into nav menus. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2121 |
case 'nav_menus' : |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2122 |
foreach ( $config[ $type ] as $nav_menu_location => $nav_menu ) { |
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 |
// Ensure nav menus get a name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2125 |
if ( empty( $nav_menu['name'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2126 |
$nav_menu['name'] = $nav_menu_location; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2127 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2128 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2129 |
$content[ $type ][ $nav_menu_location ]['name'] = $nav_menu['name']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2130 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2131 |
foreach ( $nav_menu['items'] as $id => $nav_menu_item ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2132 |
if ( is_array( $nav_menu_item ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2133 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2134 |
// Item extends core content. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2135 |
if ( ! empty( $core_content[ $type ][ $id ] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2136 |
$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
|
2137 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2138 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2139 |
$content[ $type ][ $nav_menu_location ]['items'][] = $nav_menu_item; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2140 |
} elseif ( is_string( $nav_menu_item ) && ! empty( $core_content[ $type ] ) && ! empty( $core_content[ $type ][ $nav_menu_item ] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2141 |
$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
|
2142 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2143 |
} |
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 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2146 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2147 |
// Attachments are posts but have special treatment. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2148 |
case 'attachments' : |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2149 |
foreach ( $config[ $type ] as $id => $item ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2150 |
if ( ! empty( $item['file'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2151 |
$content[ $type ][ $id ] = $item; |
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 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2155 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2156 |
// All that's left now are posts (besides attachments). Not a default case for the sake of clarity and future work. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2157 |
case 'posts' : |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2158 |
foreach ( $config[ $type ] as $id => $item ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2159 |
if ( is_array( $item ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2160 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2161 |
// Item extends core content. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2162 |
if ( ! empty( $core_content[ $type ][ $id ] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2163 |
$item = array_merge( $core_content[ $type ][ $id ], $item ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2164 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2165 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2166 |
// Enforce a subset of fields. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2167 |
$content[ $type ][ $id ] = wp_array_slice_assoc( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2168 |
$item, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2169 |
array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2170 |
'post_type', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2171 |
'post_title', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2172 |
'post_excerpt', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2173 |
'post_name', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2174 |
'post_content', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2175 |
'menu_order', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2176 |
'comment_status', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2177 |
'thumbnail', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2178 |
'template', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2179 |
) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2180 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2181 |
} elseif ( is_string( $item ) && ! empty( $core_content[ $type ][ $item ] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2182 |
$content[ $type ][ $item ] = $core_content[ $type ][ $item ]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2183 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2184 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2185 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2186 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2187 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2188 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2189 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2190 |
* Filters the expanded array of starter content. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2191 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2192 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2193 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2194 |
* @param array $content Array of starter content. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2195 |
* @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
|
2196 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2197 |
return apply_filters( 'get_theme_starter_content', $content, $config ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2198 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2199 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2200 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2201 |
* Registers theme support for a given feature. |
0 | 2202 |
* |
2203 |
* 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
|
2204 |
* 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
|
2205 |
* The {@see 'init'} hook may be too late for some features. |
0 | 2206 |
* |
2207 |
* @since 2.9.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2208 |
* @since 3.6.0 The `html5` feature was added |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2209 |
* @since 3.9.0 The `html5` feature now also accepts 'gallery' and 'caption' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2210 |
* @since 4.1.0 The `title-tag` feature was added |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2211 |
* @since 4.5.0 The `customize-selective-refresh-widgets` feature was added |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2212 |
* @since 4.7.0 The `starter-content` feature was added |
5 | 2213 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2214 |
* @global array $_wp_theme_features |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2215 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2216 |
* @param string $feature The feature being added. Likely core values include 'post-formats', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2217 |
* 'post-thumbnails', 'html5', 'custom-logo', 'custom-header-uploads', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2218 |
* 'custom-header', 'custom-background', 'title-tag', 'starter-content', etc. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2219 |
* @param mixed $args,... Optional extra arguments to pass along with certain features. |
5 | 2220 |
* @return void|bool False on failure, void otherwise. |
0 | 2221 |
*/ |
2222 |
function add_theme_support( $feature ) { |
|
2223 |
global $_wp_theme_features; |
|
2224 |
||
2225 |
if ( func_num_args() == 1 ) |
|
2226 |
$args = true; |
|
2227 |
else |
|
2228 |
$args = array_slice( func_get_args(), 1 ); |
|
2229 |
||
2230 |
switch ( $feature ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2231 |
case 'post-thumbnails': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2232 |
// All post types are already supported. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2233 |
if ( true === get_theme_support( 'post-thumbnails' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2234 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2235 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2236 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2237 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2238 |
* 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
|
2239 |
* for post thumbnails. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2240 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2241 |
if ( is_array( $args[0] ) && isset( $_wp_theme_features['post-thumbnails'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2242 |
$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
|
2243 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2244 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2245 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2246 |
|
0 | 2247 |
case 'post-formats' : |
5 | 2248 |
if ( is_array( $args[0] ) ) { |
2249 |
$post_formats = get_post_format_slugs(); |
|
2250 |
unset( $post_formats['standard'] ); |
|
2251 |
||
2252 |
$args[0] = array_intersect( $args[0], array_keys( $post_formats ) ); |
|
2253 |
} |
|
0 | 2254 |
break; |
2255 |
||
2256 |
case 'html5' : |
|
2257 |
// You can't just pass 'html5', you need to pass an array of types. |
|
2258 |
if ( empty( $args[0] ) ) { |
|
5 | 2259 |
// Build an array of types for back-compat. |
0 | 2260 |
$args = array( 0 => array( 'comment-list', 'comment-form', 'search-form' ) ); |
2261 |
} elseif ( ! is_array( $args[0] ) ) { |
|
5 | 2262 |
_doing_it_wrong( "add_theme_support( 'html5' )", __( 'You need to pass an array of types.' ), '3.6.1' ); |
0 | 2263 |
return false; |
2264 |
} |
|
2265 |
||
2266 |
// Calling 'html5' again merges, rather than overwrites. |
|
2267 |
if ( isset( $_wp_theme_features['html5'] ) ) |
|
2268 |
$args[0] = array_merge( $_wp_theme_features['html5'][0], $args[0] ); |
|
2269 |
break; |
|
2270 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2271 |
case 'custom-logo': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2272 |
if ( ! is_array( $args ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2273 |
$args = array( 0 => array() ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2274 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2275 |
$defaults = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2276 |
'width' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2277 |
'height' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2278 |
'flex-width' => false, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2279 |
'flex-height' => false, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2280 |
'header-text' => '', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2281 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2282 |
$args[0] = wp_parse_args( array_intersect_key( $args[0], $defaults ), $defaults ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2283 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2284 |
// Allow full flexibility if no size is specified. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2285 |
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
|
2286 |
$args[0]['flex-width'] = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2287 |
$args[0]['flex-height'] = true; |
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 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2290 |
|
0 | 2291 |
case 'custom-header-uploads' : |
2292 |
return add_theme_support( 'custom-header', array( 'uploads' => true ) ); |
|
2293 |
||
2294 |
case 'custom-header' : |
|
2295 |
if ( ! is_array( $args ) ) |
|
2296 |
$args = array( 0 => array() ); |
|
2297 |
||
2298 |
$defaults = array( |
|
2299 |
'default-image' => '', |
|
2300 |
'random-default' => false, |
|
2301 |
'width' => 0, |
|
2302 |
'height' => 0, |
|
2303 |
'flex-height' => false, |
|
2304 |
'flex-width' => false, |
|
2305 |
'default-text-color' => '', |
|
2306 |
'header-text' => true, |
|
2307 |
'uploads' => true, |
|
2308 |
'wp-head-callback' => '', |
|
2309 |
'admin-head-callback' => '', |
|
2310 |
'admin-preview-callback' => '', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2311 |
'video' => false, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2312 |
'video-active-callback' => 'is_front_page', |
0 | 2313 |
); |
2314 |
||
2315 |
$jit = isset( $args[0]['__jit'] ); |
|
2316 |
unset( $args[0]['__jit'] ); |
|
2317 |
||
2318 |
// Merge in data from previous add_theme_support() calls. |
|
2319 |
// The first value registered wins. (A child theme is set up first.) |
|
2320 |
if ( isset( $_wp_theme_features['custom-header'] ) ) |
|
2321 |
$args[0] = wp_parse_args( $_wp_theme_features['custom-header'][0], $args[0] ); |
|
2322 |
||
2323 |
// Load in the defaults at the end, as we need to insure first one wins. |
|
2324 |
// This will cause all constants to be defined, as each arg will then be set to the default. |
|
2325 |
if ( $jit ) |
|
2326 |
$args[0] = wp_parse_args( $args[0], $defaults ); |
|
2327 |
||
2328 |
// If a constant was defined, use that value. Otherwise, define the constant to ensure |
|
2329 |
// the constant is always accurate (and is not defined later, overriding our value). |
|
2330 |
// As stated above, the first value wins. |
|
2331 |
// Once we get to wp_loaded (just-in-time), define any constants we haven't already. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2332 |
// Constants are lame. Don't reference them. This is just for backward compatibility. |
0 | 2333 |
|
2334 |
if ( defined( 'NO_HEADER_TEXT' ) ) |
|
2335 |
$args[0]['header-text'] = ! NO_HEADER_TEXT; |
|
2336 |
elseif ( isset( $args[0]['header-text'] ) ) |
|
2337 |
define( 'NO_HEADER_TEXT', empty( $args[0]['header-text'] ) ); |
|
2338 |
||
2339 |
if ( defined( 'HEADER_IMAGE_WIDTH' ) ) |
|
2340 |
$args[0]['width'] = (int) HEADER_IMAGE_WIDTH; |
|
2341 |
elseif ( isset( $args[0]['width'] ) ) |
|
2342 |
define( 'HEADER_IMAGE_WIDTH', (int) $args[0]['width'] ); |
|
2343 |
||
2344 |
if ( defined( 'HEADER_IMAGE_HEIGHT' ) ) |
|
2345 |
$args[0]['height'] = (int) HEADER_IMAGE_HEIGHT; |
|
2346 |
elseif ( isset( $args[0]['height'] ) ) |
|
2347 |
define( 'HEADER_IMAGE_HEIGHT', (int) $args[0]['height'] ); |
|
2348 |
||
2349 |
if ( defined( 'HEADER_TEXTCOLOR' ) ) |
|
2350 |
$args[0]['default-text-color'] = HEADER_TEXTCOLOR; |
|
2351 |
elseif ( isset( $args[0]['default-text-color'] ) ) |
|
2352 |
define( 'HEADER_TEXTCOLOR', $args[0]['default-text-color'] ); |
|
2353 |
||
2354 |
if ( defined( 'HEADER_IMAGE' ) ) |
|
2355 |
$args[0]['default-image'] = HEADER_IMAGE; |
|
2356 |
elseif ( isset( $args[0]['default-image'] ) ) |
|
2357 |
define( 'HEADER_IMAGE', $args[0]['default-image'] ); |
|
2358 |
||
2359 |
if ( $jit && ! empty( $args[0]['default-image'] ) ) |
|
2360 |
$args[0]['random-default'] = false; |
|
2361 |
||
2362 |
// If headers are supported, and we still don't have a defined width or height, |
|
2363 |
// we have implicit flex sizes. |
|
2364 |
if ( $jit ) { |
|
2365 |
if ( empty( $args[0]['width'] ) && empty( $args[0]['flex-width'] ) ) |
|
2366 |
$args[0]['flex-width'] = true; |
|
2367 |
if ( empty( $args[0]['height'] ) && empty( $args[0]['flex-height'] ) ) |
|
2368 |
$args[0]['flex-height'] = true; |
|
2369 |
} |
|
2370 |
||
2371 |
break; |
|
2372 |
||
2373 |
case 'custom-background' : |
|
2374 |
if ( ! is_array( $args ) ) |
|
2375 |
$args = array( 0 => array() ); |
|
2376 |
||
2377 |
$defaults = array( |
|
5 | 2378 |
'default-image' => '', |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2379 |
'default-preset' => 'default', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2380 |
'default-position-x' => 'left', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2381 |
'default-position-y' => 'top', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2382 |
'default-size' => 'auto', |
5 | 2383 |
'default-repeat' => 'repeat', |
2384 |
'default-attachment' => 'scroll', |
|
2385 |
'default-color' => '', |
|
2386 |
'wp-head-callback' => '_custom_background_cb', |
|
2387 |
'admin-head-callback' => '', |
|
0 | 2388 |
'admin-preview-callback' => '', |
2389 |
); |
|
2390 |
||
2391 |
$jit = isset( $args[0]['__jit'] ); |
|
2392 |
unset( $args[0]['__jit'] ); |
|
2393 |
||
2394 |
// Merge in data from previous add_theme_support() calls. The first value registered wins. |
|
2395 |
if ( isset( $_wp_theme_features['custom-background'] ) ) |
|
2396 |
$args[0] = wp_parse_args( $_wp_theme_features['custom-background'][0], $args[0] ); |
|
2397 |
||
2398 |
if ( $jit ) |
|
2399 |
$args[0] = wp_parse_args( $args[0], $defaults ); |
|
2400 |
||
2401 |
if ( defined( 'BACKGROUND_COLOR' ) ) |
|
2402 |
$args[0]['default-color'] = BACKGROUND_COLOR; |
|
2403 |
elseif ( isset( $args[0]['default-color'] ) || $jit ) |
|
2404 |
define( 'BACKGROUND_COLOR', $args[0]['default-color'] ); |
|
2405 |
||
2406 |
if ( defined( 'BACKGROUND_IMAGE' ) ) |
|
2407 |
$args[0]['default-image'] = BACKGROUND_IMAGE; |
|
2408 |
elseif ( isset( $args[0]['default-image'] ) || $jit ) |
|
2409 |
define( 'BACKGROUND_IMAGE', $args[0]['default-image'] ); |
|
2410 |
||
2411 |
break; |
|
5 | 2412 |
|
2413 |
// Ensure that 'title-tag' is accessible in the admin. |
|
2414 |
case 'title-tag' : |
|
2415 |
// Can be called in functions.php but must happen before wp_loaded, i.e. not in header.php. |
|
2416 |
if ( did_action( 'wp_loaded' ) ) { |
|
2417 |
/* translators: 1: Theme support 2: hook name */ |
|
2418 |
_doing_it_wrong( "add_theme_support( 'title-tag' )", sprintf( __( 'Theme support for %1$s should be registered before the %2$s hook.' ), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2419 |
'<code>title-tag</code>', '<code>wp_loaded</code>' ), '4.1.0' ); |
5 | 2420 |
|
2421 |
return false; |
|
2422 |
} |
|
0 | 2423 |
} |
2424 |
||
2425 |
$_wp_theme_features[ $feature ] = $args; |
|
2426 |
} |
|
2427 |
||
2428 |
/** |
|
2429 |
* Registers the internal custom header and background routines. |
|
2430 |
* |
|
2431 |
* @since 3.4.0 |
|
2432 |
* @access private |
|
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 |
* @global Custom_Image_Header $custom_image_header |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2435 |
* @global Custom_Background $custom_background |
0 | 2436 |
*/ |
2437 |
function _custom_header_background_just_in_time() { |
|
2438 |
global $custom_image_header, $custom_background; |
|
2439 |
||
2440 |
if ( current_theme_supports( 'custom-header' ) ) { |
|
2441 |
// In case any constants were defined after an add_custom_image_header() call, re-run. |
|
2442 |
add_theme_support( 'custom-header', array( '__jit' => true ) ); |
|
2443 |
||
2444 |
$args = get_theme_support( 'custom-header' ); |
|
2445 |
if ( $args[0]['wp-head-callback'] ) |
|
2446 |
add_action( 'wp_head', $args[0]['wp-head-callback'] ); |
|
2447 |
||
2448 |
if ( is_admin() ) { |
|
2449 |
require_once( ABSPATH . 'wp-admin/custom-header.php' ); |
|
2450 |
$custom_image_header = new Custom_Image_Header( $args[0]['admin-head-callback'], $args[0]['admin-preview-callback'] ); |
|
2451 |
} |
|
2452 |
} |
|
2453 |
||
2454 |
if ( current_theme_supports( 'custom-background' ) ) { |
|
2455 |
// In case any constants were defined after an add_custom_background() call, re-run. |
|
2456 |
add_theme_support( 'custom-background', array( '__jit' => true ) ); |
|
2457 |
||
2458 |
$args = get_theme_support( 'custom-background' ); |
|
2459 |
add_action( 'wp_head', $args[0]['wp-head-callback'] ); |
|
2460 |
||
2461 |
if ( is_admin() ) { |
|
2462 |
require_once( ABSPATH . 'wp-admin/custom-background.php' ); |
|
2463 |
$custom_background = new Custom_Background( $args[0]['admin-head-callback'], $args[0]['admin-preview-callback'] ); |
|
2464 |
} |
|
2465 |
} |
|
2466 |
} |
|
2467 |
||
2468 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2469 |
* 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
|
2470 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2471 |
* @since 4.5.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2472 |
* @access private |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2473 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2474 |
function _custom_logo_header_styles() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2475 |
if ( ! current_theme_supports( 'custom-header', 'header-text' ) && get_theme_support( 'custom-logo', 'header-text' ) && ! get_theme_mod( 'header_text', true ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2476 |
$classes = (array) get_theme_support( 'custom-logo', 'header-text' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2477 |
$classes = array_map( 'sanitize_html_class', $classes ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2478 |
$classes = '.' . implode( ', .', $classes ); |
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 |
?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2481 |
<!-- Custom Logo: hide header text --> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2482 |
<style id="custom-logo-css" type="text/css"> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2483 |
<?php echo $classes; ?> { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2484 |
position: absolute; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2485 |
clip: rect(1px, 1px, 1px, 1px); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2486 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2487 |
</style> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2488 |
<?php |
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 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2491 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2492 |
/** |
0 | 2493 |
* Gets the theme support arguments passed when registering that support |
2494 |
* |
|
5 | 2495 |
* @since 3.1.0 |
2496 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2497 |
* @global array $_wp_theme_features |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2498 |
* |
0 | 2499 |
* @param string $feature the feature to check |
5 | 2500 |
* @return mixed The array of extra arguments or the value for the registered feature. |
0 | 2501 |
*/ |
2502 |
function get_theme_support( $feature ) { |
|
2503 |
global $_wp_theme_features; |
|
2504 |
if ( ! isset( $_wp_theme_features[ $feature ] ) ) |
|
2505 |
return false; |
|
2506 |
||
2507 |
if ( func_num_args() <= 1 ) |
|
2508 |
return $_wp_theme_features[ $feature ]; |
|
2509 |
||
2510 |
$args = array_slice( func_get_args(), 1 ); |
|
2511 |
switch ( $feature ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2512 |
case 'custom-logo' : |
0 | 2513 |
case 'custom-header' : |
2514 |
case 'custom-background' : |
|
2515 |
if ( isset( $_wp_theme_features[ $feature ][0][ $args[0] ] ) ) |
|
2516 |
return $_wp_theme_features[ $feature ][0][ $args[0] ]; |
|
2517 |
return false; |
|
5 | 2518 |
|
0 | 2519 |
default : |
2520 |
return $_wp_theme_features[ $feature ]; |
|
2521 |
} |
|
2522 |
} |
|
2523 |
||
2524 |
/** |
|
2525 |
* Allows a theme to de-register its support of a certain feature |
|
2526 |
* |
|
2527 |
* Should be called in the theme's functions.php file. Generally would |
|
2528 |
* be used for child themes to override support from the parent theme. |
|
2529 |
* |
|
2530 |
* @since 3.0.0 |
|
2531 |
* @see add_theme_support() |
|
2532 |
* @param string $feature the feature being added |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2533 |
* @return bool|void Whether feature was removed. |
0 | 2534 |
*/ |
2535 |
function remove_theme_support( $feature ) { |
|
2536 |
// Blacklist: for internal registrations not used directly by themes. |
|
2537 |
if ( in_array( $feature, array( 'editor-style', 'widgets', 'menus' ) ) ) |
|
2538 |
return false; |
|
2539 |
||
2540 |
return _remove_theme_support( $feature ); |
|
2541 |
} |
|
2542 |
||
2543 |
/** |
|
2544 |
* Do not use. Removes theme support internally, ignorant of the blacklist. |
|
2545 |
* |
|
2546 |
* @access private |
|
2547 |
* @since 3.1.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2548 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2549 |
* @global array $_wp_theme_features |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2550 |
* @global Custom_Image_Header $custom_image_header |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2551 |
* @global Custom_Background $custom_background |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2552 |
* |
5 | 2553 |
* @param string $feature |
0 | 2554 |
*/ |
2555 |
function _remove_theme_support( $feature ) { |
|
2556 |
global $_wp_theme_features; |
|
2557 |
||
2558 |
switch ( $feature ) { |
|
2559 |
case 'custom-header-uploads' : |
|
2560 |
if ( ! isset( $_wp_theme_features['custom-header'] ) ) |
|
2561 |
return false; |
|
2562 |
add_theme_support( 'custom-header', array( 'uploads' => false ) ); |
|
2563 |
return; // Do not continue - custom-header-uploads no longer exists. |
|
2564 |
} |
|
2565 |
||
2566 |
if ( ! isset( $_wp_theme_features[ $feature ] ) ) |
|
2567 |
return false; |
|
2568 |
||
2569 |
switch ( $feature ) { |
|
2570 |
case 'custom-header' : |
|
2571 |
if ( ! did_action( 'wp_loaded' ) ) |
|
2572 |
break; |
|
2573 |
$support = get_theme_support( 'custom-header' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2574 |
if ( isset( $support[0]['wp-head-callback'] ) ) { |
0 | 2575 |
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
|
2576 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2577 |
if ( isset( $GLOBALS['custom_image_header'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2578 |
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
|
2579 |
unset( $GLOBALS['custom_image_header'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2580 |
} |
0 | 2581 |
break; |
2582 |
||
2583 |
case 'custom-background' : |
|
2584 |
if ( ! did_action( 'wp_loaded' ) ) |
|
2585 |
break; |
|
2586 |
$support = get_theme_support( 'custom-background' ); |
|
2587 |
remove_action( 'wp_head', $support[0]['wp-head-callback'] ); |
|
2588 |
remove_action( 'admin_menu', array( $GLOBALS['custom_background'], 'init' ) ); |
|
2589 |
unset( $GLOBALS['custom_background'] ); |
|
2590 |
break; |
|
2591 |
} |
|
2592 |
||
2593 |
unset( $_wp_theme_features[ $feature ] ); |
|
2594 |
return true; |
|
2595 |
} |
|
2596 |
||
2597 |
/** |
|
2598 |
* Checks a theme's support for a given feature |
|
2599 |
* |
|
2600 |
* @since 2.9.0 |
|
7
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 |
* @global array $_wp_theme_features |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2603 |
* |
0 | 2604 |
* @param string $feature the feature being checked |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2605 |
* @return bool |
0 | 2606 |
*/ |
2607 |
function current_theme_supports( $feature ) { |
|
2608 |
global $_wp_theme_features; |
|
2609 |
||
2610 |
if ( 'custom-header-uploads' == $feature ) |
|
2611 |
return current_theme_supports( 'custom-header', 'uploads' ); |
|
2612 |
||
2613 |
if ( !isset( $_wp_theme_features[$feature] ) ) |
|
2614 |
return false; |
|
2615 |
||
2616 |
// If no args passed then no extra checks need be performed |
|
2617 |
if ( func_num_args() <= 1 ) |
|
2618 |
return true; |
|
2619 |
||
2620 |
$args = array_slice( func_get_args(), 1 ); |
|
2621 |
||
2622 |
switch ( $feature ) { |
|
2623 |
case 'post-thumbnails': |
|
2624 |
// post-thumbnails can be registered for only certain content/post types by passing |
|
2625 |
// an array of types to add_theme_support(). If no array was passed, then |
|
2626 |
// any type is accepted |
|
2627 |
if ( true === $_wp_theme_features[$feature] ) // Registered for all types |
|
2628 |
return true; |
|
2629 |
$content_type = $args[0]; |
|
2630 |
return in_array( $content_type, $_wp_theme_features[$feature][0] ); |
|
2631 |
||
2632 |
case 'html5': |
|
2633 |
case 'post-formats': |
|
2634 |
// specific post formats can be registered by passing an array of types to |
|
2635 |
// add_theme_support() |
|
2636 |
||
2637 |
// Specific areas of HTML5 support *must* be passed via an array to add_theme_support() |
|
2638 |
||
2639 |
$type = $args[0]; |
|
2640 |
return in_array( $type, $_wp_theme_features[$feature][0] ); |
|
2641 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2642 |
case 'custom-logo': |
0 | 2643 |
case 'custom-header': |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2644 |
case 'custom-background': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2645 |
// 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
|
2646 |
return ( isset( $_wp_theme_features[ $feature ][0][ $args[0] ] ) && $_wp_theme_features[ $feature ][0][ $args[0] ] ); |
0 | 2647 |
} |
2648 |
||
5 | 2649 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2650 |
* Filters whether the current theme supports a specific feature. |
5 | 2651 |
* |
2652 |
* The dynamic portion of the hook name, `$feature`, refers to the specific theme |
|
2653 |
* feature. Possible values include 'post-formats', 'post-thumbnails', 'custom-background', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2654 |
* 'custom-header', 'menus', 'automatic-feed-links', 'html5', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2655 |
* 'starter-content', and 'customize-selective-refresh-widgets'. |
5 | 2656 |
* |
2657 |
* @since 3.4.0 |
|
2658 |
* |
|
2659 |
* @param bool true Whether the current theme supports the given feature. Default true. |
|
2660 |
* @param array $args Array of arguments for the feature. |
|
2661 |
* @param string $feature The theme feature. |
|
2662 |
*/ |
|
2663 |
return apply_filters( "current_theme_supports-{$feature}", true, $args, $_wp_theme_features[$feature] ); |
|
0 | 2664 |
} |
2665 |
||
2666 |
/** |
|
2667 |
* Checks a theme's support for a given feature before loading the functions which implement it. |
|
2668 |
* |
|
2669 |
* @since 2.9.0 |
|
5 | 2670 |
* |
2671 |
* @param string $feature The feature being checked. |
|
2672 |
* @param string $include Path to the file. |
|
2673 |
* @return bool True if the current theme supports the supplied feature, false otherwise. |
|
0 | 2674 |
*/ |
5 | 2675 |
function require_if_theme_supports( $feature, $include ) { |
2676 |
if ( current_theme_supports( $feature ) ) { |
|
0 | 2677 |
require ( $include ); |
5 | 2678 |
return true; |
2679 |
} |
|
2680 |
return false; |
|
0 | 2681 |
} |
2682 |
||
2683 |
/** |
|
2684 |
* Checks an attachment being deleted to see if it's a header or background image. |
|
2685 |
* |
|
2686 |
* 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
|
2687 |
* attachment. |
0 | 2688 |
* |
2689 |
* @access private |
|
2690 |
* @since 3.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2691 |
* @since 4.3.0 Also removes `header_image_data`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2692 |
* @since 4.5.0 Also removes custom logo theme mods. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2693 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2694 |
* @param int $id The attachment id. |
0 | 2695 |
*/ |
2696 |
function _delete_attachment_theme_mod( $id ) { |
|
2697 |
$attachment_image = wp_get_attachment_url( $id ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2698 |
$header_image = get_header_image(); |
0 | 2699 |
$background_image = get_background_image(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2700 |
$custom_logo_id = get_theme_mod( 'custom_logo' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2701 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2702 |
if ( $custom_logo_id && $custom_logo_id == $id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2703 |
remove_theme_mod( 'custom_logo' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2704 |
remove_theme_mod( 'header_text' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2705 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2706 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2707 |
if ( $header_image && $header_image == $attachment_image ) { |
0 | 2708 |
remove_theme_mod( 'header_image' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2709 |
remove_theme_mod( 'header_image_data' ); |
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 |
if ( $background_image && $background_image == $attachment_image ) { |
0 | 2713 |
remove_theme_mod( 'background_image' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2714 |
} |
0 | 2715 |
} |
2716 |
||
2717 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2718 |
* 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
|
2719 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2720 |
* See {@see 'after_switch_theme'}. |
0 | 2721 |
* |
2722 |
* @since 3.3.0 |
|
2723 |
*/ |
|
2724 |
function check_theme_switched() { |
|
2725 |
if ( $stylesheet = get_option( 'theme_switched' ) ) { |
|
2726 |
$old_theme = wp_get_theme( $stylesheet ); |
|
2727 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2728 |
// Prevent widget & menu mapping from running since Customizer already called it up front |
5 | 2729 |
if ( get_option( 'theme_switched_via_customizer' ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2730 |
remove_action( 'after_switch_theme', '_wp_menus_changed' ); |
5 | 2731 |
remove_action( 'after_switch_theme', '_wp_sidebars_changed' ); |
2732 |
update_option( 'theme_switched_via_customizer', false ); |
|
2733 |
} |
|
2734 |
||
2735 |
if ( $old_theme->exists() ) { |
|
2736 |
/** |
|
2737 |
* Fires on the first WP load after a theme switch if the old theme still exists. |
|
2738 |
* |
|
2739 |
* This action fires multiple times and the parameters differs |
|
2740 |
* according to the context, if the old theme exists or not. |
|
2741 |
* If the old theme is missing, the parameter will be the slug |
|
2742 |
* of the old theme. |
|
2743 |
* |
|
2744 |
* @since 3.3.0 |
|
2745 |
* |
|
2746 |
* @param string $old_name Old theme name. |
|
2747 |
* @param WP_Theme $old_theme WP_Theme instance of the old theme. |
|
2748 |
*/ |
|
2749 |
do_action( 'after_switch_theme', $old_theme->get( 'Name' ), $old_theme ); |
|
2750 |
} else { |
|
2751 |
/** 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
|
2752 |
do_action( 'after_switch_theme', $stylesheet, $old_theme ); |
5 | 2753 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2754 |
flush_rewrite_rules(); |
0 | 2755 |
|
2756 |
update_option( 'theme_switched', false ); |
|
2757 |
} |
|
2758 |
} |
|
2759 |
||
2760 |
/** |
|
2761 |
* Includes and instantiates the WP_Customize_Manager class. |
|
2762 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2763 |
* 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
|
2764 |
* 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
|
2765 |
* 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
|
2766 |
* WordPress is loading, especially in the Customizer preview |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2767 |
* or when making Customizer Ajax requests for widgets or menus. |
0 | 2768 |
* |
2769 |
* @since 3.4.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2770 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2771 |
* @global WP_Customize_Manager $wp_customize |
0 | 2772 |
*/ |
2773 |
function _wp_customize_include() { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2774 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2775 |
$is_customize_admin_page = ( is_admin() && 'customize.php' == basename( $_SERVER['PHP_SELF'] ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2776 |
$should_include = ( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2777 |
$is_customize_admin_page |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2778 |
|| |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2779 |
( isset( $_REQUEST['wp_customize'] ) && 'on' == $_REQUEST['wp_customize'] ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2780 |
|| |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2781 |
( ! 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
|
2782 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2783 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2784 |
if ( ! $should_include ) { |
0 | 2785 |
return; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2786 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2787 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2788 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2789 |
* 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
|
2790 |
* 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
|
2791 |
* the values should contain any characters needing slashes anyway. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2792 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2793 |
$keys = array( 'changeset_uuid', 'customize_changeset_uuid', 'customize_theme', 'theme', 'customize_messenger_channel', 'customize_autosaved' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2794 |
$input_vars = array_merge( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2795 |
wp_array_slice_assoc( $_GET, $keys ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2796 |
wp_array_slice_assoc( $_POST, $keys ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2797 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2798 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2799 |
$theme = null; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2800 |
$changeset_uuid = false; // Value false indicates UUID should be determined after_setup_theme to either re-use existing saved changeset or else generate a new UUID if none exists. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2801 |
$messenger_channel = null; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2802 |
$autosaved = null; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2803 |
$branching = false; // Set initially fo false since defaults to true for back-compat; can be overridden via the customize_changeset_branching filter. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2804 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2805 |
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
|
2806 |
$changeset_uuid = sanitize_key( $input_vars['changeset_uuid'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2807 |
} elseif ( ! empty( $input_vars['customize_changeset_uuid'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2808 |
$changeset_uuid = sanitize_key( $input_vars['customize_changeset_uuid'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2809 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2810 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2811 |
// Note that theme will be sanitized via WP_Theme. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2812 |
if ( $is_customize_admin_page && isset( $input_vars['theme'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2813 |
$theme = $input_vars['theme']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2814 |
} elseif ( isset( $input_vars['customize_theme'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2815 |
$theme = $input_vars['customize_theme']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2816 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2817 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2818 |
if ( ! empty( $input_vars['customize_autosaved'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2819 |
$autosaved = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2820 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2821 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2822 |
if ( isset( $input_vars['customize_messenger_channel'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2823 |
$messenger_channel = sanitize_key( $input_vars['customize_messenger_channel'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2824 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2825 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2826 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2827 |
* 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
|
2828 |
* 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
|
2829 |
* 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
|
2830 |
* 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
|
2831 |
* there is nothing changed that needs to be saved. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2832 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2833 |
$is_customize_save_action = ( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2834 |
wp_doing_ajax() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2835 |
&& |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2836 |
isset( $_REQUEST['action'] ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2837 |
&& |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2838 |
'customize_save' === wp_unslash( $_REQUEST['action'] ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2839 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2840 |
$settings_previewed = ! $is_customize_save_action; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2841 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2842 |
require_once ABSPATH . WPINC . '/class-wp-customize-manager.php'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2843 |
$GLOBALS['wp_customize'] = new WP_Customize_Manager( compact( 'changeset_uuid', 'theme', 'messenger_channel', 'settings_previewed', 'autosaved', 'branching' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2844 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2845 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2846 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2847 |
* Publishes a snapshot's changes. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2848 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2849 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2850 |
* @access private |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2851 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2852 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2853 |
* @global WP_Customize_Manager $wp_customize Customizer instance. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2854 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2855 |
* @param string $new_status New post status. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2856 |
* @param string $old_status Old post status. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2857 |
* @param WP_Post $changeset_post Changeset post object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2858 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2859 |
function _wp_customize_publish_changeset( $new_status, $old_status, $changeset_post ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2860 |
global $wp_customize, $wpdb; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2861 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2862 |
$is_publishing_changeset = ( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2863 |
'customize_changeset' === $changeset_post->post_type |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2864 |
&& |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2865 |
'publish' === $new_status |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2866 |
&& |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2867 |
'publish' !== $old_status |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2868 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2869 |
if ( ! $is_publishing_changeset ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2870 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2871 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2872 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2873 |
if ( empty( $wp_customize ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2874 |
require_once ABSPATH . WPINC . '/class-wp-customize-manager.php'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2875 |
$wp_customize = new WP_Customize_Manager( array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2876 |
'changeset_uuid' => $changeset_post->post_name, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2877 |
'settings_previewed' => false, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2878 |
) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2879 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2880 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2881 |
if ( ! did_action( 'customize_register' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2882 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2883 |
* 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
|
2884 |
* 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
|
2885 |
* settings. Normally core will add_action( 'customize_register' ) at |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2886 |
* 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
|
2887 |
* 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
|
2888 |
* 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
|
2889 |
* call add_action() afterward, normally. However, when manually doing |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2890 |
* 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
|
2891 |
* 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
|
2892 |
* 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
|
2893 |
* 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
|
2894 |
* settings up front before doing the action. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2895 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2896 |
remove_action( 'customize_register', array( $wp_customize, 'register_controls' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2897 |
$wp_customize->register_controls(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2898 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2899 |
/** This filter is documented in /wp-includes/class-wp-customize-manager.php */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2900 |
do_action( 'customize_register', $wp_customize ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2901 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2902 |
$wp_customize->_publish_changeset_values( $changeset_post->ID ) ; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2903 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2904 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2905 |
* 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
|
2906 |
* 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
|
2907 |
* When a changeset post is published, however, it would no longer get cleaned |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2908 |
* out. Ths is a problem when the changeset posts are never displayed anywhere, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2909 |
* 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
|
2910 |
* 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
|
2911 |
* and thus garbage collected. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2912 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2913 |
if ( ! wp_revisions_enabled( $changeset_post ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2914 |
$wp_customize->trash_changeset_post( $changeset_post->ID ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2915 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2916 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2917 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2918 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2919 |
* 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
|
2920 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2921 |
* 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
|
2922 |
* transitioned into pending status by a contributor. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2923 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2924 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2925 |
* @see wp_insert_post() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2926 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2927 |
* @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
|
2928 |
* @param array $supplied_post_data An array of sanitized, but otherwise unmodified post data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2929 |
* @returns array Filtered data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2930 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2931 |
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
|
2932 |
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
|
2933 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2934 |
// 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
|
2935 |
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
|
2936 |
$post_data['post_name'] = $supplied_post_data['post_name']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2937 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2938 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2939 |
return $post_data; |
0 | 2940 |
} |
2941 |
||
2942 |
/** |
|
2943 |
* Adds settings for the customize-loader script. |
|
2944 |
* |
|
2945 |
* @since 3.4.0 |
|
2946 |
*/ |
|
2947 |
function _wp_customize_loader_settings() { |
|
2948 |
$admin_origin = parse_url( admin_url() ); |
|
2949 |
$home_origin = parse_url( home_url() ); |
|
2950 |
$cross_domain = ( strtolower( $admin_origin[ 'host' ] ) != strtolower( $home_origin[ 'host' ] ) ); |
|
2951 |
||
2952 |
$browser = array( |
|
2953 |
'mobile' => wp_is_mobile(), |
|
2954 |
'ios' => wp_is_mobile() && preg_match( '/iPad|iPod|iPhone/', $_SERVER['HTTP_USER_AGENT'] ), |
|
2955 |
); |
|
2956 |
||
2957 |
$settings = array( |
|
2958 |
'url' => esc_url( admin_url( 'customize.php' ) ), |
|
2959 |
'isCrossDomain' => $cross_domain, |
|
2960 |
'browser' => $browser, |
|
5 | 2961 |
'l10n' => array( |
2962 |
'saveAlert' => __( 'The changes you made will be lost if you navigate away from this page.' ), |
|
2963 |
'mainIframeTitle' => __( 'Customizer' ), |
|
2964 |
), |
|
0 | 2965 |
); |
2966 |
||
5 | 2967 |
$script = 'var _wpCustomizeLoaderSettings = ' . wp_json_encode( $settings ) . ';'; |
0 | 2968 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2969 |
$wp_scripts = wp_scripts(); |
0 | 2970 |
$data = $wp_scripts->get_data( 'customize-loader', 'data' ); |
2971 |
if ( $data ) |
|
2972 |
$script = "$data\n$script"; |
|
2973 |
||
2974 |
$wp_scripts->add_data( 'customize-loader', 'data', $script ); |
|
2975 |
} |
|
2976 |
||
2977 |
/** |
|
5 | 2978 |
* Returns a URL to load the Customizer. |
0 | 2979 |
* |
2980 |
* @since 3.4.0 |
|
2981 |
* |
|
2982 |
* @param string $stylesheet Optional. Theme to customize. Defaults to current theme. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2983 |
* The theme's stylesheet will be urlencoded if necessary. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2984 |
* @return string |
0 | 2985 |
*/ |
2986 |
function wp_customize_url( $stylesheet = null ) { |
|
2987 |
$url = admin_url( 'customize.php' ); |
|
2988 |
if ( $stylesheet ) |
|
2989 |
$url .= '?theme=' . urlencode( $stylesheet ); |
|
2990 |
return esc_url( $url ); |
|
2991 |
} |
|
2992 |
||
2993 |
/** |
|
5 | 2994 |
* Prints a script to check whether or not the Customizer is supported, |
0 | 2995 |
* and apply either the no-customize-support or customize-support class |
2996 |
* to the body. |
|
2997 |
* |
|
2998 |
* This function MUST be called inside the body tag. |
|
2999 |
* |
|
3000 |
* Ideally, call this function immediately after the body tag is opened. |
|
3001 |
* This prevents a flash of unstyled content. |
|
3002 |
* |
|
3003 |
* It is also recommended that you add the "no-customize-support" class |
|
3004 |
* to the body tag by default. |
|
3005 |
* |
|
3006 |
* @since 3.4.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3007 |
* @since 4.7.0 Support for IE8 and below is explicitly removed via conditional comments. |
0 | 3008 |
*/ |
3009 |
function wp_customize_support_script() { |
|
3010 |
$admin_origin = parse_url( admin_url() ); |
|
3011 |
$home_origin = parse_url( home_url() ); |
|
3012 |
$cross_domain = ( strtolower( $admin_origin[ 'host' ] ) != strtolower( $home_origin[ 'host' ] ) ); |
|
3013 |
||
3014 |
?> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3015 |
<!--[if lte IE 8]> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3016 |
<script type="text/javascript"> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3017 |
document.body.className = document.body.className.replace( /(^|\s)(no-)?customize-support(?=\s|$)/, '' ) + ' no-customize-support'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3018 |
</script> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3019 |
<![endif]--> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3020 |
<!--[if gte IE 9]><!--> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3021 |
<script type="text/javascript"> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3022 |
(function() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3023 |
var request, b = document.body, c = 'className', cs = 'customize-support', rcs = new RegExp('(^|\\s+)(no-)?'+cs+'(\\s+|$)'); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3024 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3025 |
<?php if ( $cross_domain ) : ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3026 |
request = (function(){ var xhr = new XMLHttpRequest(); return ('withCredentials' in xhr); })(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3027 |
<?php else : ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3028 |
request = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3029 |
<?php endif; ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3030 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3031 |
b[c] = b[c].replace( rcs, ' ' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3032 |
// The customizer requires postMessage and CORS (if the site is cross domain) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3033 |
b[c] += ( window.postMessage && request ? ' ' : ' no-' ) + cs; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3034 |
}()); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3035 |
</script> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3036 |
<!--<![endif]--> |
0 | 3037 |
<?php |
5 | 3038 |
} |
3039 |
||
3040 |
/** |
|
3041 |
* Whether the site is being previewed in the Customizer. |
|
3042 |
* |
|
3043 |
* @since 4.0.0 |
|
3044 |
* |
|
3045 |
* @global WP_Customize_Manager $wp_customize Customizer instance. |
|
3046 |
* |
|
3047 |
* @return bool True if the site is being previewed in the Customizer, false otherwise. |
|
3048 |
*/ |
|
3049 |
function is_customize_preview() { |
|
3050 |
global $wp_customize; |
|
3051 |
||
3052 |
return ( $wp_customize instanceof WP_Customize_Manager ) && $wp_customize->is_preview(); |
|
3053 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3054 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3055 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3056 |
* Make sure that auto-draft posts get their post_date bumped or status changed to draft to prevent premature garbage-collection. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3057 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3058 |
* 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
|
3059 |
* 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
|
3060 |
* 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
|
3061 |
* 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
|
3062 |
* 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
|
3063 |
* unless the changeset post itself is deleted. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3064 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3065 |
* 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
|
3066 |
* 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
|
3067 |
* 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
|
3068 |
* 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
|
3069 |
* editing flow in the Customizer. See #39752. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3070 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3071 |
* @link https://core.trac.wordpress.org/ticket/39752 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3072 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3073 |
* @since 4.8.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3074 |
* @access private |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3075 |
* @see wp_delete_auto_drafts() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3076 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3077 |
* @param string $new_status Transition to this post status. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3078 |
* @param string $old_status Previous post status. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3079 |
* @param \WP_Post $post Post data. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3080 |
* @global wpdb $wpdb |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3081 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3082 |
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
|
3083 |
global $wpdb; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3084 |
unset( $old_status ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3085 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3086 |
// 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
|
3087 |
if ( 'customize_changeset' !== $post->post_type || 'publish' === $new_status ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3088 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3089 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3090 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3091 |
$data = json_decode( $post->post_content, true ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3092 |
if ( empty( $data['nav_menus_created_posts']['value'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3093 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3094 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3095 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3096 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3097 |
* 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
|
3098 |
* 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
|
3099 |
* 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
|
3100 |
* 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
|
3101 |
* _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
|
3102 |
* trashed to remove from visibility immediately. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3103 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3104 |
if ( 'trash' === $new_status ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3105 |
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
|
3106 |
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
|
3107 |
wp_trash_post( $post_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3108 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3109 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3110 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3111 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3112 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3113 |
$post_args = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3114 |
if ( 'auto-draft' === $new_status ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3115 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3116 |
* 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
|
3117 |
* 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
|
3118 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3119 |
$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
|
3120 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3121 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3122 |
* 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
|
3123 |
* 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
|
3124 |
* 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
|
3125 |
* status. These drafts will be treated differently than regular drafts in |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3126 |
* that they will be tied to the given changeset. The publish metabox is |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3127 |
* 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
|
3128 |
* which will be published when the changeset is published. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3129 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3130 |
$post_args['post_status'] = 'draft'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3131 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3132 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3133 |
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
|
3134 |
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
|
3135 |
continue; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3136 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3137 |
$wpdb->update( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3138 |
$wpdb->posts, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3139 |
$post_args, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3140 |
array( 'ID' => $post_id ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3141 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3142 |
clean_post_cache( $post_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3143 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3144 |
} |