author | ymh <ymh.work@gmail.com> |
Tue, 15 Dec 2020 13:49:49 +0100 | |
changeset 16 | a86126ab1dd4 |
parent 9 | 177826044cd9 |
child 18 | be944660c56a |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
3 |
* General template tags that can go anywhere in a template. |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
* @subpackage Template |
|
7 |
*/ |
|
8 |
||
9 |
/** |
|
10 |
* Load header template. |
|
11 |
* |
|
12 |
* Includes the header template for a theme or if a name is specified then a |
|
13 |
* specialised header will be included. |
|
14 |
* |
|
15 |
* For the parameter, if the file is called "header-special.php" then specify |
|
16 |
* "special". |
|
17 |
* |
|
18 |
* @since 1.5.0 |
|
16 | 19 |
* @since 5.5.0 A return value was added. |
20 |
* @since 5.5.0 The `$args` parameter was added. |
|
0 | 21 |
* |
22 |
* @param string $name The name of the specialised header. |
|
16 | 23 |
* @param array $args Optional. Additional arguments passed to the header template. |
24 |
* Default empty array. |
|
25 |
* @return void|false Void on success, false if the template does not exist. |
|
0 | 26 |
*/ |
16 | 27 |
function get_header( $name = null, $args = array() ) { |
5 | 28 |
/** |
29 |
* Fires before the header template file is loaded. |
|
30 |
* |
|
31 |
* @since 2.1.0 |
|
16 | 32 |
* @since 2.8.0 The `$name` parameter was added. |
33 |
* @since 5.5.0 The `$args` parameter was added. |
|
5 | 34 |
* |
16 | 35 |
* @param string|null $name Name of the specific header file to use. Null for the default header. |
36 |
* @param array $args Additional arguments passed to the header template. |
|
5 | 37 |
*/ |
16 | 38 |
do_action( 'get_header', $name, $args ); |
0 | 39 |
|
40 |
$templates = array(); |
|
9 | 41 |
$name = (string) $name; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
42 |
if ( '' !== $name ) { |
0 | 43 |
$templates[] = "header-{$name}.php"; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
44 |
} |
0 | 45 |
|
46 |
$templates[] = 'header.php'; |
|
47 |
||
16 | 48 |
if ( ! locate_template( $templates, true, true, $args ) ) { |
49 |
return false; |
|
50 |
} |
|
0 | 51 |
} |
52 |
||
53 |
/** |
|
54 |
* Load footer template. |
|
55 |
* |
|
56 |
* Includes the footer template for a theme or if a name is specified then a |
|
57 |
* specialised footer will be included. |
|
58 |
* |
|
59 |
* For the parameter, if the file is called "footer-special.php" then specify |
|
60 |
* "special". |
|
61 |
* |
|
62 |
* @since 1.5.0 |
|
16 | 63 |
* @since 5.5.0 A return value was added. |
64 |
* @since 5.5.0 The `$args` parameter was added. |
|
0 | 65 |
* |
66 |
* @param string $name The name of the specialised footer. |
|
16 | 67 |
* @param array $args Optional. Additional arguments passed to the footer template. |
68 |
* Default empty array. |
|
69 |
* @return void|false Void on success, false if the template does not exist. |
|
0 | 70 |
*/ |
16 | 71 |
function get_footer( $name = null, $args = array() ) { |
5 | 72 |
/** |
73 |
* Fires before the footer template file is loaded. |
|
74 |
* |
|
75 |
* @since 2.1.0 |
|
16 | 76 |
* @since 2.8.0 The `$name` parameter was added. |
77 |
* @since 5.5.0 The `$args` parameter was added. |
|
5 | 78 |
* |
16 | 79 |
* @param string|null $name Name of the specific footer file to use. Null for the default footer. |
80 |
* @param array $args Additional arguments passed to the footer template. |
|
5 | 81 |
*/ |
16 | 82 |
do_action( 'get_footer', $name, $args ); |
0 | 83 |
|
84 |
$templates = array(); |
|
9 | 85 |
$name = (string) $name; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
86 |
if ( '' !== $name ) { |
0 | 87 |
$templates[] = "footer-{$name}.php"; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
88 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
89 |
|
9 | 90 |
$templates[] = 'footer.php'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
91 |
|
16 | 92 |
if ( ! locate_template( $templates, true, true, $args ) ) { |
93 |
return false; |
|
94 |
} |
|
0 | 95 |
} |
96 |
||
97 |
/** |
|
98 |
* Load sidebar template. |
|
99 |
* |
|
100 |
* Includes the sidebar template for a theme or if a name is specified then a |
|
101 |
* specialised sidebar will be included. |
|
102 |
* |
|
103 |
* For the parameter, if the file is called "sidebar-special.php" then specify |
|
104 |
* "special". |
|
105 |
* |
|
106 |
* @since 1.5.0 |
|
16 | 107 |
* @since 5.5.0 A return value was added. |
108 |
* @since 5.5.0 The `$args` parameter was added. |
|
0 | 109 |
* |
110 |
* @param string $name The name of the specialised sidebar. |
|
16 | 111 |
* @param array $args Optional. Additional arguments passed to the sidebar template. |
112 |
* Default empty array. |
|
113 |
* @return void|false Void on success, false if the template does not exist. |
|
0 | 114 |
*/ |
16 | 115 |
function get_sidebar( $name = null, $args = array() ) { |
5 | 116 |
/** |
117 |
* Fires before the sidebar template file is loaded. |
|
118 |
* |
|
119 |
* @since 2.2.0 |
|
16 | 120 |
* @since 2.8.0 The `$name` parameter was added. |
121 |
* @since 5.5.0 The `$args` parameter was added. |
|
5 | 122 |
* |
16 | 123 |
* @param string|null $name Name of the specific sidebar file to use. Null for the default sidebar. |
124 |
* @param array $args Additional arguments passed to the sidebar template. |
|
5 | 125 |
*/ |
16 | 126 |
do_action( 'get_sidebar', $name, $args ); |
0 | 127 |
|
128 |
$templates = array(); |
|
9 | 129 |
$name = (string) $name; |
130 |
if ( '' !== $name ) { |
|
0 | 131 |
$templates[] = "sidebar-{$name}.php"; |
9 | 132 |
} |
0 | 133 |
|
134 |
$templates[] = 'sidebar.php'; |
|
135 |
||
16 | 136 |
if ( ! locate_template( $templates, true, true, $args ) ) { |
137 |
return false; |
|
138 |
} |
|
0 | 139 |
} |
140 |
||
141 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
142 |
* Loads a template part into a template. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
143 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
144 |
* Provides a simple mechanism for child themes to overload reusable sections of code |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
145 |
* in the theme. |
0 | 146 |
* |
147 |
* Includes the named template part for a theme or if a name is specified then a |
|
148 |
* specialised part will be included. If the theme contains no {slug}.php file |
|
149 |
* then no template will be included. |
|
150 |
* |
|
151 |
* The template is included using require, not require_once, so you may include the |
|
152 |
* same template part multiple times. |
|
153 |
* |
|
154 |
* For the $name parameter, if the file is called "{slug}-special.php" then specify |
|
155 |
* "special". |
|
156 |
* |
|
157 |
* @since 3.0.0 |
|
16 | 158 |
* @since 5.5.0 A return value was added. |
159 |
* @since 5.5.0 The `$args` parameter was added. |
|
0 | 160 |
* |
161 |
* @param string $slug The slug name for the generic template. |
|
162 |
* @param string $name The name of the specialised template. |
|
16 | 163 |
* @param array $args Optional. Additional arguments passed to the template. |
164 |
* Default empty array. |
|
165 |
* @return void|false Void on success, false if the template does not exist. |
|
0 | 166 |
*/ |
16 | 167 |
function get_template_part( $slug, $name = null, $args = array() ) { |
5 | 168 |
/** |
169 |
* Fires before the specified template part file is loaded. |
|
170 |
* |
|
171 |
* The dynamic portion of the hook name, `$slug`, refers to the slug name |
|
172 |
* for the generic template part. |
|
173 |
* |
|
174 |
* @since 3.0.0 |
|
16 | 175 |
* @since 5.5.0 The `$args` parameter was added. |
5 | 176 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
177 |
* @param string $slug The slug name for the generic template. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
178 |
* @param string|null $name The name of the specialized template. |
16 | 179 |
* @param array $args Additional arguments passed to the template. |
5 | 180 |
*/ |
16 | 181 |
do_action( "get_template_part_{$slug}", $slug, $name, $args ); |
0 | 182 |
|
183 |
$templates = array(); |
|
9 | 184 |
$name = (string) $name; |
185 |
if ( '' !== $name ) { |
|
0 | 186 |
$templates[] = "{$slug}-{$name}.php"; |
9 | 187 |
} |
0 | 188 |
|
189 |
$templates[] = "{$slug}.php"; |
|
190 |
||
9 | 191 |
/** |
192 |
* Fires before a template part is loaded. |
|
193 |
* |
|
194 |
* @since 5.2.0 |
|
16 | 195 |
* @since 5.5.0 The `$args` parameter was added. |
9 | 196 |
* |
197 |
* @param string $slug The slug name for the generic template. |
|
198 |
* @param string $name The name of the specialized template. |
|
199 |
* @param string[] $templates Array of template files to search for, in order. |
|
16 | 200 |
* @param array $args Additional arguments passed to the template. |
9 | 201 |
*/ |
16 | 202 |
do_action( 'get_template_part', $slug, $name, $templates, $args ); |
203 |
||
204 |
if ( ! locate_template( $templates, true, false, $args ) ) { |
|
205 |
return false; |
|
206 |
} |
|
0 | 207 |
} |
208 |
||
209 |
/** |
|
210 |
* Display search form. |
|
211 |
* |
|
212 |
* Will first attempt to locate the searchform.php file in either the child or |
|
213 |
* the parent, then load it. If it doesn't exist, then the default search form |
|
214 |
* will be displayed. The default search form is HTML, which will be displayed. |
|
215 |
* There is a filter applied to the search form HTML in order to edit or replace |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
216 |
* it. The filter is {@see 'get_search_form'}. |
0 | 217 |
* |
218 |
* This function is primarily used by themes which want to hardcode the search |
|
219 |
* form into the sidebar and also by the search widget in WordPress. |
|
220 |
* |
|
221 |
* There is also an action that is called whenever the function is run called, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
222 |
* {@see 'pre_get_search_form'}. This can be useful for outputting JavaScript that the |
0 | 223 |
* search relies on or various formatting that applies to the beginning of the |
224 |
* search. To give a few examples of what it can be used for. |
|
225 |
* |
|
226 |
* @since 2.7.0 |
|
16 | 227 |
* @since 5.2.0 The `$args` array parameter was added in place of an `$echo` boolean flag. |
9 | 228 |
* |
229 |
* @param array $args { |
|
230 |
* Optional. Array of display arguments. |
|
231 |
* |
|
232 |
* @type bool $echo Whether to echo or return the form. Default true. |
|
233 |
* @type string $aria_label ARIA label for the search form. Useful to distinguish |
|
234 |
* multiple search forms on the same page and improve |
|
235 |
* accessibility. Default empty. |
|
236 |
* } |
|
16 | 237 |
* @return void|string Void if 'echo' argument is true, search form HTML if 'echo' is false. |
0 | 238 |
*/ |
9 | 239 |
function get_search_form( $args = array() ) { |
5 | 240 |
/** |
241 |
* Fires before the search form is retrieved, at the start of get_search_form(). |
|
242 |
* |
|
243 |
* @since 2.7.0 as 'get_search_form' action. |
|
244 |
* @since 3.6.0 |
|
16 | 245 |
* @since 5.5.0 The `$args` parameter was added. |
5 | 246 |
* |
247 |
* @link https://core.trac.wordpress.org/ticket/19321 |
|
16 | 248 |
* |
249 |
* @param array $args The array of arguments for building the search form. |
|
5 | 250 |
*/ |
16 | 251 |
do_action( 'pre_get_search_form', $args ); |
0 | 252 |
|
9 | 253 |
$echo = true; |
254 |
||
255 |
if ( ! is_array( $args ) ) { |
|
256 |
/* |
|
257 |
* Back compat: to ensure previous uses of get_search_form() continue to |
|
258 |
* function as expected, we handle a value for the boolean $echo param removed |
|
259 |
* in 5.2.0. Then we deal with the $args array and cast its defaults. |
|
260 |
*/ |
|
261 |
$echo = (bool) $args; |
|
262 |
||
263 |
// Set an empty array and allow default arguments to take over. |
|
264 |
$args = array(); |
|
265 |
} |
|
266 |
||
267 |
// Defaults are to echo and to output no custom label on the form. |
|
268 |
$defaults = array( |
|
269 |
'echo' => $echo, |
|
270 |
'aria_label' => '', |
|
271 |
); |
|
272 |
||
273 |
$args = wp_parse_args( $args, $defaults ); |
|
274 |
||
275 |
/** |
|
276 |
* Filters the array of arguments used when generating the search form. |
|
277 |
* |
|
278 |
* @since 5.2.0 |
|
279 |
* |
|
280 |
* @param array $args The array of arguments for building the search form. |
|
281 |
*/ |
|
282 |
$args = apply_filters( 'search_form_args', $args ); |
|
283 |
||
0 | 284 |
$format = current_theme_supports( 'html5', 'search-form' ) ? 'html5' : 'xhtml'; |
5 | 285 |
|
286 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
287 |
* Filters the HTML format of the search form. |
5 | 288 |
* |
289 |
* @since 3.6.0 |
|
16 | 290 |
* @since 5.5.0 The `$args` parameter was added. |
5 | 291 |
* |
292 |
* @param string $format The type of markup to use in the search form. |
|
293 |
* Accepts 'html5', 'xhtml'. |
|
16 | 294 |
* @param array $args The array of arguments for building the search form. |
5 | 295 |
*/ |
16 | 296 |
$format = apply_filters( 'search_form_format', $format, $args ); |
0 | 297 |
|
298 |
$search_form_template = locate_template( 'searchform.php' ); |
|
16 | 299 |
|
300 |
if ( '' !== $search_form_template ) { |
|
0 | 301 |
ob_start(); |
16 | 302 |
require $search_form_template; |
0 | 303 |
$form = ob_get_clean(); |
304 |
} else { |
|
9 | 305 |
// Build a string containing an aria-label to use for the search form. |
306 |
if ( isset( $args['aria_label'] ) && $args['aria_label'] ) { |
|
307 |
$aria_label = 'aria-label="' . esc_attr( $args['aria_label'] ) . '" '; |
|
308 |
} else { |
|
309 |
/* |
|
310 |
* If there's no custom aria-label, we can set a default here. At the |
|
311 |
* moment it's empty as there's uncertainty about what the default should be. |
|
312 |
*/ |
|
313 |
$aria_label = ''; |
|
314 |
} |
|
16 | 315 |
|
316 |
if ( 'html5' === $format ) { |
|
9 | 317 |
$form = '<form role="search" ' . $aria_label . 'method="get" class="search-form" action="' . esc_url( home_url( '/' ) ) . '"> |
0 | 318 |
<label> |
319 |
<span class="screen-reader-text">' . _x( 'Search for:', 'label' ) . '</span> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
320 |
<input type="search" class="search-field" placeholder="' . esc_attr_x( 'Search …', 'placeholder' ) . '" value="' . get_search_query() . '" name="s" /> |
0 | 321 |
</label> |
9 | 322 |
<input type="submit" class="search-submit" value="' . esc_attr_x( 'Search', 'submit button' ) . '" /> |
0 | 323 |
</form>'; |
324 |
} else { |
|
9 | 325 |
$form = '<form role="search" ' . $aria_label . 'method="get" id="searchform" class="searchform" action="' . esc_url( home_url( '/' ) ) . '"> |
0 | 326 |
<div> |
327 |
<label class="screen-reader-text" for="s">' . _x( 'Search for:', 'label' ) . '</label> |
|
328 |
<input type="text" value="' . get_search_query() . '" name="s" id="s" /> |
|
9 | 329 |
<input type="submit" id="searchsubmit" value="' . esc_attr_x( 'Search', 'submit button' ) . '" /> |
0 | 330 |
</div> |
331 |
</form>'; |
|
332 |
} |
|
333 |
} |
|
334 |
||
5 | 335 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
336 |
* Filters the HTML output of the search form. |
5 | 337 |
* |
338 |
* @since 2.7.0 |
|
16 | 339 |
* @since 5.5.0 The `$args` parameter was added. |
5 | 340 |
* |
341 |
* @param string $form The search form HTML output. |
|
16 | 342 |
* @param array $args The array of arguments for building the search form. |
5 | 343 |
*/ |
16 | 344 |
$result = apply_filters( 'get_search_form', $form, $args ); |
5 | 345 |
|
9 | 346 |
if ( null === $result ) { |
0 | 347 |
$result = $form; |
9 | 348 |
} |
349 |
||
16 | 350 |
if ( $args['echo'] ) { |
0 | 351 |
echo $result; |
9 | 352 |
} else { |
0 | 353 |
return $result; |
9 | 354 |
} |
0 | 355 |
} |
356 |
||
357 |
/** |
|
358 |
* Display the Log In/Out link. |
|
359 |
* |
|
360 |
* Displays a link, which allows users to navigate to the Log In page to log in |
|
361 |
* or log out depending on whether they are currently logged in. |
|
362 |
* |
|
363 |
* @since 1.5.0 |
|
364 |
* |
|
365 |
* @param string $redirect Optional path to redirect to on login/logout. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
366 |
* @param bool $echo Default to echo and not return the link. |
16 | 367 |
* @return void|string Void if `$echo` argument is true, log in/out link if `$echo` is false. |
0 | 368 |
*/ |
9 | 369 |
function wp_loginout( $redirect = '', $echo = true ) { |
370 |
if ( ! is_user_logged_in() ) { |
|
371 |
$link = '<a href="' . esc_url( wp_login_url( $redirect ) ) . '">' . __( 'Log in' ) . '</a>'; |
|
372 |
} else { |
|
373 |
$link = '<a href="' . esc_url( wp_logout_url( $redirect ) ) . '">' . __( 'Log out' ) . '</a>'; |
|
374 |
} |
|
0 | 375 |
|
5 | 376 |
if ( $echo ) { |
377 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
378 |
* Filters the HTML output for the Log In/Log Out link. |
5 | 379 |
* |
380 |
* @since 1.5.0 |
|
381 |
* |
|
382 |
* @param string $link The HTML link content. |
|
383 |
*/ |
|
384 |
echo apply_filters( 'loginout', $link ); |
|
385 |
} else { |
|
386 |
/** This filter is documented in wp-includes/general-template.php */ |
|
387 |
return apply_filters( 'loginout', $link ); |
|
388 |
} |
|
0 | 389 |
} |
390 |
||
391 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
392 |
* Retrieves the logout URL. |
0 | 393 |
* |
394 |
* Returns the URL that allows the user to log out of the site. |
|
395 |
* |
|
396 |
* @since 2.7.0 |
|
397 |
* |
|
398 |
* @param string $redirect Path to redirect to on logout. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
399 |
* @return string The logout URL. Note: HTML-encoded via esc_html() in wp_nonce_url(). |
0 | 400 |
*/ |
9 | 401 |
function wp_logout_url( $redirect = '' ) { |
16 | 402 |
$args = array(); |
9 | 403 |
if ( ! empty( $redirect ) ) { |
0 | 404 |
$args['redirect_to'] = urlencode( $redirect ); |
405 |
} |
|
406 |
||
16 | 407 |
$logout_url = add_query_arg( $args, site_url( 'wp-login.php?action=logout', 'login' ) ); |
0 | 408 |
$logout_url = wp_nonce_url( $logout_url, 'log-out' ); |
409 |
||
5 | 410 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
411 |
* Filters the logout URL. |
5 | 412 |
* |
413 |
* @since 2.8.0 |
|
414 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
415 |
* @param string $logout_url The HTML-encoded logout URL. |
5 | 416 |
* @param string $redirect Path to redirect to on logout. |
417 |
*/ |
|
418 |
return apply_filters( 'logout_url', $logout_url, $redirect ); |
|
0 | 419 |
} |
420 |
||
421 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
422 |
* Retrieves the login URL. |
0 | 423 |
* |
424 |
* @since 2.7.0 |
|
425 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
426 |
* @param string $redirect Path to redirect to on log in. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
427 |
* @param bool $force_reauth Whether to force reauthorization, even if a cookie is present. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
428 |
* Default false. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
429 |
* @return string The login URL. Not HTML-encoded. |
0 | 430 |
*/ |
9 | 431 |
function wp_login_url( $redirect = '', $force_reauth = false ) { |
432 |
$login_url = site_url( 'wp-login.php', 'login' ); |
|
433 |
||
434 |
if ( ! empty( $redirect ) ) { |
|
435 |
$login_url = add_query_arg( 'redirect_to', urlencode( $redirect ), $login_url ); |
|
436 |
} |
|
437 |
||
438 |
if ( $force_reauth ) { |
|
439 |
$login_url = add_query_arg( 'reauth', '1', $login_url ); |
|
440 |
} |
|
0 | 441 |
|
5 | 442 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
443 |
* Filters the login URL. |
5 | 444 |
* |
445 |
* @since 2.8.0 |
|
446 |
* @since 4.2.0 The `$force_reauth` parameter was added. |
|
447 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
448 |
* @param string $login_url The login URL. Not HTML-encoded. |
5 | 449 |
* @param string $redirect The path to redirect to on login, if supplied. |
450 |
* @param bool $force_reauth Whether to force reauthorization, even if a cookie is present. |
|
451 |
*/ |
|
452 |
return apply_filters( 'login_url', $login_url, $redirect, $force_reauth ); |
|
0 | 453 |
} |
454 |
||
455 |
/** |
|
456 |
* Returns the URL that allows the user to register on the site. |
|
457 |
* |
|
458 |
* @since 3.6.0 |
|
459 |
* |
|
5 | 460 |
* @return string User registration URL. |
0 | 461 |
*/ |
462 |
function wp_registration_url() { |
|
5 | 463 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
464 |
* Filters the user registration URL. |
5 | 465 |
* |
466 |
* @since 3.6.0 |
|
467 |
* |
|
468 |
* @param string $register The user registration URL. |
|
469 |
*/ |
|
0 | 470 |
return apply_filters( 'register_url', site_url( 'wp-login.php?action=register', 'login' ) ); |
471 |
} |
|
472 |
||
473 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
474 |
* Provides a simple login form for use anywhere within WordPress. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
475 |
* |
16 | 476 |
* The login form HTML is echoed by default. Pass a false value for `$echo` to return it instead. |
0 | 477 |
* |
478 |
* @since 3.0.0 |
|
5 | 479 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
480 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
481 |
* Optional. Array of options to control the form output. Default empty array. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
482 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
483 |
* @type bool $echo Whether to display the login form or return the form HTML code. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
484 |
* Default true (echo). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
485 |
* @type string $redirect URL to redirect to. Must be absolute, as in "https://example.com/mypage/". |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
486 |
* Default is to redirect back to the request URI. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
487 |
* @type string $form_id ID attribute value for the form. Default 'loginform'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
488 |
* @type string $label_username Label for the username or email address field. Default 'Username or Email Address'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
489 |
* @type string $label_password Label for the password field. Default 'Password'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
490 |
* @type string $label_remember Label for the remember field. Default 'Remember Me'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
491 |
* @type string $label_log_in Label for the submit button. Default 'Log In'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
492 |
* @type string $id_username ID attribute value for the username field. Default 'user_login'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
493 |
* @type string $id_password ID attribute value for the password field. Default 'user_pass'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
494 |
* @type string $id_remember ID attribute value for the remember field. Default 'rememberme'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
495 |
* @type string $id_submit ID attribute value for the submit button. Default 'wp-submit'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
496 |
* @type bool $remember Whether to display the "rememberme" checkbox in the form. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
497 |
* @type string $value_username Default value for the username field. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
498 |
* @type bool $value_remember Whether the "Remember Me" checkbox should be checked by default. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
499 |
* Default false (unchecked). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
500 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
501 |
* } |
16 | 502 |
* @return void|string Void if 'echo' argument is true, login form HTML if 'echo' is false. |
0 | 503 |
*/ |
504 |
function wp_login_form( $args = array() ) { |
|
505 |
$defaults = array( |
|
9 | 506 |
'echo' => true, |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
507 |
// Default 'redirect' value takes the user back to the request URI. |
9 | 508 |
'redirect' => ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], |
509 |
'form_id' => 'loginform', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
510 |
'label_username' => __( 'Username or Email Address' ), |
0 | 511 |
'label_password' => __( 'Password' ), |
512 |
'label_remember' => __( 'Remember Me' ), |
|
9 | 513 |
'label_log_in' => __( 'Log In' ), |
514 |
'id_username' => 'user_login', |
|
515 |
'id_password' => 'user_pass', |
|
516 |
'id_remember' => 'rememberme', |
|
517 |
'id_submit' => 'wp-submit', |
|
518 |
'remember' => true, |
|
0 | 519 |
'value_username' => '', |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
520 |
// Set 'value_remember' to true to default the "Remember me" checkbox to checked. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
521 |
'value_remember' => false, |
0 | 522 |
); |
5 | 523 |
|
524 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
525 |
* Filters the default login form output arguments. |
5 | 526 |
* |
527 |
* @since 3.0.0 |
|
528 |
* |
|
529 |
* @see wp_login_form() |
|
530 |
* |
|
531 |
* @param array $defaults An array of default login form arguments. |
|
532 |
*/ |
|
0 | 533 |
$args = wp_parse_args( $args, apply_filters( 'login_form_defaults', $defaults ) ); |
534 |
||
5 | 535 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
536 |
* Filters content to display at the top of the login form. |
5 | 537 |
* |
538 |
* The filter evaluates just following the opening form tag element. |
|
539 |
* |
|
540 |
* @since 3.0.0 |
|
541 |
* |
|
542 |
* @param string $content Content to display. Default empty. |
|
543 |
* @param array $args Array of login form arguments. |
|
544 |
*/ |
|
545 |
$login_form_top = apply_filters( 'login_form_top', '', $args ); |
|
546 |
||
547 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
548 |
* Filters content to display in the middle of the login form. |
5 | 549 |
* |
550 |
* The filter evaluates just following the location where the 'login-password' |
|
551 |
* field is displayed. |
|
552 |
* |
|
553 |
* @since 3.0.0 |
|
554 |
* |
|
555 |
* @param string $content Content to display. Default empty. |
|
556 |
* @param array $args Array of login form arguments. |
|
557 |
*/ |
|
558 |
$login_form_middle = apply_filters( 'login_form_middle', '', $args ); |
|
559 |
||
560 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
561 |
* Filters content to display at the bottom of the login form. |
5 | 562 |
* |
563 |
* The filter evaluates just preceding the closing form tag element. |
|
564 |
* |
|
565 |
* @since 3.0.0 |
|
566 |
* |
|
567 |
* @param string $content Content to display. Default empty. |
|
568 |
* @param array $args Array of login form arguments. |
|
569 |
*/ |
|
570 |
$login_form_bottom = apply_filters( 'login_form_bottom', '', $args ); |
|
571 |
||
0 | 572 |
$form = ' |
573 |
<form name="' . $args['form_id'] . '" id="' . $args['form_id'] . '" action="' . esc_url( site_url( 'wp-login.php', 'login_post' ) ) . '" method="post"> |
|
5 | 574 |
' . $login_form_top . ' |
0 | 575 |
<p class="login-username"> |
576 |
<label for="' . esc_attr( $args['id_username'] ) . '">' . esc_html( $args['label_username'] ) . '</label> |
|
577 |
<input type="text" name="log" id="' . esc_attr( $args['id_username'] ) . '" class="input" value="' . esc_attr( $args['value_username'] ) . '" size="20" /> |
|
578 |
</p> |
|
579 |
<p class="login-password"> |
|
580 |
<label for="' . esc_attr( $args['id_password'] ) . '">' . esc_html( $args['label_password'] ) . '</label> |
|
581 |
<input type="password" name="pwd" id="' . esc_attr( $args['id_password'] ) . '" class="input" value="" size="20" /> |
|
582 |
</p> |
|
5 | 583 |
' . $login_form_middle . ' |
0 | 584 |
' . ( $args['remember'] ? '<p class="login-remember"><label><input name="rememberme" type="checkbox" id="' . esc_attr( $args['id_remember'] ) . '" value="forever"' . ( $args['value_remember'] ? ' checked="checked"' : '' ) . ' /> ' . esc_html( $args['label_remember'] ) . '</label></p>' : '' ) . ' |
585 |
<p class="login-submit"> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
586 |
<input type="submit" name="wp-submit" id="' . esc_attr( $args['id_submit'] ) . '" class="button button-primary" value="' . esc_attr( $args['label_log_in'] ) . '" /> |
0 | 587 |
<input type="hidden" name="redirect_to" value="' . esc_url( $args['redirect'] ) . '" /> |
588 |
</p> |
|
5 | 589 |
' . $login_form_bottom . ' |
0 | 590 |
</form>'; |
591 |
||
9 | 592 |
if ( $args['echo'] ) { |
0 | 593 |
echo $form; |
9 | 594 |
} else { |
0 | 595 |
return $form; |
9 | 596 |
} |
0 | 597 |
} |
598 |
||
599 |
/** |
|
600 |
* Returns the URL that allows the user to retrieve the lost password |
|
601 |
* |
|
602 |
* @since 2.8.0 |
|
603 |
* |
|
604 |
* @param string $redirect Path to redirect to on login. |
|
605 |
* @return string Lost password URL. |
|
606 |
*/ |
|
607 |
function wp_lostpassword_url( $redirect = '' ) { |
|
16 | 608 |
$args = array( |
609 |
'action' => 'lostpassword', |
|
610 |
); |
|
611 |
||
9 | 612 |
if ( ! empty( $redirect ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
613 |
$args['redirect_to'] = urlencode( $redirect ); |
0 | 614 |
} |
615 |
||
16 | 616 |
if ( is_multisite() ) { |
617 |
$blog_details = get_blog_details(); |
|
618 |
$wp_login_path = $blog_details->path . 'wp-login.php'; |
|
619 |
} else { |
|
620 |
$wp_login_path = 'wp-login.php'; |
|
621 |
} |
|
622 |
||
623 |
$lostpassword_url = add_query_arg( $args, network_site_url( $wp_login_path, 'login' ) ); |
|
5 | 624 |
|
625 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
626 |
* Filters the Lost Password URL. |
5 | 627 |
* |
628 |
* @since 2.8.0 |
|
629 |
* |
|
630 |
* @param string $lostpassword_url The lost password page URL. |
|
631 |
* @param string $redirect The path to redirect to on login. |
|
632 |
*/ |
|
0 | 633 |
return apply_filters( 'lostpassword_url', $lostpassword_url, $redirect ); |
634 |
} |
|
635 |
||
636 |
/** |
|
637 |
* Display the Registration or Admin link. |
|
638 |
* |
|
639 |
* Display a link which allows the user to navigate to the registration page if |
|
640 |
* not logged in and registration is enabled or to the dashboard if logged in. |
|
641 |
* |
|
642 |
* @since 1.5.0 |
|
643 |
* |
|
5 | 644 |
* @param string $before Text to output before the link. Default `<li>`. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
645 |
* @param string $after Text to output after the link. Default `</li>`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
646 |
* @param bool $echo Default to echo and not return the link. |
16 | 647 |
* @return void|string Void if `$echo` argument is true, registration or admin link |
648 |
* if `$echo` is false. |
|
0 | 649 |
*/ |
650 |
function wp_register( $before = '<li>', $after = '</li>', $echo = true ) { |
|
651 |
if ( ! is_user_logged_in() ) { |
|
9 | 652 |
if ( get_option( 'users_can_register' ) ) { |
653 |
$link = $before . '<a href="' . esc_url( wp_registration_url() ) . '">' . __( 'Register' ) . '</a>' . $after; |
|
654 |
} else { |
|
0 | 655 |
$link = ''; |
9 | 656 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
657 |
} elseif ( current_user_can( 'read' ) ) { |
9 | 658 |
$link = $before . '<a href="' . admin_url() . '">' . __( 'Site Admin' ) . '</a>' . $after; |
0 | 659 |
} else { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
660 |
$link = ''; |
0 | 661 |
} |
662 |
||
5 | 663 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
664 |
* Filters the HTML link to the Registration or Admin page. |
5 | 665 |
* |
666 |
* Users are sent to the admin page if logged-in, or the registration page |
|
667 |
* if enabled and logged-out. |
|
668 |
* |
|
669 |
* @since 1.5.0 |
|
670 |
* |
|
671 |
* @param string $link The HTML code for the link to the Registration or Admin page. |
|
672 |
*/ |
|
673 |
$link = apply_filters( 'register', $link ); |
|
674 |
||
675 |
if ( $echo ) { |
|
676 |
echo $link; |
|
677 |
} else { |
|
678 |
return $link; |
|
679 |
} |
|
0 | 680 |
} |
681 |
||
682 |
/** |
|
683 |
* Theme container function for the 'wp_meta' action. |
|
684 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
685 |
* The {@see 'wp_meta'} action can have several purposes, depending on how you use it, |
0 | 686 |
* but one purpose might have been to allow for theme switching. |
687 |
* |
|
688 |
* @since 1.5.0 |
|
5 | 689 |
* |
690 |
* @link https://core.trac.wordpress.org/ticket/1458 Explanation of 'wp_meta' action. |
|
0 | 691 |
*/ |
692 |
function wp_meta() { |
|
5 | 693 |
/** |
694 |
* Fires before displaying echoed content in the sidebar. |
|
695 |
* |
|
696 |
* @since 1.5.0 |
|
697 |
*/ |
|
698 |
do_action( 'wp_meta' ); |
|
0 | 699 |
} |
700 |
||
701 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
702 |
* Displays information about the current site. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
703 |
* |
0 | 704 |
* @since 0.71 |
705 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
706 |
* @see get_bloginfo() For possible `$show` values |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
707 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
708 |
* @param string $show Optional. Site information to display. Default empty. |
0 | 709 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
710 |
function bloginfo( $show = '' ) { |
0 | 711 |
echo get_bloginfo( $show, 'display' ); |
712 |
} |
|
713 |
||
714 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
715 |
* Retrieves information about the current site. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
716 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
717 |
* Possible values for `$show` include: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
718 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
719 |
* - 'name' - Site title (set in Settings > General) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
720 |
* - 'description' - Site tagline (set in Settings > General) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
721 |
* - 'wpurl' - The WordPress address (URL) (set in Settings > General) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
722 |
* - 'url' - The Site address (URL) (set in Settings > General) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
723 |
* - 'admin_email' - Admin email (set in Settings > General) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
724 |
* - 'charset' - The "Encoding for pages and feeds" (set in Settings > Reading) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
725 |
* - 'version' - The current WordPress version |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
726 |
* - 'html_type' - The content-type (default: "text/html"). Themes and plugins |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
727 |
* can override the default value using the {@see 'pre_option_html_type'} filter |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
728 |
* - 'text_direction' - The text direction determined by the site's language. is_rtl() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
729 |
* should be used instead |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
730 |
* - 'language' - Language code for the current site |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
731 |
* - 'stylesheet_url' - URL to the stylesheet for the active theme. An active child theme |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
732 |
* will take precedence over this value |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
733 |
* - 'stylesheet_directory' - Directory path for the active theme. An active child theme |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
734 |
* will take precedence over this value |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
735 |
* - 'template_url' / 'template_directory' - URL of the active theme's directory. An active |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
736 |
* child theme will NOT take precedence over this value |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
737 |
* - 'pingback_url' - The pingback XML-RPC file URL (xmlrpc.php) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
738 |
* - 'atom_url' - The Atom feed URL (/feed/atom) |
9 | 739 |
* - 'rdf_url' - The RDF/RSS 1.0 feed URL (/feed/rdf) |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
740 |
* - 'rss_url' - The RSS 0.92 feed URL (/feed/rss) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
741 |
* - 'rss2_url' - The RSS 2.0 feed URL (/feed) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
742 |
* - 'comments_atom_url' - The comments Atom feed URL (/comments/feed) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
743 |
* - 'comments_rss2_url' - The comments RSS 2.0 feed URL (/comments/feed) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
744 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
745 |
* Some `$show` values are deprecated and will be removed in future versions. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
746 |
* These options will trigger the _deprecated_argument() function. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
747 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
748 |
* Deprecated arguments include: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
749 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
750 |
* - 'siteurl' - Use 'url' instead |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
751 |
* - 'home' - Use 'url' instead |
0 | 752 |
* |
753 |
* @since 0.71 |
|
754 |
* |
|
16 | 755 |
* @global string $wp_version The WordPress version string. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
756 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
757 |
* @param string $show Optional. Site info to retrieve. Default empty (site name). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
758 |
* @param string $filter Optional. How to filter what is retrieved. Default 'raw'. |
0 | 759 |
* @return string Mostly string values, might be empty. |
760 |
*/ |
|
761 |
function get_bloginfo( $show = '', $filter = 'raw' ) { |
|
9 | 762 |
switch ( $show ) { |
16 | 763 |
case 'home': // Deprecated. |
764 |
case 'siteurl': // Deprecated. |
|
9 | 765 |
_deprecated_argument( |
766 |
__FUNCTION__, |
|
767 |
'2.2.0', |
|
768 |
sprintf( |
|
16 | 769 |
/* translators: 1: 'siteurl'/'home' argument, 2: bloginfo() function name, 3: 'url' argument. */ |
9 | 770 |
__( 'The %1$s option is deprecated for the family of %2$s functions. Use the %3$s option instead.' ), |
771 |
'<code>' . $show . '</code>', |
|
772 |
'<code>bloginfo()</code>', |
|
773 |
'<code>url</code>' |
|
774 |
) |
|
775 |
); |
|
776 |
// Intentional fall-through to be handled by the 'url' case. |
|
777 |
case 'url': |
|
0 | 778 |
$output = home_url(); |
779 |
break; |
|
9 | 780 |
case 'wpurl': |
0 | 781 |
$output = site_url(); |
782 |
break; |
|
783 |
case 'description': |
|
9 | 784 |
$output = get_option( 'blogdescription' ); |
0 | 785 |
break; |
786 |
case 'rdf_url': |
|
9 | 787 |
$output = get_feed_link( 'rdf' ); |
0 | 788 |
break; |
789 |
case 'rss_url': |
|
9 | 790 |
$output = get_feed_link( 'rss' ); |
0 | 791 |
break; |
792 |
case 'rss2_url': |
|
9 | 793 |
$output = get_feed_link( 'rss2' ); |
0 | 794 |
break; |
795 |
case 'atom_url': |
|
9 | 796 |
$output = get_feed_link( 'atom' ); |
0 | 797 |
break; |
798 |
case 'comments_atom_url': |
|
9 | 799 |
$output = get_feed_link( 'comments_atom' ); |
0 | 800 |
break; |
801 |
case 'comments_rss2_url': |
|
9 | 802 |
$output = get_feed_link( 'comments_rss2' ); |
0 | 803 |
break; |
804 |
case 'pingback_url': |
|
805 |
$output = site_url( 'xmlrpc.php' ); |
|
806 |
break; |
|
807 |
case 'stylesheet_url': |
|
808 |
$output = get_stylesheet_uri(); |
|
809 |
break; |
|
810 |
case 'stylesheet_directory': |
|
811 |
$output = get_stylesheet_directory_uri(); |
|
812 |
break; |
|
813 |
case 'template_directory': |
|
814 |
case 'template_url': |
|
815 |
$output = get_template_directory_uri(); |
|
816 |
break; |
|
817 |
case 'admin_email': |
|
9 | 818 |
$output = get_option( 'admin_email' ); |
0 | 819 |
break; |
820 |
case 'charset': |
|
9 | 821 |
$output = get_option( 'blog_charset' ); |
16 | 822 |
if ( '' === $output ) { |
9 | 823 |
$output = 'UTF-8'; |
824 |
} |
|
0 | 825 |
break; |
9 | 826 |
case 'html_type': |
827 |
$output = get_option( 'html_type' ); |
|
0 | 828 |
break; |
829 |
case 'version': |
|
830 |
global $wp_version; |
|
831 |
$output = $wp_version; |
|
832 |
break; |
|
833 |
case 'language': |
|
16 | 834 |
/* |
835 |
* translators: Translate this to the correct language tag for your locale, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
836 |
* see https://www.w3.org/International/articles/language-tags/ for reference. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
837 |
* Do not translate into your own language. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
838 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
839 |
$output = __( 'html_lang_attribute' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
840 |
if ( 'html_lang_attribute' === $output || preg_match( '/[^a-zA-Z0-9-]/', $output ) ) { |
9 | 841 |
$output = determine_locale(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
842 |
$output = str_replace( '_', '-', $output ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
843 |
} |
0 | 844 |
break; |
845 |
case 'text_direction': |
|
9 | 846 |
_deprecated_argument( |
847 |
__FUNCTION__, |
|
848 |
'2.2.0', |
|
849 |
sprintf( |
|
16 | 850 |
/* translators: 1: 'text_direction' argument, 2: bloginfo() function name, 3: is_rtl() function name. */ |
9 | 851 |
__( 'The %1$s option is deprecated for the family of %2$s functions. Use the %3$s function instead.' ), |
852 |
'<code>' . $show . '</code>', |
|
853 |
'<code>bloginfo()</code>', |
|
854 |
'<code>is_rtl()</code>' |
|
855 |
) |
|
856 |
); |
|
0 | 857 |
if ( function_exists( 'is_rtl' ) ) { |
858 |
$output = is_rtl() ? 'rtl' : 'ltr'; |
|
859 |
} else { |
|
860 |
$output = 'ltr'; |
|
861 |
} |
|
862 |
break; |
|
863 |
case 'name': |
|
864 |
default: |
|
9 | 865 |
$output = get_option( 'blogname' ); |
0 | 866 |
break; |
867 |
} |
|
868 |
||
869 |
$url = true; |
|
9 | 870 |
if ( strpos( $show, 'url' ) === false && |
871 |
strpos( $show, 'directory' ) === false && |
|
872 |
strpos( $show, 'home' ) === false ) { |
|
0 | 873 |
$url = false; |
9 | 874 |
} |
0 | 875 |
|
16 | 876 |
if ( 'display' === $filter ) { |
5 | 877 |
if ( $url ) { |
878 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
879 |
* Filters the URL returned by get_bloginfo(). |
5 | 880 |
* |
881 |
* @since 2.0.5 |
|
882 |
* |
|
16 | 883 |
* @param string $output The URL returned by bloginfo(). |
884 |
* @param string $show Type of information requested. |
|
5 | 885 |
*/ |
886 |
$output = apply_filters( 'bloginfo_url', $output, $show ); |
|
887 |
} else { |
|
888 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
889 |
* Filters the site information returned by get_bloginfo(). |
5 | 890 |
* |
891 |
* @since 0.71 |
|
892 |
* |
|
16 | 893 |
* @param mixed $output The requested non-URL site information. |
894 |
* @param string $show Type of information requested. |
|
5 | 895 |
*/ |
896 |
$output = apply_filters( 'bloginfo', $output, $show ); |
|
897 |
} |
|
0 | 898 |
} |
899 |
||
900 |
return $output; |
|
901 |
} |
|
902 |
||
903 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
904 |
* Returns the Site Icon URL. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
905 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
906 |
* @since 4.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
907 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
908 |
* @param int $size Optional. Size of the site icon. Default 512 (pixels). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
909 |
* @param string $url Optional. Fallback url if no site icon is found. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
910 |
* @param int $blog_id Optional. ID of the blog to get the site icon for. Default current blog. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
911 |
* @return string Site Icon URL. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
912 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
913 |
function get_site_icon_url( $size = 512, $url = '', $blog_id = 0 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
914 |
$switched_blog = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
915 |
|
16 | 916 |
if ( is_multisite() && ! empty( $blog_id ) && get_current_blog_id() !== (int) $blog_id ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
917 |
switch_to_blog( $blog_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
918 |
$switched_blog = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
919 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
920 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
921 |
$site_icon_id = get_option( 'site_icon' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
922 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
923 |
if ( $site_icon_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
924 |
if ( $size >= 512 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
925 |
$size_data = 'full'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
926 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
927 |
$size_data = array( $size, $size ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
928 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
929 |
$url = wp_get_attachment_image_url( $site_icon_id, $size_data ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
930 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
931 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
932 |
if ( $switched_blog ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
933 |
restore_current_blog(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
934 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
935 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
936 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
937 |
* Filters the site icon URL. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
938 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
939 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
940 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
941 |
* @param string $url Site icon URL. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
942 |
* @param int $size Size of the site icon. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
943 |
* @param int $blog_id ID of the blog to get the site icon for. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
944 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
945 |
return apply_filters( 'get_site_icon_url', $url, $size, $blog_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
946 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
947 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
948 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
949 |
* Displays the Site Icon URL. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
950 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
951 |
* @since 4.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
952 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
953 |
* @param int $size Optional. Size of the site icon. Default 512 (pixels). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
954 |
* @param string $url Optional. Fallback url if no site icon is found. Default empty. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
955 |
* @param int $blog_id Optional. ID of the blog to get the site icon for. Default current blog. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
956 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
957 |
function site_icon_url( $size = 512, $url = '', $blog_id = 0 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
958 |
echo esc_url( get_site_icon_url( $size, $url, $blog_id ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
959 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
960 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
961 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
962 |
* Whether the site has a Site Icon. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
963 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
964 |
* @since 4.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
965 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
966 |
* @param int $blog_id Optional. ID of the blog in question. Default current blog. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
967 |
* @return bool Whether the site has a site icon or not. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
968 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
969 |
function has_site_icon( $blog_id = 0 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
970 |
return (bool) get_site_icon_url( 512, '', $blog_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
971 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
972 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
973 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
974 |
* Determines whether the site has a custom logo. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
975 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
976 |
* @since 4.5.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
977 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
978 |
* @param int $blog_id Optional. ID of the blog in question. Default is the ID of the current blog. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
979 |
* @return bool Whether the site has a custom logo or not. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
980 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
981 |
function has_custom_logo( $blog_id = 0 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
982 |
$switched_blog = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
983 |
|
16 | 984 |
if ( is_multisite() && ! empty( $blog_id ) && get_current_blog_id() !== (int) $blog_id ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
985 |
switch_to_blog( $blog_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
986 |
$switched_blog = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
987 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
988 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
989 |
$custom_logo_id = get_theme_mod( 'custom_logo' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
990 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
991 |
if ( $switched_blog ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
992 |
restore_current_blog(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
993 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
994 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
995 |
return (bool) $custom_logo_id; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
996 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
997 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
998 |
/** |
16 | 999 |
* Returns a custom logo, linked to home unless the theme supports removing the link on the home page. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1000 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1001 |
* @since 4.5.0 |
16 | 1002 |
* @since 5.5.0 Added option to remove the link on the home page with `unlink-homepage-logo` theme support. |
1003 |
* @since 5.5.1 Disabled lazy-loading by default. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1004 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1005 |
* @param int $blog_id Optional. ID of the blog in question. Default is the ID of the current blog. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1006 |
* @return string Custom logo markup. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1007 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1008 |
function get_custom_logo( $blog_id = 0 ) { |
9 | 1009 |
$html = ''; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1010 |
$switched_blog = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1011 |
|
16 | 1012 |
if ( is_multisite() && ! empty( $blog_id ) && get_current_blog_id() !== (int) $blog_id ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1013 |
switch_to_blog( $blog_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1014 |
$switched_blog = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1015 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1016 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1017 |
$custom_logo_id = get_theme_mod( 'custom_logo' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1018 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1019 |
// We have a logo. Logo is go. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1020 |
if ( $custom_logo_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1021 |
$custom_logo_attr = array( |
16 | 1022 |
'class' => 'custom-logo', |
1023 |
'loading' => false, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1024 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1025 |
|
16 | 1026 |
$unlink_homepage_logo = (bool) get_theme_support( 'custom-logo', 'unlink-homepage-logo' ); |
1027 |
||
1028 |
if ( $unlink_homepage_logo && is_front_page() && ! is_paged() ) { |
|
1029 |
/* |
|
1030 |
* If on the home page, set the logo alt attribute to an empty string, |
|
1031 |
* as the image is decorative and doesn't need its purpose to be described. |
|
1032 |
*/ |
|
1033 |
$custom_logo_attr['alt'] = ''; |
|
1034 |
} else { |
|
1035 |
/* |
|
1036 |
* If the logo alt attribute is empty, get the site title and explicitly pass it |
|
1037 |
* to the attributes used by wp_get_attachment_image(). |
|
1038 |
*/ |
|
1039 |
$image_alt = get_post_meta( $custom_logo_id, '_wp_attachment_image_alt', true ); |
|
1040 |
if ( empty( $image_alt ) ) { |
|
1041 |
$custom_logo_attr['alt'] = get_bloginfo( 'name', 'display' ); |
|
1042 |
} |
|
1043 |
} |
|
1044 |
||
1045 |
/** |
|
1046 |
* Filters the list of custom logo image attributes. |
|
1047 |
* |
|
1048 |
* @since 5.5.0 |
|
1049 |
* |
|
1050 |
* @param array $custom_logo_attr Custom logo image attributes. |
|
1051 |
* @param int $custom_logo_id Custom logo attachment ID. |
|
1052 |
* @param int $blog_id ID of the blog to get the custom logo for. |
|
1053 |
*/ |
|
1054 |
$custom_logo_attr = apply_filters( 'get_custom_logo_image_attributes', $custom_logo_attr, $custom_logo_id, $blog_id ); |
|
1055 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1056 |
/* |
16 | 1057 |
* If the alt attribute is not empty, there's no need to explicitly pass it |
1058 |
* because wp_get_attachment_image() already adds the alt attribute. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1059 |
*/ |
16 | 1060 |
$image = wp_get_attachment_image( $custom_logo_id, 'full', false, $custom_logo_attr ); |
1061 |
||
1062 |
if ( $unlink_homepage_logo && is_front_page() && ! is_paged() ) { |
|
1063 |
// If on the home page, don't link the logo to home. |
|
1064 |
$html = sprintf( |
|
1065 |
'<span class="custom-logo-link">%1$s</span>', |
|
1066 |
$image |
|
1067 |
); |
|
1068 |
} else { |
|
1069 |
$aria_current = is_front_page() && ! is_paged() ? ' aria-current="page"' : ''; |
|
1070 |
||
1071 |
$html = sprintf( |
|
1072 |
'<a href="%1$s" class="custom-logo-link" rel="home"%2$s>%3$s</a>', |
|
1073 |
esc_url( home_url( '/' ) ), |
|
1074 |
$aria_current, |
|
1075 |
$image |
|
1076 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1077 |
} |
9 | 1078 |
} elseif ( is_customize_preview() ) { |
1079 |
// If no logo is set but we're in the Customizer, leave a placeholder (needed for the live preview). |
|
1080 |
$html = sprintf( |
|
1081 |
'<a href="%1$s" class="custom-logo-link" style="display:none;"><img class="custom-logo"/></a>', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1082 |
esc_url( home_url( '/' ) ) |
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 |
if ( $switched_blog ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1087 |
restore_current_blog(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1088 |
} |
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 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1091 |
* Filters the custom logo output. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1092 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1093 |
* @since 4.5.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1094 |
* @since 4.6.0 Added the `$blog_id` parameter. |
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 |
* @param string $html Custom logo HTML output. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1097 |
* @param int $blog_id ID of the blog to get the custom logo for. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1098 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1099 |
return apply_filters( 'get_custom_logo', $html, $blog_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1100 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1101 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1102 |
/** |
16 | 1103 |
* Displays a custom logo, linked to home unless the theme supports removing the link on the home page. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1104 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1105 |
* @since 4.5.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1106 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1107 |
* @param int $blog_id Optional. ID of the blog in question. Default is the ID of the current blog. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1108 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1109 |
function the_custom_logo( $blog_id = 0 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1110 |
echo get_custom_logo( $blog_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1111 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1112 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1113 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1114 |
* Returns document title for the current page. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1115 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1116 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1117 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1118 |
* @global int $page Page number of a single post. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1119 |
* @global int $paged Page number of a list of posts. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1120 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1121 |
* @return string Tag with the document title. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1122 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1123 |
function wp_get_document_title() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1124 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1125 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1126 |
* Filters the document title before it is generated. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1127 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1128 |
* Passing a non-empty value will short-circuit wp_get_document_title(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1129 |
* returning that value instead. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1130 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1131 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1132 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1133 |
* @param string $title The document title. Default empty string. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1134 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1135 |
$title = apply_filters( 'pre_get_document_title', '' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1136 |
if ( ! empty( $title ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1137 |
return $title; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1138 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1139 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1140 |
global $page, $paged; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1141 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1142 |
$title = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1143 |
'title' => '', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1144 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1145 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1146 |
// If it's a 404 page, use a "Page not found" title. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1147 |
if ( is_404() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1148 |
$title['title'] = __( 'Page not found' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1149 |
|
9 | 1150 |
// If it's a search, use a dynamic search results title. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1151 |
} elseif ( is_search() ) { |
16 | 1152 |
/* translators: %s: Search query. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1153 |
$title['title'] = sprintf( __( 'Search Results for “%s”' ), get_search_query() ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1154 |
|
9 | 1155 |
// If on the front page, use the site title. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1156 |
} elseif ( is_front_page() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1157 |
$title['title'] = get_bloginfo( 'name', 'display' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1158 |
|
9 | 1159 |
// If on a post type archive, use the post type archive title. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1160 |
} elseif ( is_post_type_archive() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1161 |
$title['title'] = post_type_archive_title( '', false ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1162 |
|
9 | 1163 |
// If on a taxonomy archive, use the term title. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1164 |
} elseif ( is_tax() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1165 |
$title['title'] = single_term_title( '', false ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1166 |
|
9 | 1167 |
/* |
16 | 1168 |
* If we're on the blog page that is not the homepage |
1169 |
* or a single post of any post type, use the post title. |
|
9 | 1170 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1171 |
} elseif ( is_home() || is_singular() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1172 |
$title['title'] = single_post_title( '', false ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1173 |
|
9 | 1174 |
// If on a category or tag archive, use the term title. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1175 |
} elseif ( is_category() || is_tag() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1176 |
$title['title'] = single_term_title( '', false ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1177 |
|
9 | 1178 |
// If on an author archive, use the author's display name. |
16 | 1179 |
} elseif ( is_author() && get_queried_object() ) { |
1180 |
$author = get_queried_object(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1181 |
$title['title'] = $author->display_name; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1182 |
|
9 | 1183 |
// If it's a date archive, use the date as the title. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1184 |
} elseif ( is_year() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1185 |
$title['title'] = get_the_date( _x( 'Y', 'yearly archives date format' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1186 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1187 |
} elseif ( is_month() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1188 |
$title['title'] = get_the_date( _x( 'F Y', 'monthly archives date format' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1189 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1190 |
} elseif ( is_day() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1191 |
$title['title'] = get_the_date(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1192 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1193 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1194 |
// Add a page number if necessary. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1195 |
if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) { |
16 | 1196 |
/* translators: %s: Page number. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1197 |
$title['page'] = sprintf( __( 'Page %s' ), max( $paged, $page ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1198 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1199 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1200 |
// Append the description or site title to give context. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1201 |
if ( is_front_page() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1202 |
$title['tagline'] = get_bloginfo( 'description', 'display' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1203 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1204 |
$title['site'] = get_bloginfo( 'name', 'display' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1205 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1206 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1207 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1208 |
* Filters the separator for the document title. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1209 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1210 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1211 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1212 |
* @param string $sep Document title separator. Default '-'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1213 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1214 |
$sep = apply_filters( 'document_title_separator', '-' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1215 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1216 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1217 |
* Filters the parts of the document title. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1218 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1219 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1220 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1221 |
* @param array $title { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1222 |
* The document title parts. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1223 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1224 |
* @type string $title Title of the viewed page. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1225 |
* @type string $page Optional. Page number if paginated. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1226 |
* @type string $tagline Optional. Site description when on home page. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1227 |
* @type string $site Optional. Site title when not on home page. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1228 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1229 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1230 |
$title = apply_filters( 'document_title_parts', $title ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1231 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1232 |
$title = implode( " $sep ", array_filter( $title ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1233 |
$title = wptexturize( $title ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1234 |
$title = convert_chars( $title ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1235 |
$title = esc_html( $title ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1236 |
$title = capital_P_dangit( $title ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1237 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1238 |
return $title; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1239 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1240 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1241 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1242 |
* Displays title tag with content. |
5 | 1243 |
* |
1244 |
* @ignore |
|
1245 |
* @since 4.1.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1246 |
* @since 4.4.0 Improved title output replaced `wp_title()`. |
5 | 1247 |
* @access private |
1248 |
*/ |
|
1249 |
function _wp_render_title_tag() { |
|
1250 |
if ( ! current_theme_supports( 'title-tag' ) ) { |
|
1251 |
return; |
|
1252 |
} |
|
1253 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1254 |
echo '<title>' . wp_get_document_title() . '</title>' . "\n"; |
5 | 1255 |
} |
1256 |
||
1257 |
/** |
|
0 | 1258 |
* Display or retrieve page title for all areas of blog. |
1259 |
* |
|
1260 |
* By default, the page title will display the separator before the page title, |
|
1261 |
* so that the blog title will be before the page title. This is not good for |
|
1262 |
* title display, since the blog title shows up on most tabs and not what is |
|
1263 |
* important, which is the page that the user is looking at. |
|
1264 |
* |
|
1265 |
* There are also SEO benefits to having the blog title after or to the 'right' |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1266 |
* of the page title. However, it is mostly common sense to have the blog title |
0 | 1267 |
* to the right with most browsers supporting tabs. You can achieve this by |
1268 |
* using the seplocation parameter and setting the value to 'right'. This change |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1269 |
* was introduced around 2.5.0, in case backward compatibility of themes is |
0 | 1270 |
* important. |
1271 |
* |
|
1272 |
* @since 1.0.0 |
|
1273 |
* |
|
16 | 1274 |
* @global WP_Locale $wp_locale WordPress date and time locale object. |
1275 |
* |
|
1276 |
* @param string $sep Optional. How to separate the various items within the page title. |
|
1277 |
* Default '»'. |
|
1278 |
* @param bool $display Optional. Whether to display or retrieve title. Default true. |
|
1279 |
* @param string $seplocation Optional. Location of the separator ('left' or 'right'). |
|
0 | 1280 |
* @return string|null String on retrieve, null when displaying. |
1281 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1282 |
function wp_title( $sep = '»', $display = true, $seplocation = '' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1283 |
global $wp_locale; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1284 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1285 |
$m = get_query_var( 'm' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1286 |
$year = get_query_var( 'year' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1287 |
$monthnum = get_query_var( 'monthnum' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1288 |
$day = get_query_var( 'day' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1289 |
$search = get_query_var( 's' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1290 |
$title = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1291 |
|
16 | 1292 |
$t_sep = '%WP_TITLE_SEP%'; // Temporary separator, for accurate flipping, if necessary. |
1293 |
||
1294 |
// If there is a post. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1295 |
if ( is_single() || ( is_home() && ! is_front_page() ) || ( is_page() && ! is_front_page() ) ) { |
0 | 1296 |
$title = single_post_title( '', false ); |
1297 |
} |
|
1298 |
||
16 | 1299 |
// If there's a post type archive. |
0 | 1300 |
if ( is_post_type_archive() ) { |
1301 |
$post_type = get_query_var( 'post_type' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1302 |
if ( is_array( $post_type ) ) { |
0 | 1303 |
$post_type = reset( $post_type ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1304 |
} |
0 | 1305 |
$post_type_object = get_post_type_object( $post_type ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1306 |
if ( ! $post_type_object->has_archive ) { |
0 | 1307 |
$title = post_type_archive_title( '', false ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1308 |
} |
0 | 1309 |
} |
1310 |
||
16 | 1311 |
// If there's a category or tag. |
0 | 1312 |
if ( is_category() || is_tag() ) { |
1313 |
$title = single_term_title( '', false ); |
|
1314 |
} |
|
1315 |
||
16 | 1316 |
// If there's a taxonomy. |
0 | 1317 |
if ( is_tax() ) { |
1318 |
$term = get_queried_object(); |
|
1319 |
if ( $term ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1320 |
$tax = get_taxonomy( $term->taxonomy ); |
0 | 1321 |
$title = single_term_title( $tax->labels->name . $t_sep, false ); |
1322 |
} |
|
1323 |
} |
|
1324 |
||
16 | 1325 |
// If there's an author. |
5 | 1326 |
if ( is_author() && ! is_post_type_archive() ) { |
0 | 1327 |
$author = get_queried_object(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1328 |
if ( $author ) { |
0 | 1329 |
$title = $author->display_name; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1330 |
} |
0 | 1331 |
} |
1332 |
||
1333 |
// Post type archives with has_archive should override terms. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1334 |
if ( is_post_type_archive() && $post_type_object->has_archive ) { |
0 | 1335 |
$title = post_type_archive_title( '', false ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1336 |
} |
0 | 1337 |
|
16 | 1338 |
// If there's a month. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1339 |
if ( is_archive() && ! empty( $m ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1340 |
$my_year = substr( $m, 0, 4 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1341 |
$my_month = $wp_locale->get_month( substr( $m, 4, 2 ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1342 |
$my_day = intval( substr( $m, 6, 2 ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1343 |
$title = $my_year . ( $my_month ? $t_sep . $my_month : '' ) . ( $my_day ? $t_sep . $my_day : '' ); |
0 | 1344 |
} |
1345 |
||
16 | 1346 |
// If there's a year. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1347 |
if ( is_archive() && ! empty( $year ) ) { |
0 | 1348 |
$title = $year; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1349 |
if ( ! empty( $monthnum ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1350 |
$title .= $t_sep . $wp_locale->get_month( $monthnum ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1351 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1352 |
if ( ! empty( $day ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1353 |
$title .= $t_sep . zeroise( $day, 2 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1354 |
} |
0 | 1355 |
} |
1356 |
||
16 | 1357 |
// If it's a search. |
0 | 1358 |
if ( is_search() ) { |
16 | 1359 |
/* translators: 1: Separator, 2: Search query. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1360 |
$title = sprintf( __( 'Search Results %1$s %2$s' ), $t_sep, strip_tags( $search ) ); |
0 | 1361 |
} |
1362 |
||
16 | 1363 |
// If it's a 404 page. |
0 | 1364 |
if ( is_404() ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1365 |
$title = __( 'Page not found' ); |
0 | 1366 |
} |
1367 |
||
1368 |
$prefix = ''; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1369 |
if ( ! empty( $title ) ) { |
0 | 1370 |
$prefix = " $sep "; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1371 |
} |
0 | 1372 |
|
5 | 1373 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1374 |
* Filters the parts of the page title. |
5 | 1375 |
* |
1376 |
* @since 4.0.0 |
|
1377 |
* |
|
16 | 1378 |
* @param string[] $title_array Array of parts of the page title. |
5 | 1379 |
*/ |
1380 |
$title_array = apply_filters( 'wp_title_parts', explode( $t_sep, $title ) ); |
|
1381 |
||
16 | 1382 |
// Determines position of the separator and direction of the breadcrumb. |
1383 |
if ( 'right' === $seplocation ) { // Separator on right, so reverse the order. |
|
0 | 1384 |
$title_array = array_reverse( $title_array ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1385 |
$title = implode( " $sep ", $title_array ) . $prefix; |
0 | 1386 |
} else { |
1387 |
$title = $prefix . implode( " $sep ", $title_array ); |
|
1388 |
} |
|
1389 |
||
5 | 1390 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1391 |
* Filters the text of the page title. |
5 | 1392 |
* |
1393 |
* @since 2.0.0 |
|
1394 |
* |
|
16 | 1395 |
* @param string $title Page title. |
1396 |
* @param string $sep Title separator. |
|
1397 |
* @param string $seplocation Location of the separator ('left' or 'right'). |
|
5 | 1398 |
*/ |
1399 |
$title = apply_filters( 'wp_title', $title, $sep, $seplocation ); |
|
0 | 1400 |
|
16 | 1401 |
// Send it out. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1402 |
if ( $display ) { |
0 | 1403 |
echo $title; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1404 |
} else { |
0 | 1405 |
return $title; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1406 |
} |
0 | 1407 |
} |
1408 |
||
1409 |
/** |
|
1410 |
* Display or retrieve page title for post. |
|
1411 |
* |
|
1412 |
* This is optimized for single.php template file for displaying the post title. |
|
1413 |
* |
|
1414 |
* It does not support placing the separator after the title, but by leaving the |
|
1415 |
* prefix parameter empty, you can set the title separator manually. The prefix |
|
1416 |
* does not automatically place a space between the prefix, so if there should |
|
1417 |
* be a space, the parameter value will need to have it at the end. |
|
1418 |
* |
|
1419 |
* @since 0.71 |
|
1420 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1421 |
* @param string $prefix Optional. What to display before the title. |
16 | 1422 |
* @param bool $display Optional. Whether to display or retrieve title. Default true. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1423 |
* @return string|void Title when retrieving. |
0 | 1424 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1425 |
function single_post_title( $prefix = '', $display = true ) { |
0 | 1426 |
$_post = get_queried_object(); |
1427 |
||
9 | 1428 |
if ( ! isset( $_post->post_title ) ) { |
0 | 1429 |
return; |
9 | 1430 |
} |
0 | 1431 |
|
5 | 1432 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1433 |
* Filters the page title for a single post. |
5 | 1434 |
* |
1435 |
* @since 0.71 |
|
1436 |
* |
|
16 | 1437 |
* @param string $_post_title The single post page title. |
1438 |
* @param WP_Post $_post The current post. |
|
5 | 1439 |
*/ |
1440 |
$title = apply_filters( 'single_post_title', $_post->post_title, $_post ); |
|
9 | 1441 |
if ( $display ) { |
0 | 1442 |
echo $prefix . $title; |
9 | 1443 |
} else { |
0 | 1444 |
return $prefix . $title; |
9 | 1445 |
} |
0 | 1446 |
} |
1447 |
||
1448 |
/** |
|
1449 |
* Display or retrieve title for a post type archive. |
|
1450 |
* |
|
1451 |
* This is optimized for archive.php and archive-{$post_type}.php template files |
|
1452 |
* for displaying the title of the post type. |
|
1453 |
* |
|
1454 |
* @since 3.1.0 |
|
1455 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1456 |
* @param string $prefix Optional. What to display before the title. |
16 | 1457 |
* @param bool $display Optional. Whether to display or retrieve title. Default true. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1458 |
* @return string|void Title when retrieving, null when displaying or failure. |
0 | 1459 |
*/ |
1460 |
function post_type_archive_title( $prefix = '', $display = true ) { |
|
9 | 1461 |
if ( ! is_post_type_archive() ) { |
0 | 1462 |
return; |
9 | 1463 |
} |
0 | 1464 |
|
1465 |
$post_type = get_query_var( 'post_type' ); |
|
9 | 1466 |
if ( is_array( $post_type ) ) { |
0 | 1467 |
$post_type = reset( $post_type ); |
9 | 1468 |
} |
0 | 1469 |
|
1470 |
$post_type_obj = get_post_type_object( $post_type ); |
|
5 | 1471 |
|
1472 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1473 |
* Filters the post type archive title. |
5 | 1474 |
* |
1475 |
* @since 3.1.0 |
|
1476 |
* |
|
1477 |
* @param string $post_type_name Post type 'name' label. |
|
1478 |
* @param string $post_type Post type. |
|
1479 |
*/ |
|
1480 |
$title = apply_filters( 'post_type_archive_title', $post_type_obj->labels->name, $post_type ); |
|
0 | 1481 |
|
9 | 1482 |
if ( $display ) { |
0 | 1483 |
echo $prefix . $title; |
9 | 1484 |
} else { |
0 | 1485 |
return $prefix . $title; |
9 | 1486 |
} |
0 | 1487 |
} |
1488 |
||
1489 |
/** |
|
1490 |
* Display or retrieve page title for category archive. |
|
1491 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1492 |
* Useful for category template files for displaying the category page title. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1493 |
* The prefix does not automatically place a space between the prefix, so if |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1494 |
* there should be a space, the parameter value will need to have it at the end. |
0 | 1495 |
* |
1496 |
* @since 0.71 |
|
1497 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1498 |
* @param string $prefix Optional. What to display before the title. |
16 | 1499 |
* @param bool $display Optional. Whether to display or retrieve title. Default true. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1500 |
* @return string|void Title when retrieving. |
0 | 1501 |
*/ |
1502 |
function single_cat_title( $prefix = '', $display = true ) { |
|
1503 |
return single_term_title( $prefix, $display ); |
|
1504 |
} |
|
1505 |
||
1506 |
/** |
|
1507 |
* Display or retrieve page title for tag post archive. |
|
1508 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1509 |
* Useful for tag template files for displaying the tag page title. The prefix |
0 | 1510 |
* does not automatically place a space between the prefix, so if there should |
1511 |
* be a space, the parameter value will need to have it at the end. |
|
1512 |
* |
|
1513 |
* @since 2.3.0 |
|
1514 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1515 |
* @param string $prefix Optional. What to display before the title. |
16 | 1516 |
* @param bool $display Optional. Whether to display or retrieve title. Default true. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1517 |
* @return string|void Title when retrieving. |
0 | 1518 |
*/ |
1519 |
function single_tag_title( $prefix = '', $display = true ) { |
|
1520 |
return single_term_title( $prefix, $display ); |
|
1521 |
} |
|
1522 |
||
1523 |
/** |
|
1524 |
* Display or retrieve page title for taxonomy term archive. |
|
1525 |
* |
|
1526 |
* Useful for taxonomy term template files for displaying the taxonomy term page title. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1527 |
* The prefix does not automatically place a space between the prefix, so if there should |
0 | 1528 |
* be a space, the parameter value will need to have it at the end. |
1529 |
* |
|
1530 |
* @since 3.1.0 |
|
1531 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1532 |
* @param string $prefix Optional. What to display before the title. |
16 | 1533 |
* @param bool $display Optional. Whether to display or retrieve title. Default true. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1534 |
* @return string|void Title when retrieving. |
0 | 1535 |
*/ |
1536 |
function single_term_title( $prefix = '', $display = true ) { |
|
1537 |
$term = get_queried_object(); |
|
1538 |
||
9 | 1539 |
if ( ! $term ) { |
0 | 1540 |
return; |
9 | 1541 |
} |
0 | 1542 |
|
5 | 1543 |
if ( is_category() ) { |
1544 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1545 |
* Filters the category archive page title. |
5 | 1546 |
* |
1547 |
* @since 2.0.10 |
|
1548 |
* |
|
1549 |
* @param string $term_name Category name for archive being displayed. |
|
1550 |
*/ |
|
0 | 1551 |
$term_name = apply_filters( 'single_cat_title', $term->name ); |
5 | 1552 |
} elseif ( is_tag() ) { |
1553 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1554 |
* Filters the tag archive page title. |
5 | 1555 |
* |
1556 |
* @since 2.3.0 |
|
1557 |
* |
|
1558 |
* @param string $term_name Tag name for archive being displayed. |
|
1559 |
*/ |
|
0 | 1560 |
$term_name = apply_filters( 'single_tag_title', $term->name ); |
5 | 1561 |
} elseif ( is_tax() ) { |
1562 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1563 |
* Filters the custom taxonomy archive page title. |
5 | 1564 |
* |
1565 |
* @since 3.1.0 |
|
1566 |
* |
|
1567 |
* @param string $term_name Term name for archive being displayed. |
|
1568 |
*/ |
|
0 | 1569 |
$term_name = apply_filters( 'single_term_title', $term->name ); |
5 | 1570 |
} else { |
0 | 1571 |
return; |
5 | 1572 |
} |
0 | 1573 |
|
9 | 1574 |
if ( empty( $term_name ) ) { |
0 | 1575 |
return; |
9 | 1576 |
} |
1577 |
||
1578 |
if ( $display ) { |
|
0 | 1579 |
echo $prefix . $term_name; |
9 | 1580 |
} else { |
0 | 1581 |
return $prefix . $term_name; |
9 | 1582 |
} |
0 | 1583 |
} |
1584 |
||
1585 |
/** |
|
1586 |
* Display or retrieve page title for post archive based on date. |
|
1587 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1588 |
* Useful for when the template only needs to display the month and year, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1589 |
* if either are available. The prefix does not automatically place a space |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1590 |
* between the prefix, so if there should be a space, the parameter value |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1591 |
* will need to have it at the end. |
0 | 1592 |
* |
1593 |
* @since 0.71 |
|
1594 |
* |
|
16 | 1595 |
* @global WP_Locale $wp_locale WordPress date and time locale object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1596 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1597 |
* @param string $prefix Optional. What to display before the title. |
16 | 1598 |
* @param bool $display Optional. Whether to display or retrieve title. Default true. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1599 |
* @return string|void Title when retrieving. |
0 | 1600 |
*/ |
9 | 1601 |
function single_month_title( $prefix = '', $display = true ) { |
0 | 1602 |
global $wp_locale; |
1603 |
||
9 | 1604 |
$m = get_query_var( 'm' ); |
1605 |
$year = get_query_var( 'year' ); |
|
1606 |
$monthnum = get_query_var( 'monthnum' ); |
|
1607 |
||
1608 |
if ( ! empty( $monthnum ) && ! empty( $year ) ) { |
|
1609 |
$my_year = $year; |
|
1610 |
$my_month = $wp_locale->get_month( $monthnum ); |
|
1611 |
} elseif ( ! empty( $m ) ) { |
|
1612 |
$my_year = substr( $m, 0, 4 ); |
|
1613 |
$my_month = $wp_locale->get_month( substr( $m, 4, 2 ) ); |
|
0 | 1614 |
} |
1615 |
||
9 | 1616 |
if ( empty( $my_month ) ) { |
0 | 1617 |
return false; |
9 | 1618 |
} |
0 | 1619 |
|
1620 |
$result = $prefix . $my_month . $prefix . $my_year; |
|
1621 |
||
9 | 1622 |
if ( ! $display ) { |
0 | 1623 |
return $result; |
9 | 1624 |
} |
0 | 1625 |
echo $result; |
1626 |
} |
|
1627 |
||
1628 |
/** |
|
5 | 1629 |
* Display the archive title based on the queried object. |
1630 |
* |
|
1631 |
* @since 4.1.0 |
|
1632 |
* |
|
1633 |
* @see get_the_archive_title() |
|
1634 |
* |
|
1635 |
* @param string $before Optional. Content to prepend to the title. Default empty. |
|
1636 |
* @param string $after Optional. Content to append to the title. Default empty. |
|
1637 |
*/ |
|
1638 |
function the_archive_title( $before = '', $after = '' ) { |
|
1639 |
$title = get_the_archive_title(); |
|
1640 |
||
1641 |
if ( ! empty( $title ) ) { |
|
1642 |
echo $before . $title . $after; |
|
1643 |
} |
|
1644 |
} |
|
1645 |
||
1646 |
/** |
|
1647 |
* Retrieve the archive title based on the queried object. |
|
1648 |
* |
|
1649 |
* @since 4.1.0 |
|
16 | 1650 |
* @since 5.5.0 The title part is wrapped in a `<span>` element. |
5 | 1651 |
* |
1652 |
* @return string Archive title. |
|
1653 |
*/ |
|
1654 |
function get_the_archive_title() { |
|
16 | 1655 |
$title = __( 'Archives' ); |
1656 |
$prefix = ''; |
|
1657 |
||
5 | 1658 |
if ( is_category() ) { |
16 | 1659 |
$title = single_cat_title( '', false ); |
1660 |
$prefix = _x( 'Category:', 'category archive title prefix' ); |
|
5 | 1661 |
} elseif ( is_tag() ) { |
16 | 1662 |
$title = single_tag_title( '', false ); |
1663 |
$prefix = _x( 'Tag:', 'tag archive title prefix' ); |
|
5 | 1664 |
} elseif ( is_author() ) { |
16 | 1665 |
$title = get_the_author(); |
1666 |
$prefix = _x( 'Author:', 'author archive title prefix' ); |
|
5 | 1667 |
} elseif ( is_year() ) { |
16 | 1668 |
$title = get_the_date( _x( 'Y', 'yearly archives date format' ) ); |
1669 |
$prefix = _x( 'Year:', 'date archive title prefix' ); |
|
5 | 1670 |
} elseif ( is_month() ) { |
16 | 1671 |
$title = get_the_date( _x( 'F Y', 'monthly archives date format' ) ); |
1672 |
$prefix = _x( 'Month:', 'date archive title prefix' ); |
|
5 | 1673 |
} elseif ( is_day() ) { |
16 | 1674 |
$title = get_the_date( _x( 'F j, Y', 'daily archives date format' ) ); |
1675 |
$prefix = _x( 'Day:', 'date archive title prefix' ); |
|
5 | 1676 |
} elseif ( is_tax( 'post_format' ) ) { |
1677 |
if ( is_tax( 'post_format', 'post-format-aside' ) ) { |
|
1678 |
$title = _x( 'Asides', 'post format archive title' ); |
|
1679 |
} elseif ( is_tax( 'post_format', 'post-format-gallery' ) ) { |
|
1680 |
$title = _x( 'Galleries', 'post format archive title' ); |
|
1681 |
} elseif ( is_tax( 'post_format', 'post-format-image' ) ) { |
|
1682 |
$title = _x( 'Images', 'post format archive title' ); |
|
1683 |
} elseif ( is_tax( 'post_format', 'post-format-video' ) ) { |
|
1684 |
$title = _x( 'Videos', 'post format archive title' ); |
|
1685 |
} elseif ( is_tax( 'post_format', 'post-format-quote' ) ) { |
|
1686 |
$title = _x( 'Quotes', 'post format archive title' ); |
|
1687 |
} elseif ( is_tax( 'post_format', 'post-format-link' ) ) { |
|
1688 |
$title = _x( 'Links', 'post format archive title' ); |
|
1689 |
} elseif ( is_tax( 'post_format', 'post-format-status' ) ) { |
|
1690 |
$title = _x( 'Statuses', 'post format archive title' ); |
|
1691 |
} elseif ( is_tax( 'post_format', 'post-format-audio' ) ) { |
|
1692 |
$title = _x( 'Audio', 'post format archive title' ); |
|
1693 |
} elseif ( is_tax( 'post_format', 'post-format-chat' ) ) { |
|
1694 |
$title = _x( 'Chats', 'post format archive title' ); |
|
1695 |
} |
|
1696 |
} elseif ( is_post_type_archive() ) { |
|
16 | 1697 |
$title = post_type_archive_title( '', false ); |
1698 |
$prefix = _x( 'Archives:', 'post type archive title prefix' ); |
|
5 | 1699 |
} elseif ( is_tax() ) { |
16 | 1700 |
$queried_object = get_queried_object(); |
1701 |
if ( $queried_object ) { |
|
1702 |
$tax = get_taxonomy( $queried_object->taxonomy ); |
|
1703 |
$title = single_term_title( '', false ); |
|
1704 |
$prefix = sprintf( |
|
1705 |
/* translators: %s: Taxonomy singular name. */ |
|
1706 |
_x( '%s:', 'taxonomy term archive title prefix' ), |
|
1707 |
$tax->labels->singular_name |
|
1708 |
); |
|
1709 |
} |
|
1710 |
} |
|
1711 |
||
1712 |
$original_title = $title; |
|
1713 |
||
1714 |
/** |
|
1715 |
* Filters the archive title prefix. |
|
1716 |
* |
|
1717 |
* @since 5.5.0 |
|
1718 |
* |
|
1719 |
* @param string $prefix Archive title prefix. |
|
1720 |
*/ |
|
1721 |
$prefix = apply_filters( 'get_the_archive_title_prefix', $prefix ); |
|
1722 |
if ( $prefix ) { |
|
1723 |
$title = sprintf( |
|
1724 |
/* translators: 1: Title prefix. 2: Title. */ |
|
1725 |
_x( '%1$s %2$s', 'archive title' ), |
|
1726 |
$prefix, |
|
1727 |
'<span>' . $title . '</span>' |
|
1728 |
); |
|
5 | 1729 |
} |
1730 |
||
1731 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1732 |
* Filters the archive title. |
5 | 1733 |
* |
1734 |
* @since 4.1.0 |
|
16 | 1735 |
* @since 5.5.0 Added the `$prefix` and `$original_title` parameters. |
5 | 1736 |
* |
16 | 1737 |
* @param string $title Archive title to be displayed. |
1738 |
* @param string $original_title Archive title without prefix. |
|
1739 |
* @param string $prefix Archive title prefix. |
|
5 | 1740 |
*/ |
16 | 1741 |
return apply_filters( 'get_the_archive_title', $title, $original_title, $prefix ); |
5 | 1742 |
} |
1743 |
||
1744 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1745 |
* Display category, tag, term, or author description. |
5 | 1746 |
* |
1747 |
* @since 4.1.0 |
|
1748 |
* |
|
1749 |
* @see get_the_archive_description() |
|
1750 |
* |
|
1751 |
* @param string $before Optional. Content to prepend to the description. Default empty. |
|
1752 |
* @param string $after Optional. Content to append to the description. Default empty. |
|
1753 |
*/ |
|
1754 |
function the_archive_description( $before = '', $after = '' ) { |
|
1755 |
$description = get_the_archive_description(); |
|
1756 |
if ( $description ) { |
|
1757 |
echo $before . $description . $after; |
|
1758 |
} |
|
1759 |
} |
|
1760 |
||
1761 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1762 |
* Retrieves the description for an author, post type, or term archive. |
5 | 1763 |
* |
1764 |
* @since 4.1.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1765 |
* @since 4.7.0 Added support for author archives. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1766 |
* @since 4.9.0 Added support for post type archives. |
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 |
* @see term_description() |
5 | 1769 |
* |
1770 |
* @return string Archive description. |
|
1771 |
*/ |
|
1772 |
function get_the_archive_description() { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1773 |
if ( is_author() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1774 |
$description = get_the_author_meta( 'description' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1775 |
} elseif ( is_post_type_archive() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1776 |
$description = get_the_post_type_description(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1777 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1778 |
$description = term_description(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1779 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1780 |
|
5 | 1781 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1782 |
* Filters the archive description. |
5 | 1783 |
* |
1784 |
* @since 4.1.0 |
|
1785 |
* |
|
1786 |
* @param string $description Archive description to be displayed. |
|
1787 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1788 |
return apply_filters( 'get_the_archive_description', $description ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1789 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1790 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1791 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1792 |
* Retrieves the description for a post type archive. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1793 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1794 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1795 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1796 |
* @return string The post type description. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1797 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1798 |
function get_the_post_type_description() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1799 |
$post_type = get_query_var( 'post_type' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1800 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1801 |
if ( is_array( $post_type ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1802 |
$post_type = reset( $post_type ); |
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 |
$post_type_obj = get_post_type_object( $post_type ); |
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 |
// Check if a description is set. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1808 |
if ( isset( $post_type_obj->description ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1809 |
$description = $post_type_obj->description; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1810 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1811 |
$description = ''; |
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 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1814 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1815 |
* Filters the description for a post type archive. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1816 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1817 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1818 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1819 |
* @param string $description The post type description. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1820 |
* @param WP_Post_Type $post_type_obj The post type object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1821 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1822 |
return apply_filters( 'get_the_post_type_description', $description, $post_type_obj ); |
5 | 1823 |
} |
1824 |
||
1825 |
/** |
|
0 | 1826 |
* Retrieve archive link content based on predefined or custom code. |
1827 |
* |
|
1828 |
* The format can be one of four styles. The 'link' for head element, 'option' |
|
1829 |
* for use in the select element, 'html' for use in list (either ol or ul HTML |
|
1830 |
* elements). Custom content is also supported using the before and after |
|
1831 |
* parameters. |
|
1832 |
* |
|
5 | 1833 |
* The 'link' format uses the `<link>` HTML element with the **archives** |
0 | 1834 |
* relationship. The before and after parameters are not used. The text |
1835 |
* parameter is used to describe the link. |
|
1836 |
* |
|
1837 |
* The 'option' format uses the option HTML element for use in select element. |
|
1838 |
* The value is the url parameter and the before and after parameters are used |
|
1839 |
* between the text description. |
|
1840 |
* |
|
1841 |
* The 'html' format, which is the default, uses the li HTML element for use in |
|
1842 |
* the list HTML elements. The before parameter is before the link and the after |
|
1843 |
* parameter is after the closing link. |
|
1844 |
* |
|
1845 |
* The custom format uses the before parameter before the link ('a' HTML |
|
1846 |
* element) and the after parameter after the closing link tag. If the above |
|
1847 |
* three values for the format are not used, then custom format is assumed. |
|
1848 |
* |
|
1849 |
* @since 1.0.0 |
|
9 | 1850 |
* @since 5.2.0 Added the `$selected` parameter. |
1851 |
* |
|
1852 |
* @param string $url URL to archive. |
|
1853 |
* @param string $text Archive text description. |
|
16 | 1854 |
* @param string $format Optional. Can be 'link', 'option', 'html', or custom. Default 'html'. |
9 | 1855 |
* @param string $before Optional. Content to prepend to the description. Default empty. |
1856 |
* @param string $after Optional. Content to append to the description. Default empty. |
|
1857 |
* @param bool $selected Optional. Set to true if the current page is the selected archive page. |
|
0 | 1858 |
* @return string HTML link content for archive. |
1859 |
*/ |
|
9 | 1860 |
function get_archives_link( $url, $text, $format = 'html', $before = '', $after = '', $selected = false ) { |
16 | 1861 |
$text = wptexturize( $text ); |
1862 |
$url = esc_url( $url ); |
|
1863 |
$aria_current = $selected ? ' aria-current="page"' : ''; |
|
1864 |
||
1865 |
if ( 'link' === $format ) { |
|
0 | 1866 |
$link_html = "\t<link rel='archives' title='" . esc_attr( $text ) . "' href='$url' />\n"; |
16 | 1867 |
} elseif ( 'option' === $format ) { |
9 | 1868 |
$selected_attr = $selected ? " selected='selected'" : ''; |
1869 |
$link_html = "\t<option value='$url'$selected_attr>$before $text $after</option>\n"; |
|
16 | 1870 |
} elseif ( 'html' === $format ) { |
1871 |
$link_html = "\t<li>$before<a href='$url'$aria_current>$text</a>$after</li>\n"; |
|
1872 |
} else { // Custom. |
|
1873 |
$link_html = "\t$before<a href='$url'$aria_current>$text</a>$after\n"; |
|
9 | 1874 |
} |
0 | 1875 |
|
5 | 1876 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1877 |
* Filters the archive link content. |
5 | 1878 |
* |
1879 |
* @since 2.6.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1880 |
* @since 4.5.0 Added the `$url`, `$text`, `$format`, `$before`, and `$after` parameters. |
9 | 1881 |
* @since 5.2.0 Added the `$selected` parameter. |
5 | 1882 |
* |
1883 |
* @param string $link_html The archive HTML link content. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1884 |
* @param string $url URL to archive. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1885 |
* @param string $text Archive text description. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1886 |
* @param string $format Link format. Can be 'link', 'option', 'html', or custom. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1887 |
* @param string $before Content to prepend to the description. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1888 |
* @param string $after Content to append to the description. |
9 | 1889 |
* @param bool $selected True if the current page is the selected archive. |
5 | 1890 |
*/ |
9 | 1891 |
return apply_filters( 'get_archives_link', $link_html, $url, $text, $format, $before, $after, $selected ); |
0 | 1892 |
} |
1893 |
||
1894 |
/** |
|
1895 |
* Display archive links based on type and format. |
|
1896 |
* |
|
1897 |
* @since 1.2.0 |
|
9 | 1898 |
* @since 4.4.0 The `$post_type` argument was added. |
1899 |
* @since 5.2.0 The `$year`, `$monthnum`, `$day`, and `$w` arguments were added. |
|
0 | 1900 |
* |
5 | 1901 |
* @see get_archives_link() |
1902 |
* |
|
16 | 1903 |
* @global wpdb $wpdb WordPress database abstraction object. |
1904 |
* @global WP_Locale $wp_locale WordPress date and time locale object. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1905 |
* |
5 | 1906 |
* @param string|array $args { |
1907 |
* Default archive links arguments. Optional. |
|
1908 |
* |
|
1909 |
* @type string $type Type of archive to retrieve. Accepts 'daily', 'weekly', 'monthly', |
|
1910 |
* 'yearly', 'postbypost', or 'alpha'. Both 'postbypost' and 'alpha' |
|
1911 |
* display the same archive link list as well as post titles instead |
|
1912 |
* of displaying dates. The difference between the two is that 'alpha' |
|
1913 |
* will order by post title and 'postbypost' will order by post date. |
|
1914 |
* Default 'monthly'. |
|
1915 |
* @type string|int $limit Number of links to limit the query to. Default empty (no limit). |
|
1916 |
* @type string $format Format each link should take using the $before and $after args. |
|
1917 |
* Accepts 'link' (`<link>` tag), 'option' (`<option>` tag), 'html' |
|
1918 |
* (`<li>` tag), or a custom format, which generates a link anchor |
|
1919 |
* with $before preceding and $after succeeding. Default 'html'. |
|
1920 |
* @type string $before Markup to prepend to the beginning of each link. Default empty. |
|
1921 |
* @type string $after Markup to append to the end of each link. Default empty. |
|
1922 |
* @type bool $show_post_count Whether to display the post count alongside the link. Default false. |
|
1923 |
* @type bool|int $echo Whether to echo or return the links list. Default 1|true to echo. |
|
1924 |
* @type string $order Whether to use ascending or descending order. Accepts 'ASC', or 'DESC'. |
|
1925 |
* Default 'DESC'. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1926 |
* @type string $post_type Post type. Default 'post'. |
9 | 1927 |
* @type string $year Year. Default current year. |
1928 |
* @type string $monthnum Month number. Default current month number. |
|
1929 |
* @type string $day Day. Default current day. |
|
1930 |
* @type string $w Week. Default current week. |
|
5 | 1931 |
* } |
16 | 1932 |
* @return void|string Void if 'echo' argument is true, archive links if 'echo' is false. |
0 | 1933 |
*/ |
5 | 1934 |
function wp_get_archives( $args = '' ) { |
0 | 1935 |
global $wpdb, $wp_locale; |
1936 |
||
1937 |
$defaults = array( |
|
9 | 1938 |
'type' => 'monthly', |
1939 |
'limit' => '', |
|
1940 |
'format' => 'html', |
|
1941 |
'before' => '', |
|
1942 |
'after' => '', |
|
1943 |
'show_post_count' => false, |
|
1944 |
'echo' => 1, |
|
1945 |
'order' => 'DESC', |
|
1946 |
'post_type' => 'post', |
|
1947 |
'year' => get_query_var( 'year' ), |
|
1948 |
'monthnum' => get_query_var( 'monthnum' ), |
|
1949 |
'day' => get_query_var( 'day' ), |
|
1950 |
'w' => get_query_var( 'w' ), |
|
0 | 1951 |
); |
1952 |
||
16 | 1953 |
$parsed_args = wp_parse_args( $args, $defaults ); |
1954 |
||
1955 |
$post_type_object = get_post_type_object( $parsed_args['post_type'] ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1956 |
if ( ! is_post_type_viewable( $post_type_object ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1957 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1958 |
} |
16 | 1959 |
|
1960 |
$parsed_args['post_type'] = $post_type_object->name; |
|
1961 |
||
1962 |
if ( '' === $parsed_args['type'] ) { |
|
1963 |
$parsed_args['type'] = 'monthly'; |
|
0 | 1964 |
} |
1965 |
||
16 | 1966 |
if ( ! empty( $parsed_args['limit'] ) ) { |
1967 |
$parsed_args['limit'] = absint( $parsed_args['limit'] ); |
|
1968 |
$parsed_args['limit'] = ' LIMIT ' . $parsed_args['limit']; |
|
5 | 1969 |
} |
1970 |
||
16 | 1971 |
$order = strtoupper( $parsed_args['order'] ); |
1972 |
if ( 'ASC' !== $order ) { |
|
0 | 1973 |
$order = 'DESC'; |
5 | 1974 |
} |
0 | 1975 |
|
16 | 1976 |
// This is what will separate dates on weekly archive links. |
0 | 1977 |
$archive_week_separator = '–'; |
1978 |
||
16 | 1979 |
$sql_where = $wpdb->prepare( "WHERE post_type = %s AND post_status = 'publish'", $parsed_args['post_type'] ); |
0 | 1980 |
|
5 | 1981 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1982 |
* Filters the SQL WHERE clause for retrieving archives. |
5 | 1983 |
* |
1984 |
* @since 2.2.0 |
|
1985 |
* |
|
16 | 1986 |
* @param string $sql_where Portion of SQL query containing the WHERE clause. |
1987 |
* @param array $parsed_args An array of default arguments. |
|
5 | 1988 |
*/ |
16 | 1989 |
$where = apply_filters( 'getarchives_where', $sql_where, $parsed_args ); |
5 | 1990 |
|
1991 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1992 |
* Filters the SQL JOIN clause for retrieving archives. |
5 | 1993 |
* |
1994 |
* @since 2.2.0 |
|
1995 |
* |
|
16 | 1996 |
* @param string $sql_join Portion of SQL query containing JOIN clause. |
1997 |
* @param array $parsed_args An array of default arguments. |
|
5 | 1998 |
*/ |
16 | 1999 |
$join = apply_filters( 'getarchives_join', '', $parsed_args ); |
0 | 2000 |
|
2001 |
$output = ''; |
|
2002 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2003 |
$last_changed = wp_cache_get_last_changed( 'posts' ); |
0 | 2004 |
|
16 | 2005 |
$limit = $parsed_args['limit']; |
2006 |
||
2007 |
if ( 'monthly' === $parsed_args['type'] ) { |
|
2008 |
$query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date $order $limit"; |
|
2009 |
$key = md5( $query ); |
|
2010 |
$key = "wp_get_archives:$key:$last_changed"; |
|
2011 |
$results = wp_cache_get( $key, 'posts' ); |
|
2012 |
if ( ! $results ) { |
|
0 | 2013 |
$results = $wpdb->get_results( $query ); |
2014 |
wp_cache_set( $key, $results, 'posts' ); |
|
2015 |
} |
|
2016 |
if ( $results ) { |
|
16 | 2017 |
$after = $parsed_args['after']; |
0 | 2018 |
foreach ( (array) $results as $result ) { |
2019 |
$url = get_month_link( $result->year, $result->month ); |
|
16 | 2020 |
if ( 'post' !== $parsed_args['post_type'] ) { |
2021 |
$url = add_query_arg( 'post_type', $parsed_args['post_type'], $url ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2022 |
} |
16 | 2023 |
/* translators: 1: Month name, 2: 4-digit year. */ |
5 | 2024 |
$text = sprintf( __( '%1$s %2$d' ), $wp_locale->get_month( $result->month ), $result->year ); |
16 | 2025 |
if ( $parsed_args['show_post_count'] ) { |
2026 |
$parsed_args['after'] = ' (' . $result->posts . ')' . $after; |
|
5 | 2027 |
} |
16 | 2028 |
$selected = is_archive() && (string) $parsed_args['year'] === $result->year && (string) $parsed_args['monthnum'] === $result->month; |
2029 |
$output .= get_archives_link( $url, $text, $parsed_args['format'], $parsed_args['before'], $parsed_args['after'], $selected ); |
|
0 | 2030 |
} |
2031 |
} |
|
16 | 2032 |
} elseif ( 'yearly' === $parsed_args['type'] ) { |
2033 |
$query = "SELECT YEAR(post_date) AS `year`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date) ORDER BY post_date $order $limit"; |
|
2034 |
$key = md5( $query ); |
|
2035 |
$key = "wp_get_archives:$key:$last_changed"; |
|
2036 |
$results = wp_cache_get( $key, 'posts' ); |
|
2037 |
if ( ! $results ) { |
|
0 | 2038 |
$results = $wpdb->get_results( $query ); |
2039 |
wp_cache_set( $key, $results, 'posts' ); |
|
2040 |
} |
|
2041 |
if ( $results ) { |
|
16 | 2042 |
$after = $parsed_args['after']; |
9 | 2043 |
foreach ( (array) $results as $result ) { |
5 | 2044 |
$url = get_year_link( $result->year ); |
16 | 2045 |
if ( 'post' !== $parsed_args['post_type'] ) { |
2046 |
$url = add_query_arg( 'post_type', $parsed_args['post_type'], $url ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2047 |
} |
5 | 2048 |
$text = sprintf( '%d', $result->year ); |
16 | 2049 |
if ( $parsed_args['show_post_count'] ) { |
2050 |
$parsed_args['after'] = ' (' . $result->posts . ')' . $after; |
|
5 | 2051 |
} |
16 | 2052 |
$selected = is_archive() && (string) $parsed_args['year'] === $result->year; |
2053 |
$output .= get_archives_link( $url, $text, $parsed_args['format'], $parsed_args['before'], $parsed_args['after'], $selected ); |
|
0 | 2054 |
} |
2055 |
} |
|
16 | 2056 |
} elseif ( 'daily' === $parsed_args['type'] ) { |
2057 |
$query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, DAYOFMONTH(post_date) AS `dayofmonth`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date) ORDER BY post_date $order $limit"; |
|
2058 |
$key = md5( $query ); |
|
2059 |
$key = "wp_get_archives:$key:$last_changed"; |
|
2060 |
$results = wp_cache_get( $key, 'posts' ); |
|
2061 |
if ( ! $results ) { |
|
0 | 2062 |
$results = $wpdb->get_results( $query ); |
2063 |
wp_cache_set( $key, $results, 'posts' ); |
|
2064 |
} |
|
2065 |
if ( $results ) { |
|
16 | 2066 |
$after = $parsed_args['after']; |
0 | 2067 |
foreach ( (array) $results as $result ) { |
9 | 2068 |
$url = get_day_link( $result->year, $result->month, $result->dayofmonth ); |
16 | 2069 |
if ( 'post' !== $parsed_args['post_type'] ) { |
2070 |
$url = add_query_arg( 'post_type', $parsed_args['post_type'], $url ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2071 |
} |
5 | 2072 |
$date = sprintf( '%1$d-%2$02d-%3$02d 00:00:00', $result->year, $result->month, $result->dayofmonth ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2073 |
$text = mysql2date( get_option( 'date_format' ), $date ); |
16 | 2074 |
if ( $parsed_args['show_post_count'] ) { |
2075 |
$parsed_args['after'] = ' (' . $result->posts . ')' . $after; |
|
5 | 2076 |
} |
16 | 2077 |
$selected = is_archive() && (string) $parsed_args['year'] === $result->year && (string) $parsed_args['monthnum'] === $result->month && (string) $parsed_args['day'] === $result->dayofmonth; |
2078 |
$output .= get_archives_link( $url, $text, $parsed_args['format'], $parsed_args['before'], $parsed_args['after'], $selected ); |
|
0 | 2079 |
} |
2080 |
} |
|
16 | 2081 |
} elseif ( 'weekly' === $parsed_args['type'] ) { |
2082 |
$week = _wp_mysql_week( '`post_date`' ); |
|
2083 |
$query = "SELECT DISTINCT $week AS `week`, YEAR( `post_date` ) AS `yr`, DATE_FORMAT( `post_date`, '%Y-%m-%d' ) AS `yyyymmdd`, count( `ID` ) AS `posts` FROM `$wpdb->posts` $join $where GROUP BY $week, YEAR( `post_date` ) ORDER BY `post_date` $order $limit"; |
|
2084 |
$key = md5( $query ); |
|
2085 |
$key = "wp_get_archives:$key:$last_changed"; |
|
2086 |
$results = wp_cache_get( $key, 'posts' ); |
|
2087 |
if ( ! $results ) { |
|
0 | 2088 |
$results = $wpdb->get_results( $query ); |
2089 |
wp_cache_set( $key, $results, 'posts' ); |
|
2090 |
} |
|
2091 |
$arc_w_last = ''; |
|
2092 |
if ( $results ) { |
|
16 | 2093 |
$after = $parsed_args['after']; |
5 | 2094 |
foreach ( (array) $results as $result ) { |
2095 |
if ( $result->week != $arc_w_last ) { |
|
2096 |
$arc_year = $result->yr; |
|
2097 |
$arc_w_last = $result->week; |
|
2098 |
$arc_week = get_weekstartend( $result->yyyymmdd, get_option( 'start_of_week' ) ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2099 |
$arc_week_start = date_i18n( get_option( 'date_format' ), $arc_week['start'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2100 |
$arc_week_end = date_i18n( get_option( 'date_format' ), $arc_week['end'] ); |
9 | 2101 |
$url = add_query_arg( |
2102 |
array( |
|
2103 |
'm' => $arc_year, |
|
2104 |
'w' => $result->week, |
|
2105 |
), |
|
2106 |
home_url( '/' ) |
|
2107 |
); |
|
16 | 2108 |
if ( 'post' !== $parsed_args['post_type'] ) { |
2109 |
$url = add_query_arg( 'post_type', $parsed_args['post_type'], $url ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2110 |
} |
9 | 2111 |
$text = $arc_week_start . $archive_week_separator . $arc_week_end; |
16 | 2112 |
if ( $parsed_args['show_post_count'] ) { |
2113 |
$parsed_args['after'] = ' (' . $result->posts . ')' . $after; |
|
0 | 2114 |
} |
16 | 2115 |
$selected = is_archive() && (string) $parsed_args['year'] === $result->yr && (string) $parsed_args['w'] === $result->week; |
2116 |
$output .= get_archives_link( $url, $text, $parsed_args['format'], $parsed_args['before'], $parsed_args['after'], $selected ); |
|
0 | 2117 |
} |
5 | 2118 |
} |
0 | 2119 |
} |
16 | 2120 |
} elseif ( ( 'postbypost' === $parsed_args['type'] ) || ( 'alpha' === $parsed_args['type'] ) ) { |
2121 |
$orderby = ( 'alpha' === $parsed_args['type'] ) ? 'post_title ASC ' : 'post_date DESC, ID DESC '; |
|
9 | 2122 |
$query = "SELECT * FROM $wpdb->posts $join $where ORDER BY $orderby $limit"; |
2123 |
$key = md5( $query ); |
|
2124 |
$key = "wp_get_archives:$key:$last_changed"; |
|
16 | 2125 |
$results = wp_cache_get( $key, 'posts' ); |
2126 |
if ( ! $results ) { |
|
0 | 2127 |
$results = $wpdb->get_results( $query ); |
2128 |
wp_cache_set( $key, $results, 'posts' ); |
|
2129 |
} |
|
2130 |
if ( $results ) { |
|
2131 |
foreach ( (array) $results as $result ) { |
|
16 | 2132 |
if ( '0000-00-00 00:00:00' !== $result->post_date ) { |
5 | 2133 |
$url = get_permalink( $result ); |
0 | 2134 |
if ( $result->post_title ) { |
2135 |
/** This filter is documented in wp-includes/post-template.php */ |
|
2136 |
$text = strip_tags( apply_filters( 'the_title', $result->post_title, $result->ID ) ); |
|
2137 |
} else { |
|
2138 |
$text = $result->ID; |
|
2139 |
} |
|
16 | 2140 |
$selected = get_the_ID() === $result->ID; |
2141 |
$output .= get_archives_link( $url, $text, $parsed_args['format'], $parsed_args['before'], $parsed_args['after'], $selected ); |
|
0 | 2142 |
} |
2143 |
} |
|
2144 |
} |
|
2145 |
} |
|
16 | 2146 |
|
2147 |
if ( $parsed_args['echo'] ) { |
|
0 | 2148 |
echo $output; |
5 | 2149 |
} else { |
0 | 2150 |
return $output; |
5 | 2151 |
} |
0 | 2152 |
} |
2153 |
||
2154 |
/** |
|
2155 |
* Get number of days since the start of the week. |
|
2156 |
* |
|
2157 |
* @since 1.5.0 |
|
2158 |
* |
|
2159 |
* @param int $num Number of day. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2160 |
* @return float Days since the start of the week. |
0 | 2161 |
*/ |
9 | 2162 |
function calendar_week_mod( $num ) { |
0 | 2163 |
$base = 7; |
9 | 2164 |
return ( $num - $base * floor( $num / $base ) ); |
0 | 2165 |
} |
2166 |
||
2167 |
/** |
|
2168 |
* Display calendar with days that have posts as links. |
|
2169 |
* |
|
2170 |
* The calendar is cached, which will be retrieved, if it exists. If there are |
|
2171 |
* no posts for the month, then it will not be displayed. |
|
2172 |
* |
|
2173 |
* @since 1.0.0 |
|
2174 |
* |
|
16 | 2175 |
* @global wpdb $wpdb WordPress database abstraction object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2176 |
* @global int $m |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2177 |
* @global int $monthnum |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2178 |
* @global int $year |
16 | 2179 |
* @global WP_Locale $wp_locale WordPress date and time locale object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2180 |
* @global array $posts |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2181 |
* |
16 | 2182 |
* @param bool $initial Optional. Whether to use initial calendar names. Default true. |
2183 |
* @param bool $echo Optional. Whether to display the calendar output. Default true. |
|
2184 |
* @return void|string Void if `$echo` argument is true, calendar HTML if `$echo` is false. |
|
0 | 2185 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2186 |
function get_calendar( $initial = true, $echo = true ) { |
0 | 2187 |
global $wpdb, $m, $monthnum, $year, $wp_locale, $posts; |
2188 |
||
9 | 2189 |
$key = md5( $m . $monthnum . $year ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2190 |
$cache = wp_cache_get( 'get_calendar', 'calendar' ); |
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 |
if ( $cache && is_array( $cache ) && isset( $cache[ $key ] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2193 |
/** This filter is documented in wp-includes/general-template.php */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2194 |
$output = apply_filters( 'get_calendar', $cache[ $key ] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2195 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2196 |
if ( $echo ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2197 |
echo $output; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2198 |
return; |
0 | 2199 |
} |
7
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 |
return $output; |
0 | 2202 |
} |
2203 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2204 |
if ( ! is_array( $cache ) ) { |
0 | 2205 |
$cache = array(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2206 |
} |
0 | 2207 |
|
2208 |
// Quick check. If we have no posts at all, abort! |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2209 |
if ( ! $posts ) { |
9 | 2210 |
$gotsome = $wpdb->get_var( "SELECT 1 as test FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 1" ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2211 |
if ( ! $gotsome ) { |
0 | 2212 |
$cache[ $key ] = ''; |
2213 |
wp_cache_set( 'get_calendar', $cache, 'calendar' ); |
|
2214 |
return; |
|
2215 |
} |
|
2216 |
} |
|
2217 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2218 |
if ( isset( $_GET['w'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2219 |
$w = (int) $_GET['w']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2220 |
} |
16 | 2221 |
// week_begins = 0 stands for Sunday. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2222 |
$week_begins = (int) get_option( 'start_of_week' ); |
0 | 2223 |
|
16 | 2224 |
// Let's figure out when we are. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2225 |
if ( ! empty( $monthnum ) && ! empty( $year ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2226 |
$thismonth = zeroise( intval( $monthnum ), 2 ); |
9 | 2227 |
$thisyear = (int) $year; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2228 |
} elseif ( ! empty( $w ) ) { |
16 | 2229 |
// We need to get the month from MySQL. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2230 |
$thisyear = (int) substr( $m, 0, 4 ); |
16 | 2231 |
// It seems MySQL's weeks disagree with PHP's. |
9 | 2232 |
$d = ( ( $w - 1 ) * 7 ) + 6; |
2233 |
$thismonth = $wpdb->get_var( "SELECT DATE_FORMAT((DATE_ADD('{$thisyear}0101', INTERVAL $d DAY) ), '%m')" ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2234 |
} elseif ( ! empty( $m ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2235 |
$thisyear = (int) substr( $m, 0, 4 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2236 |
if ( strlen( $m ) < 6 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2237 |
$thismonth = '01'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2238 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2239 |
$thismonth = zeroise( (int) substr( $m, 4, 2 ), 2 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2240 |
} |
0 | 2241 |
} else { |
9 | 2242 |
$thisyear = current_time( 'Y' ); |
2243 |
$thismonth = current_time( 'm' ); |
|
0 | 2244 |
} |
2245 |
||
9 | 2246 |
$unixmonth = mktime( 0, 0, 0, $thismonth, 1, $thisyear ); |
16 | 2247 |
$last_day = gmdate( 't', $unixmonth ); |
2248 |
||
2249 |
// Get the next and previous month and year with at least one post. |
|
9 | 2250 |
$previous = $wpdb->get_row( |
2251 |
"SELECT MONTH(post_date) AS month, YEAR(post_date) AS year |
|
0 | 2252 |
FROM $wpdb->posts |
2253 |
WHERE post_date < '$thisyear-$thismonth-01' |
|
2254 |
AND post_type = 'post' AND post_status = 'publish' |
|
2255 |
ORDER BY post_date DESC |
|
9 | 2256 |
LIMIT 1" |
2257 |
); |
|
2258 |
$next = $wpdb->get_row( |
|
2259 |
"SELECT MONTH(post_date) AS month, YEAR(post_date) AS year |
|
0 | 2260 |
FROM $wpdb->posts |
2261 |
WHERE post_date > '$thisyear-$thismonth-{$last_day} 23:59:59' |
|
2262 |
AND post_type = 'post' AND post_status = 'publish' |
|
2263 |
ORDER BY post_date ASC |
|
9 | 2264 |
LIMIT 1" |
2265 |
); |
|
0 | 2266 |
|
16 | 2267 |
/* translators: Calendar caption: 1: Month name, 2: 4-digit year. */ |
9 | 2268 |
$calendar_caption = _x( '%1$s %2$s', 'calendar caption' ); |
16 | 2269 |
$calendar_output = '<table id="wp-calendar" class="wp-calendar-table"> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2270 |
<caption>' . sprintf( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2271 |
$calendar_caption, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2272 |
$wp_locale->get_month( $thismonth ), |
16 | 2273 |
gmdate( 'Y', $unixmonth ) |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2274 |
) . '</caption> |
0 | 2275 |
<thead> |
2276 |
<tr>'; |
|
2277 |
||
2278 |
$myweek = array(); |
|
2279 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2280 |
for ( $wdcount = 0; $wdcount <= 6; $wdcount++ ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2281 |
$myweek[] = $wp_locale->get_weekday( ( $wdcount + $week_begins ) % 7 ); |
0 | 2282 |
} |
2283 |
||
2284 |
foreach ( $myweek as $wd ) { |
|
9 | 2285 |
$day_name = $initial ? $wp_locale->get_weekday_initial( $wd ) : $wp_locale->get_weekday_abbrev( $wd ); |
2286 |
$wd = esc_attr( $wd ); |
|
0 | 2287 |
$calendar_output .= "\n\t\t<th scope=\"col\" title=\"$wd\">$day_name</th>"; |
2288 |
} |
|
2289 |
||
2290 |
$calendar_output .= ' |
|
2291 |
</tr> |
|
2292 |
</thead> |
|
2293 |
<tbody> |
|
2294 |
<tr>'; |
|
2295 |
||
5 | 2296 |
$daywithpost = array(); |
2297 |
||
16 | 2298 |
// Get days with posts. |
9 | 2299 |
$dayswithposts = $wpdb->get_results( |
2300 |
"SELECT DISTINCT DAYOFMONTH(post_date) |
|
0 | 2301 |
FROM $wpdb->posts WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00' |
2302 |
AND post_type = 'post' AND post_status = 'publish' |
|
9 | 2303 |
AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59'", |
2304 |
ARRAY_N |
|
2305 |
); |
|
16 | 2306 |
|
0 | 2307 |
if ( $dayswithposts ) { |
2308 |
foreach ( (array) $dayswithposts as $daywith ) { |
|
16 | 2309 |
$daywithpost[] = (int) $daywith[0]; |
0 | 2310 |
} |
2311 |
} |
|
2312 |
||
16 | 2313 |
// See how much we should pad in the beginning. |
2314 |
$pad = calendar_week_mod( gmdate( 'w', $unixmonth ) - $week_begins ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2315 |
if ( 0 != $pad ) { |
9 | 2316 |
$calendar_output .= "\n\t\t" . '<td colspan="' . esc_attr( $pad ) . '" class="pad"> </td>'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2317 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2318 |
|
9 | 2319 |
$newrow = false; |
16 | 2320 |
$daysinmonth = (int) gmdate( 't', $unixmonth ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2321 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2322 |
for ( $day = 1; $day <= $daysinmonth; ++$day ) { |
9 | 2323 |
if ( isset( $newrow ) && $newrow ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2324 |
$calendar_output .= "\n\t</tr>\n\t<tr>\n\t\t"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2325 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2326 |
$newrow = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2327 |
|
16 | 2328 |
if ( current_time( 'j' ) == $day && |
2329 |
current_time( 'm' ) == $thismonth && |
|
2330 |
current_time( 'Y' ) == $thisyear ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2331 |
$calendar_output .= '<td id="today">'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2332 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2333 |
$calendar_output .= '<td>'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2334 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2335 |
|
16 | 2336 |
if ( in_array( $day, $daywithpost, true ) ) { |
2337 |
// Any posts today? |
|
2338 |
$date_format = gmdate( _x( 'F j, Y', 'daily archives date format' ), strtotime( "{$thisyear}-{$thismonth}-{$day}" ) ); |
|
2339 |
/* translators: Post calendar label. %s: Date. */ |
|
9 | 2340 |
$label = sprintf( __( 'Posts published on %s' ), $date_format ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2341 |
$calendar_output .= sprintf( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2342 |
'<a href="%s" aria-label="%s">%s</a>', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2343 |
get_day_link( $thisyear, $thismonth, $day ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2344 |
esc_attr( $label ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2345 |
$day |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2346 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2347 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2348 |
$calendar_output .= $day; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2349 |
} |
16 | 2350 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2351 |
$calendar_output .= '</td>'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2352 |
|
16 | 2353 |
if ( 6 == calendar_week_mod( gmdate( 'w', mktime( 0, 0, 0, $thismonth, $day, $thisyear ) ) - $week_begins ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2354 |
$newrow = true; |
0 | 2355 |
} |
2356 |
} |
|
2357 |
||
16 | 2358 |
$pad = 7 - calendar_week_mod( gmdate( 'w', mktime( 0, 0, 0, $thismonth, $day, $thisyear ) ) - $week_begins ); |
2359 |
if ( 0 != $pad && 7 != $pad ) { |
|
9 | 2360 |
$calendar_output .= "\n\t\t" . '<td class="pad" colspan="' . esc_attr( $pad ) . '"> </td>'; |
0 | 2361 |
} |
16 | 2362 |
|
2363 |
$calendar_output .= "\n\t</tr>\n\t</tbody>"; |
|
2364 |
||
2365 |
$calendar_output .= "\n\t</table>"; |
|
2366 |
||
2367 |
$calendar_output .= '<nav aria-label="' . __( 'Previous and next months' ) . '" class="wp-calendar-nav">'; |
|
2368 |
||
2369 |
if ( $previous ) { |
|
2370 |
$calendar_output .= "\n\t\t" . '<span class="wp-calendar-nav-prev"><a href="' . get_month_link( $previous->year, $previous->month ) . '">« ' . |
|
2371 |
$wp_locale->get_month_abbrev( $wp_locale->get_month( $previous->month ) ) . |
|
2372 |
'</a></span>'; |
|
2373 |
} else { |
|
2374 |
$calendar_output .= "\n\t\t" . '<span class="wp-calendar-nav-prev"> </span>'; |
|
2375 |
} |
|
2376 |
||
2377 |
$calendar_output .= "\n\t\t" . '<span class="pad"> </span>'; |
|
2378 |
||
2379 |
if ( $next ) { |
|
2380 |
$calendar_output .= "\n\t\t" . '<span class="wp-calendar-nav-next"><a href="' . get_month_link( $next->year, $next->month ) . '">' . |
|
2381 |
$wp_locale->get_month_abbrev( $wp_locale->get_month( $next->month ) ) . |
|
2382 |
' »</a></span>'; |
|
2383 |
} else { |
|
2384 |
$calendar_output .= "\n\t\t" . '<span class="wp-calendar-nav-next"> </span>'; |
|
2385 |
} |
|
2386 |
||
2387 |
$calendar_output .= ' |
|
2388 |
</nav>'; |
|
0 | 2389 |
|
2390 |
$cache[ $key ] = $calendar_output; |
|
2391 |
wp_cache_set( 'get_calendar', $cache, 'calendar' ); |
|
2392 |
||
5 | 2393 |
if ( $echo ) { |
2394 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2395 |
* Filters the HTML calendar output. |
5 | 2396 |
* |
2397 |
* @since 3.0.0 |
|
2398 |
* |
|
2399 |
* @param string $calendar_output HTML output of the calendar. |
|
2400 |
*/ |
|
2401 |
echo apply_filters( 'get_calendar', $calendar_output ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2402 |
return; |
5 | 2403 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2404 |
/** This filter is documented in wp-includes/general-template.php */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2405 |
return apply_filters( 'get_calendar', $calendar_output ); |
0 | 2406 |
} |
2407 |
||
2408 |
/** |
|
2409 |
* Purge the cached results of get_calendar. |
|
2410 |
* |
|
2411 |
* @see get_calendar |
|
2412 |
* @since 2.1.0 |
|
2413 |
*/ |
|
2414 |
function delete_get_calendar_cache() { |
|
2415 |
wp_cache_delete( 'get_calendar', 'calendar' ); |
|
2416 |
} |
|
2417 |
||
2418 |
/** |
|
2419 |
* Display all of the allowed tags in HTML format with attributes. |
|
2420 |
* |
|
2421 |
* This is useful for displaying in the comment area, which elements and |
|
2422 |
* attributes are supported. As well as any plugins which want to display it. |
|
2423 |
* |
|
2424 |
* @since 1.0.1 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2425 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2426 |
* @global array $allowedtags |
0 | 2427 |
* |
2428 |
* @return string HTML allowed tags entity encoded. |
|
2429 |
*/ |
|
2430 |
function allowed_tags() { |
|
2431 |
global $allowedtags; |
|
2432 |
$allowed = ''; |
|
2433 |
foreach ( (array) $allowedtags as $tag => $attributes ) { |
|
9 | 2434 |
$allowed .= '<' . $tag; |
2435 |
if ( 0 < count( $attributes ) ) { |
|
0 | 2436 |
foreach ( $attributes as $attribute => $limits ) { |
9 | 2437 |
$allowed .= ' ' . $attribute . '=""'; |
0 | 2438 |
} |
2439 |
} |
|
2440 |
$allowed .= '> '; |
|
2441 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2442 |
return htmlentities( $allowed ); |
0 | 2443 |
} |
2444 |
||
9 | 2445 |
/***** Date/Time tags */ |
0 | 2446 |
|
2447 |
/** |
|
2448 |
* Outputs the date in iso8601 format for xml files. |
|
2449 |
* |
|
2450 |
* @since 1.0.0 |
|
2451 |
*/ |
|
2452 |
function the_date_xml() { |
|
2453 |
echo mysql2date( 'Y-m-d', get_post()->post_date, false ); |
|
2454 |
} |
|
2455 |
||
2456 |
/** |
|
5 | 2457 |
* Display or Retrieve the date the current post was written (once per date) |
0 | 2458 |
* |
2459 |
* Will only output the date if the current post's date is different from the |
|
2460 |
* previous one output. |
|
2461 |
* |
|
2462 |
* i.e. Only one date listing will show per day worth of posts shown in the loop, even if the |
|
2463 |
* function is called several times for each post. |
|
2464 |
* |
|
2465 |
* HTML output can be filtered with 'the_date'. |
|
2466 |
* Date string output can be filtered with 'get_the_date'. |
|
2467 |
* |
|
2468 |
* @since 0.71 |
|
5 | 2469 |
* |
16 | 2470 |
* @global string $currentday The day of the current post in the loop. |
2471 |
* @global string $previousday The day of the previous post in the loop. |
|
2472 |
* |
|
2473 |
* @param string $format Optional. PHP date format defaults to the date_format option if not specified. |
|
0 | 2474 |
* @param string $before Optional. Output before the date. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2475 |
* @param string $after Optional. Output after the date. |
16 | 2476 |
* @param bool $echo Optional. Whether to echo the date or return it. Default true. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2477 |
* @return string|void String if retrieving. |
0 | 2478 |
*/ |
16 | 2479 |
function the_date( $format = '', $before = '', $after = '', $echo = true ) { |
0 | 2480 |
global $currentday, $previousday; |
5 | 2481 |
|
16 | 2482 |
$the_date = ''; |
2483 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2484 |
if ( is_new_day() ) { |
16 | 2485 |
$the_date = $before . get_the_date( $format ) . $after; |
0 | 2486 |
$previousday = $currentday; |
16 | 2487 |
} |
2488 |
||
2489 |
/** |
|
2490 |
* Filters the date a post was published for display. |
|
2491 |
* |
|
2492 |
* @since 0.71 |
|
2493 |
* |
|
2494 |
* @param string $the_date The formatted date string. |
|
2495 |
* @param string $format PHP date format. Defaults to 'date_format' option |
|
2496 |
* if not specified. |
|
2497 |
* @param string $before HTML output before the date. |
|
2498 |
* @param string $after HTML output after the date. |
|
2499 |
*/ |
|
2500 |
$the_date = apply_filters( 'the_date', $the_date, $format, $before, $after ); |
|
2501 |
||
2502 |
if ( $echo ) { |
|
2503 |
echo $the_date; |
|
2504 |
} else { |
|
2505 |
return $the_date; |
|
0 | 2506 |
} |
2507 |
} |
|
2508 |
||
2509 |
/** |
|
5 | 2510 |
* Retrieve the date on which the post was written. |
0 | 2511 |
* |
2512 |
* Unlike the_date() this function will always return the date. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2513 |
* Modify output with the {@see 'get_the_date'} filter. |
0 | 2514 |
* |
2515 |
* @since 3.0.0 |
|
2516 |
* |
|
16 | 2517 |
* @param string $format Optional. PHP date format defaults to the date_format option if not specified. |
2518 |
* @param int|WP_Post $post Optional. Post ID or WP_Post object. Default current post. |
|
2519 |
* @return string|false Date the current post was written. False on failure. |
|
0 | 2520 |
*/ |
16 | 2521 |
function get_the_date( $format = '', $post = null ) { |
5 | 2522 |
$post = get_post( $post ); |
2523 |
||
2524 |
if ( ! $post ) { |
|
2525 |
return false; |
|
2526 |
} |
|
0 | 2527 |
|
16 | 2528 |
$_format = ! empty( $format ) ? $format : get_option( 'date_format' ); |
2529 |
||
2530 |
$the_date = get_post_time( $_format, false, $post, true ); |
|
0 | 2531 |
|
5 | 2532 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2533 |
* Filters the date a post was published. |
5 | 2534 |
* |
2535 |
* @since 3.0.0 |
|
2536 |
* |
|
2537 |
* @param string $the_date The formatted date. |
|
16 | 2538 |
* @param string $format PHP date format. Defaults to 'date_format' option |
5 | 2539 |
* if not specified. |
2540 |
* @param int|WP_Post $post The post object or ID. |
|
2541 |
*/ |
|
16 | 2542 |
return apply_filters( 'get_the_date', $the_date, $format, $post ); |
0 | 2543 |
} |
2544 |
||
2545 |
/** |
|
2546 |
* Display the date on which the post was last modified. |
|
2547 |
* |
|
2548 |
* @since 2.1.0 |
|
2549 |
* |
|
16 | 2550 |
* @param string $format Optional. PHP date format defaults to the date_format option if not specified. |
0 | 2551 |
* @param string $before Optional. Output before the date. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2552 |
* @param string $after Optional. Output after the date. |
16 | 2553 |
* @param bool $echo Optional. Whether to echo the date or return it. Default true. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2554 |
* @return string|void String if retrieving. |
0 | 2555 |
*/ |
16 | 2556 |
function the_modified_date( $format = '', $before = '', $after = '', $echo = true ) { |
2557 |
$the_modified_date = $before . get_the_modified_date( $format ) . $after; |
|
5 | 2558 |
|
2559 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2560 |
* Filters the date a post was last modified for display. |
5 | 2561 |
* |
2562 |
* @since 2.1.0 |
|
2563 |
* |
|
2564 |
* @param string $the_modified_date The last modified date. |
|
16 | 2565 |
* @param string $format PHP date format. Defaults to 'date_format' option |
5 | 2566 |
* if not specified. |
2567 |
* @param string $before HTML output before the date. |
|
2568 |
* @param string $after HTML output after the date. |
|
2569 |
*/ |
|
16 | 2570 |
$the_modified_date = apply_filters( 'the_modified_date', $the_modified_date, $format, $before, $after ); |
0 | 2571 |
|
9 | 2572 |
if ( $echo ) { |
0 | 2573 |
echo $the_modified_date; |
9 | 2574 |
} else { |
0 | 2575 |
return $the_modified_date; |
9 | 2576 |
} |
0 | 2577 |
|
2578 |
} |
|
2579 |
||
2580 |
/** |
|
2581 |
* Retrieve the date on which the post was last modified. |
|
2582 |
* |
|
2583 |
* @since 2.1.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2584 |
* @since 4.6.0 Added the `$post` parameter. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2585 |
* |
16 | 2586 |
* @param string $format Optional. PHP date format defaults to the date_format option if not specified. |
2587 |
* @param int|WP_Post $post Optional. Post ID or WP_Post object. Default current post. |
|
2588 |
* @return string|false Date the current post was modified. False on failure. |
|
0 | 2589 |
*/ |
16 | 2590 |
function get_the_modified_date( $format = '', $post = null ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2591 |
$post = get_post( $post ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2592 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2593 |
if ( ! $post ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2594 |
// For backward compatibility, failures go through the filter below. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2595 |
$the_time = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2596 |
} else { |
16 | 2597 |
$_format = ! empty( $format ) ? $format : get_option( 'date_format' ); |
2598 |
||
2599 |
$the_time = get_post_modified_time( $_format, false, $post, true ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2600 |
} |
5 | 2601 |
|
2602 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2603 |
* Filters the date a post was last modified. |
5 | 2604 |
* |
2605 |
* @since 2.1.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2606 |
* @since 4.6.0 Added the `$post` parameter. |
5 | 2607 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2608 |
* @param string|bool $the_time The formatted date or false if no post is found. |
16 | 2609 |
* @param string $format PHP date format. Defaults to value specified in |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2610 |
* 'date_format' option. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2611 |
* @param WP_Post|null $post WP_Post object or null if no post is found. |
5 | 2612 |
*/ |
16 | 2613 |
return apply_filters( 'get_the_modified_date', $the_time, $format, $post ); |
0 | 2614 |
} |
2615 |
||
2616 |
/** |
|
2617 |
* Display the time at which the post was written. |
|
2618 |
* |
|
2619 |
* @since 0.71 |
|
2620 |
* |
|
16 | 2621 |
* @param string $format Either 'G', 'U', or PHP date format. |
0 | 2622 |
*/ |
16 | 2623 |
function the_time( $format = '' ) { |
5 | 2624 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2625 |
* Filters the time a post was written for display. |
5 | 2626 |
* |
2627 |
* @since 0.71 |
|
2628 |
* |
|
2629 |
* @param string $get_the_time The formatted time. |
|
16 | 2630 |
* @param string $format The time format. Accepts 'G', 'U', |
2631 |
* or PHP date format. |
|
5 | 2632 |
*/ |
16 | 2633 |
echo apply_filters( 'the_time', get_the_time( $format ), $format ); |
0 | 2634 |
} |
2635 |
||
2636 |
/** |
|
2637 |
* Retrieve the time at which the post was written. |
|
2638 |
* |
|
2639 |
* @since 1.5.0 |
|
2640 |
* |
|
16 | 2641 |
* @param string $format Optional. Format to use for retrieving the time the post |
2642 |
* was written. Either 'G', 'U', or PHP date format defaults |
|
2643 |
* to the value specified in the time_format option. Default empty. |
|
2644 |
* @param int|WP_Post $post WP_Post object or ID. Default is global `$post` object. |
|
2645 |
* @return string|int|false Formatted date string or Unix timestamp if `$format` is 'U' or 'G'. |
|
2646 |
* False on failure. |
|
0 | 2647 |
*/ |
16 | 2648 |
function get_the_time( $format = '', $post = null ) { |
9 | 2649 |
$post = get_post( $post ); |
0 | 2650 |
|
5 | 2651 |
if ( ! $post ) { |
2652 |
return false; |
|
2653 |
} |
|
2654 |
||
16 | 2655 |
$_format = ! empty( $format ) ? $format : get_option( 'time_format' ); |
2656 |
||
2657 |
$the_time = get_post_time( $_format, false, $post, true ); |
|
5 | 2658 |
|
2659 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2660 |
* Filters the time a post was written. |
5 | 2661 |
* |
2662 |
* @since 1.5.0 |
|
2663 |
* |
|
2664 |
* @param string $the_time The formatted time. |
|
16 | 2665 |
* @param string $format Format to use for retrieving the time the post was written. |
2666 |
* Accepts 'G', 'U', or PHP date format value specified |
|
5 | 2667 |
* in 'time_format' option. Default empty. |
2668 |
* @param int|WP_Post $post WP_Post object or ID. |
|
2669 |
*/ |
|
16 | 2670 |
return apply_filters( 'get_the_time', $the_time, $format, $post ); |
0 | 2671 |
} |
2672 |
||
2673 |
/** |
|
2674 |
* Retrieve the time at which the post was written. |
|
2675 |
* |
|
2676 |
* @since 2.0.0 |
|
2677 |
* |
|
16 | 2678 |
* @param string $format Optional. Format to use for retrieving the time the post |
2679 |
* was written. Either 'G', 'U', or PHP date format. Default 'U'. |
|
5 | 2680 |
* @param bool $gmt Optional. Whether to retrieve the GMT time. Default false. |
16 | 2681 |
* @param int|WP_Post $post WP_Post object or ID. Default is global `$post` object. |
5 | 2682 |
* @param bool $translate Whether to translate the time string. Default false. |
16 | 2683 |
* @return string|int|false Formatted date string or Unix timestamp if `$format` is 'U' or 'G'. |
2684 |
* False on failure. |
|
0 | 2685 |
*/ |
16 | 2686 |
function get_post_time( $format = 'U', $gmt = false, $post = null, $translate = false ) { |
9 | 2687 |
$post = get_post( $post ); |
0 | 2688 |
|
5 | 2689 |
if ( ! $post ) { |
2690 |
return false; |
|
2691 |
} |
|
2692 |
||
16 | 2693 |
$source = ( $gmt ) ? 'gmt' : 'local'; |
2694 |
$datetime = get_post_datetime( $post, 'date', $source ); |
|
2695 |
||
2696 |
if ( false === $datetime ) { |
|
2697 |
return false; |
|
2698 |
} |
|
2699 |
||
2700 |
if ( 'U' === $format || 'G' === $format ) { |
|
2701 |
$time = $datetime->getTimestamp(); |
|
2702 |
||
2703 |
// Returns a sum of timestamp with timezone offset. Ideally should never be used. |
|
2704 |
if ( ! $gmt ) { |
|
2705 |
$time += $datetime->getOffset(); |
|
2706 |
} |
|
2707 |
} elseif ( $translate ) { |
|
2708 |
$time = wp_date( $format, $datetime->getTimestamp(), $gmt ? new DateTimeZone( 'UTC' ) : null ); |
|
9 | 2709 |
} else { |
16 | 2710 |
if ( $gmt ) { |
2711 |
$datetime = $datetime->setTimezone( new DateTimeZone( 'UTC' ) ); |
|
2712 |
} |
|
2713 |
||
2714 |
$time = $datetime->format( $format ); |
|
9 | 2715 |
} |
2716 |
||
5 | 2717 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2718 |
* Filters the localized time a post was written. |
5 | 2719 |
* |
2720 |
* @since 2.6.0 |
|
2721 |
* |
|
16 | 2722 |
* @param string $time The formatted time. |
2723 |
* @param string $format Format to use for retrieving the time the post was written. |
|
2724 |
* Accepts 'G', 'U', or PHP date format. Default 'U'. |
|
2725 |
* @param bool $gmt Whether to retrieve the GMT time. Default false. |
|
5 | 2726 |
*/ |
16 | 2727 |
return apply_filters( 'get_post_time', $time, $format, $gmt ); |
2728 |
} |
|
2729 |
||
2730 |
/** |
|
2731 |
* Retrieve post published or modified time as a `DateTimeImmutable` object instance. |
|
2732 |
* |
|
2733 |
* The object will be set to the timezone from WordPress settings. |
|
2734 |
* |
|
2735 |
* For legacy reasons, this function allows to choose to instantiate from local or UTC time in database. |
|
2736 |
* Normally this should make no difference to the result. However, the values might get out of sync in database, |
|
2737 |
* typically because of timezone setting changes. The parameter ensures the ability to reproduce backwards |
|
2738 |
* compatible behaviors in such cases. |
|
2739 |
* |
|
2740 |
* @since 5.3.0 |
|
2741 |
* |
|
2742 |
* @param int|WP_Post $post Optional. WP_Post object or ID. Default is global `$post` object. |
|
2743 |
* @param string $field Optional. Published or modified time to use from database. Accepts 'date' or 'modified'. |
|
2744 |
* Default 'date'. |
|
2745 |
* @param string $source Optional. Local or UTC time to use from database. Accepts 'local' or 'gmt'. |
|
2746 |
* Default 'local'. |
|
2747 |
* @return DateTimeImmutable|false Time object on success, false on failure. |
|
2748 |
*/ |
|
2749 |
function get_post_datetime( $post = null, $field = 'date', $source = 'local' ) { |
|
2750 |
$post = get_post( $post ); |
|
2751 |
||
2752 |
if ( ! $post ) { |
|
2753 |
return false; |
|
2754 |
} |
|
2755 |
||
2756 |
$wp_timezone = wp_timezone(); |
|
2757 |
||
2758 |
if ( 'gmt' === $source ) { |
|
2759 |
$time = ( 'modified' === $field ) ? $post->post_modified_gmt : $post->post_date_gmt; |
|
2760 |
$timezone = new DateTimeZone( 'UTC' ); |
|
2761 |
} else { |
|
2762 |
$time = ( 'modified' === $field ) ? $post->post_modified : $post->post_date; |
|
2763 |
$timezone = $wp_timezone; |
|
2764 |
} |
|
2765 |
||
2766 |
if ( empty( $time ) || '0000-00-00 00:00:00' === $time ) { |
|
2767 |
return false; |
|
2768 |
} |
|
2769 |
||
2770 |
$datetime = date_create_immutable_from_format( 'Y-m-d H:i:s', $time, $timezone ); |
|
2771 |
||
2772 |
if ( false === $datetime ) { |
|
2773 |
return false; |
|
2774 |
} |
|
2775 |
||
2776 |
return $datetime->setTimezone( $wp_timezone ); |
|
2777 |
} |
|
2778 |
||
2779 |
/** |
|
2780 |
* Retrieve post published or modified time as a Unix timestamp. |
|
2781 |
* |
|
2782 |
* Note that this function returns a true Unix timestamp, not summed with timezone offset |
|
2783 |
* like older WP functions. |
|
2784 |
* |
|
2785 |
* @since 5.3.0 |
|
2786 |
* |
|
2787 |
* @param int|WP_Post $post Optional. WP_Post object or ID. Default is global `$post` object. |
|
2788 |
* @param string $field Optional. Published or modified time to use from database. Accepts 'date' or 'modified'. |
|
2789 |
* Default 'date'. |
|
2790 |
* @return int|false Unix timestamp on success, false on failure. |
|
2791 |
*/ |
|
2792 |
function get_post_timestamp( $post = null, $field = 'date' ) { |
|
2793 |
$datetime = get_post_datetime( $post, $field ); |
|
2794 |
||
2795 |
if ( false === $datetime ) { |
|
2796 |
return false; |
|
2797 |
} |
|
2798 |
||
2799 |
return $datetime->getTimestamp(); |
|
0 | 2800 |
} |
2801 |
||
2802 |
/** |
|
2803 |
* Display the time at which the post was last modified. |
|
2804 |
* |
|
2805 |
* @since 2.0.0 |
|
2806 |
* |
|
16 | 2807 |
* @param string $format Optional. Either 'G', 'U', or PHP date format defaults |
2808 |
* to the value specified in the time_format option. |
|
0 | 2809 |
*/ |
16 | 2810 |
function the_modified_time( $format = '' ) { |
5 | 2811 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2812 |
* Filters the localized time a post was last modified, for display. |
5 | 2813 |
* |
2814 |
* @since 2.0.0 |
|
2815 |
* |
|
2816 |
* @param string $get_the_modified_time The formatted time. |
|
16 | 2817 |
* @param string $format The time format. Accepts 'G', 'U', |
2818 |
* or PHP date format. Defaults to value |
|
5 | 2819 |
* specified in 'time_format' option. |
2820 |
*/ |
|
16 | 2821 |
echo apply_filters( 'the_modified_time', get_the_modified_time( $format ), $format ); |
0 | 2822 |
} |
2823 |
||
2824 |
/** |
|
2825 |
* Retrieve the time at which the post was last modified. |
|
2826 |
* |
|
2827 |
* @since 2.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2828 |
* @since 4.6.0 Added the `$post` parameter. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2829 |
* |
16 | 2830 |
* @param string $format Optional. Format to use for retrieving the time the post |
2831 |
* was modified. Either 'G', 'U', or PHP date format defaults |
|
2832 |
* to the value specified in the time_format option. Default empty. |
|
2833 |
* @param int|WP_Post $post Optional. Post ID or WP_Post object. Default current post. |
|
2834 |
* @return string|false Formatted date string or Unix timestamp. False on failure. |
|
0 | 2835 |
*/ |
16 | 2836 |
function get_the_modified_time( $format = '', $post = null ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2837 |
$post = get_post( $post ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2838 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2839 |
if ( ! $post ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2840 |
// For backward compatibility, failures go through the filter below. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2841 |
$the_time = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2842 |
} else { |
16 | 2843 |
$_format = ! empty( $format ) ? $format : get_option( 'time_format' ); |
2844 |
||
2845 |
$the_time = get_post_modified_time( $_format, false, $post, true ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2846 |
} |
5 | 2847 |
|
2848 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2849 |
* Filters the localized time a post was last modified. |
5 | 2850 |
* |
2851 |
* @since 2.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2852 |
* @since 4.6.0 Added the `$post` parameter. |
5 | 2853 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2854 |
* @param string|bool $the_time The formatted time or false if no post is found. |
16 | 2855 |
* @param string $format Format to use for retrieving the time the post was |
2856 |
* written. Accepts 'G', 'U', or PHP date format. Defaults |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2857 |
* to value specified in 'time_format' option. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2858 |
* @param WP_Post|null $post WP_Post object or null if no post is found. |
5 | 2859 |
*/ |
16 | 2860 |
return apply_filters( 'get_the_modified_time', $the_time, $format, $post ); |
0 | 2861 |
} |
2862 |
||
2863 |
/** |
|
2864 |
* Retrieve the time at which the post was last modified. |
|
2865 |
* |
|
2866 |
* @since 2.0.0 |
|
2867 |
* |
|
16 | 2868 |
* @param string $format Optional. Format to use for retrieving the time the post |
2869 |
* was modified. Either 'G', 'U', or PHP date format. Default 'U'. |
|
5 | 2870 |
* @param bool $gmt Optional. Whether to retrieve the GMT time. Default false. |
16 | 2871 |
* @param int|WP_Post $post WP_Post object or ID. Default is global `$post` object. |
5 | 2872 |
* @param bool $translate Whether to translate the time string. Default false. |
16 | 2873 |
* @return string|int|false Formatted date string or Unix timestamp if `$format` is 'U' or 'G'. |
2874 |
* False on failure. |
|
0 | 2875 |
*/ |
16 | 2876 |
function get_post_modified_time( $format = 'U', $gmt = false, $post = null, $translate = false ) { |
9 | 2877 |
$post = get_post( $post ); |
0 | 2878 |
|
5 | 2879 |
if ( ! $post ) { |
2880 |
return false; |
|
2881 |
} |
|
2882 |
||
16 | 2883 |
$source = ( $gmt ) ? 'gmt' : 'local'; |
2884 |
$datetime = get_post_datetime( $post, 'modified', $source ); |
|
2885 |
||
2886 |
if ( false === $datetime ) { |
|
2887 |
return false; |
|
2888 |
} |
|
2889 |
||
2890 |
if ( 'U' === $format || 'G' === $format ) { |
|
2891 |
$time = $datetime->getTimestamp(); |
|
2892 |
||
2893 |
// Returns a sum of timestamp with timezone offset. Ideally should never be used. |
|
2894 |
if ( ! $gmt ) { |
|
2895 |
$time += $datetime->getOffset(); |
|
2896 |
} |
|
2897 |
} elseif ( $translate ) { |
|
2898 |
$time = wp_date( $format, $datetime->getTimestamp(), $gmt ? new DateTimeZone( 'UTC' ) : null ); |
|
9 | 2899 |
} else { |
16 | 2900 |
if ( $gmt ) { |
2901 |
$datetime = $datetime->setTimezone( new DateTimeZone( 'UTC' ) ); |
|
2902 |
} |
|
2903 |
||
2904 |
$time = $datetime->format( $format ); |
|
9 | 2905 |
} |
0 | 2906 |
|
5 | 2907 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2908 |
* Filters the localized time a post was last modified. |
5 | 2909 |
* |
2910 |
* @since 2.8.0 |
|
2911 |
* |
|
16 | 2912 |
* @param string $time The formatted time. |
2913 |
* @param string $format Format to use for retrieving the time the post was modified. |
|
2914 |
* Accepts 'G', 'U', or PHP date format. Default 'U'. |
|
2915 |
* @param bool $gmt Whether to retrieve the GMT time. Default false. |
|
5 | 2916 |
*/ |
16 | 2917 |
return apply_filters( 'get_post_modified_time', $time, $format, $gmt ); |
0 | 2918 |
} |
2919 |
||
2920 |
/** |
|
2921 |
* Display the weekday on which the post was written. |
|
2922 |
* |
|
2923 |
* @since 0.71 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2924 |
* |
16 | 2925 |
* @global WP_Locale $wp_locale WordPress date and time locale object. |
0 | 2926 |
*/ |
2927 |
function the_weekday() { |
|
2928 |
global $wp_locale; |
|
16 | 2929 |
|
2930 |
$post = get_post(); |
|
2931 |
||
2932 |
if ( ! $post ) { |
|
2933 |
return; |
|
2934 |
} |
|
2935 |
||
2936 |
$the_weekday = $wp_locale->get_weekday( get_post_time( 'w', false, $post ) ); |
|
5 | 2937 |
|
2938 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2939 |
* Filters the weekday on which the post was written, for display. |
5 | 2940 |
* |
2941 |
* @since 0.71 |
|
2942 |
* |
|
2943 |
* @param string $the_weekday |
|
2944 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2945 |
echo apply_filters( 'the_weekday', $the_weekday ); |
0 | 2946 |
} |
2947 |
||
2948 |
/** |
|
2949 |
* Display the weekday on which the post was written. |
|
2950 |
* |
|
2951 |
* Will only output the weekday if the current post's weekday is different from |
|
2952 |
* the previous one output. |
|
2953 |
* |
|
2954 |
* @since 0.71 |
|
2955 |
* |
|
16 | 2956 |
* @global WP_Locale $wp_locale WordPress date and time locale object. |
2957 |
* @global string $currentday The day of the current post in the loop. |
|
2958 |
* @global string $previousweekday The day of the previous post in the loop. |
|
2959 |
* |
|
2960 |
* @param string $before Optional. Output before the date. |
|
2961 |
* @param string $after Optional. Output after the date. |
|
0 | 2962 |
*/ |
9 | 2963 |
function the_weekday_date( $before = '', $after = '' ) { |
0 | 2964 |
global $wp_locale, $currentday, $previousweekday; |
16 | 2965 |
|
2966 |
$post = get_post(); |
|
2967 |
||
2968 |
if ( ! $post ) { |
|
2969 |
return; |
|
2970 |
} |
|
2971 |
||
0 | 2972 |
$the_weekday_date = ''; |
16 | 2973 |
|
2974 |
if ( $currentday !== $previousweekday ) { |
|
0 | 2975 |
$the_weekday_date .= $before; |
16 | 2976 |
$the_weekday_date .= $wp_locale->get_weekday( get_post_time( 'w', false, $post ) ); |
0 | 2977 |
$the_weekday_date .= $after; |
9 | 2978 |
$previousweekday = $currentday; |
0 | 2979 |
} |
5 | 2980 |
|
2981 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2982 |
* Filters the localized date on which the post was written, for display. |
5 | 2983 |
* |
2984 |
* @since 0.71 |
|
2985 |
* |
|
16 | 2986 |
* @param string $the_weekday_date The weekday on which the post was written. |
5 | 2987 |
* @param string $before The HTML to output before the date. |
2988 |
* @param string $after The HTML to output after the date. |
|
2989 |
*/ |
|
16 | 2990 |
echo apply_filters( 'the_weekday_date', $the_weekday_date, $before, $after ); |
0 | 2991 |
} |
2992 |
||
2993 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2994 |
* Fire the wp_head action. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2995 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2996 |
* See {@see 'wp_head'}. |
0 | 2997 |
* |
2998 |
* @since 1.2.0 |
|
2999 |
*/ |
|
3000 |
function wp_head() { |
|
5 | 3001 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3002 |
* Prints scripts or data in the head tag on the front end. |
5 | 3003 |
* |
3004 |
* @since 1.5.0 |
|
3005 |
*/ |
|
3006 |
do_action( 'wp_head' ); |
|
0 | 3007 |
} |
3008 |
||
3009 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3010 |
* Fire the wp_footer action. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3011 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3012 |
* See {@see 'wp_footer'}. |
0 | 3013 |
* |
3014 |
* @since 1.5.1 |
|
3015 |
*/ |
|
3016 |
function wp_footer() { |
|
5 | 3017 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3018 |
* Prints scripts or data before the closing body tag on the front end. |
5 | 3019 |
* |
3020 |
* @since 1.5.1 |
|
3021 |
*/ |
|
3022 |
do_action( 'wp_footer' ); |
|
0 | 3023 |
} |
3024 |
||
3025 |
/** |
|
9 | 3026 |
* Fire the wp_body_open action. |
3027 |
* |
|
16 | 3028 |
* See {@see 'wp_body_open'}. |
9 | 3029 |
* |
3030 |
* @since 5.2.0 |
|
3031 |
*/ |
|
3032 |
function wp_body_open() { |
|
3033 |
/** |
|
16 | 3034 |
* Triggered after the opening body tag. |
9 | 3035 |
* |
3036 |
* @since 5.2.0 |
|
3037 |
*/ |
|
3038 |
do_action( 'wp_body_open' ); |
|
3039 |
} |
|
3040 |
||
3041 |
/** |
|
0 | 3042 |
* Display the links to the general feeds. |
3043 |
* |
|
3044 |
* @since 2.8.0 |
|
3045 |
* |
|
3046 |
* @param array $args Optional arguments. |
|
3047 |
*/ |
|
3048 |
function feed_links( $args = array() ) { |
|
9 | 3049 |
if ( ! current_theme_supports( 'automatic-feed-links' ) ) { |
0 | 3050 |
return; |
9 | 3051 |
} |
0 | 3052 |
|
3053 |
$defaults = array( |
|
16 | 3054 |
/* translators: Separator between blog name and feed type in feed links. */ |
9 | 3055 |
'separator' => _x( '»', 'feed link' ), |
16 | 3056 |
/* translators: 1: Blog title, 2: Separator (raquo). */ |
9 | 3057 |
'feedtitle' => __( '%1$s %2$s Feed' ), |
16 | 3058 |
/* translators: 1: Blog title, 2: Separator (raquo). */ |
9 | 3059 |
'comstitle' => __( '%1$s %2$s Comments Feed' ), |
0 | 3060 |
); |
3061 |
||
3062 |
$args = wp_parse_args( $args, $defaults ); |
|
3063 |
||
7
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 |
* Filters whether to display the posts feed link. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3066 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3067 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3068 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3069 |
* @param bool $show Whether to display the posts feed link. Default true. |
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 |
if ( apply_filters( 'feed_links_show_posts_feed', true ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3072 |
echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . esc_attr( sprintf( $args['feedtitle'], get_bloginfo( 'name' ), $args['separator'] ) ) . '" href="' . esc_url( get_feed_link() ) . "\" />\n"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3073 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3074 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3075 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3076 |
* Filters whether to display the comments feed link. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3077 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3078 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3079 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3080 |
* @param bool $show Whether to display the comments feed link. Default true. |
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 |
if ( apply_filters( 'feed_links_show_comments_feed', true ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3083 |
echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . esc_attr( sprintf( $args['comstitle'], get_bloginfo( 'name' ), $args['separator'] ) ) . '" href="' . esc_url( get_feed_link( 'comments_' . get_default_feed() ) ) . "\" />\n"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3084 |
} |
0 | 3085 |
} |
3086 |
||
3087 |
/** |
|
3088 |
* Display the links to the extra feeds such as category feeds. |
|
3089 |
* |
|
3090 |
* @since 2.8.0 |
|
3091 |
* |
|
3092 |
* @param array $args Optional arguments. |
|
3093 |
*/ |
|
3094 |
function feed_links_extra( $args = array() ) { |
|
3095 |
$defaults = array( |
|
16 | 3096 |
/* translators: Separator between blog name and feed type in feed links. */ |
9 | 3097 |
'separator' => _x( '»', 'feed link' ), |
16 | 3098 |
/* translators: 1: Blog name, 2: Separator (raquo), 3: Post title. */ |
9 | 3099 |
'singletitle' => __( '%1$s %2$s %3$s Comments Feed' ), |
16 | 3100 |
/* translators: 1: Blog name, 2: Separator (raquo), 3: Category name. */ |
9 | 3101 |
'cattitle' => __( '%1$s %2$s %3$s Category Feed' ), |
16 | 3102 |
/* translators: 1: Blog name, 2: Separator (raquo), 3: Tag name. */ |
9 | 3103 |
'tagtitle' => __( '%1$s %2$s %3$s Tag Feed' ), |
16 | 3104 |
/* translators: 1: Blog name, 2: Separator (raquo), 3: Term name, 4: Taxonomy singular name. */ |
9 | 3105 |
'taxtitle' => __( '%1$s %2$s %3$s %4$s Feed' ), |
16 | 3106 |
/* translators: 1: Blog name, 2: Separator (raquo), 3: Author name. */ |
9 | 3107 |
'authortitle' => __( '%1$s %2$s Posts by %3$s Feed' ), |
16 | 3108 |
/* translators: 1: Blog name, 2: Separator (raquo), 3: Search query. */ |
9 | 3109 |
'searchtitle' => __( '%1$s %2$s Search Results for “%3$s” Feed' ), |
16 | 3110 |
/* translators: 1: Blog name, 2: Separator (raquo), 3: Post type name. */ |
9 | 3111 |
'posttypetitle' => __( '%1$s %2$s %3$s Feed' ), |
0 | 3112 |
); |
3113 |
||
3114 |
$args = wp_parse_args( $args, $defaults ); |
|
3115 |
||
3116 |
if ( is_singular() ) { |
|
9 | 3117 |
$id = 0; |
0 | 3118 |
$post = get_post( $id ); |
3119 |
||
3120 |
if ( comments_open() || pings_open() || $post->comment_count > 0 ) { |
|
9 | 3121 |
$title = sprintf( $args['singletitle'], get_bloginfo( 'name' ), $args['separator'], the_title_attribute( array( 'echo' => false ) ) ); |
3122 |
$href = get_post_comments_feed_link( $post->ID ); |
|
0 | 3123 |
} |
3124 |
} elseif ( is_post_type_archive() ) { |
|
3125 |
$post_type = get_query_var( 'post_type' ); |
|
9 | 3126 |
if ( is_array( $post_type ) ) { |
0 | 3127 |
$post_type = reset( $post_type ); |
9 | 3128 |
} |
0 | 3129 |
|
3130 |
$post_type_obj = get_post_type_object( $post_type ); |
|
9 | 3131 |
$title = sprintf( $args['posttypetitle'], get_bloginfo( 'name' ), $args['separator'], $post_type_obj->labels->name ); |
3132 |
$href = get_post_type_archive_feed_link( $post_type_obj->name ); |
|
0 | 3133 |
} elseif ( is_category() ) { |
3134 |
$term = get_queried_object(); |
|
3135 |
||
3136 |
if ( $term ) { |
|
9 | 3137 |
$title = sprintf( $args['cattitle'], get_bloginfo( 'name' ), $args['separator'], $term->name ); |
3138 |
$href = get_category_feed_link( $term->term_id ); |
|
0 | 3139 |
} |
3140 |
} elseif ( is_tag() ) { |
|
3141 |
$term = get_queried_object(); |
|
3142 |
||
3143 |
if ( $term ) { |
|
9 | 3144 |
$title = sprintf( $args['tagtitle'], get_bloginfo( 'name' ), $args['separator'], $term->name ); |
3145 |
$href = get_tag_feed_link( $term->term_id ); |
|
0 | 3146 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3147 |
} elseif ( is_tax() ) { |
16 | 3148 |
$term = get_queried_object(); |
3149 |
||
3150 |
if ( $term ) { |
|
3151 |
$tax = get_taxonomy( $term->taxonomy ); |
|
3152 |
$title = sprintf( $args['taxtitle'], get_bloginfo( 'name' ), $args['separator'], $term->name, $tax->labels->singular_name ); |
|
3153 |
$href = get_term_feed_link( $term->term_id, $term->taxonomy ); |
|
3154 |
} |
|
0 | 3155 |
} elseif ( is_author() ) { |
9 | 3156 |
$author_id = intval( get_query_var( 'author' ) ); |
3157 |
||
3158 |
$title = sprintf( $args['authortitle'], get_bloginfo( 'name' ), $args['separator'], get_the_author_meta( 'display_name', $author_id ) ); |
|
3159 |
$href = get_author_feed_link( $author_id ); |
|
0 | 3160 |
} elseif ( is_search() ) { |
9 | 3161 |
$title = sprintf( $args['searchtitle'], get_bloginfo( 'name' ), $args['separator'], get_search_query( false ) ); |
3162 |
$href = get_search_feed_link(); |
|
0 | 3163 |
} |
3164 |
||
9 | 3165 |
if ( isset( $title ) && isset( $href ) ) { |
0 | 3166 |
echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . esc_attr( $title ) . '" href="' . esc_url( $href ) . '" />' . "\n"; |
9 | 3167 |
} |
0 | 3168 |
} |
3169 |
||
3170 |
/** |
|
3171 |
* Display the link to the Really Simple Discovery service endpoint. |
|
3172 |
* |
|
3173 |
* @link http://archipelago.phrasewise.com/rsd |
|
3174 |
* @since 2.0.0 |
|
3175 |
*/ |
|
3176 |
function rsd_link() { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3177 |
echo '<link rel="EditURI" type="application/rsd+xml" title="RSD" href="' . esc_url( site_url( 'xmlrpc.php?rsd', 'rpc' ) ) . '" />' . "\n"; |
0 | 3178 |
} |
3179 |
||
3180 |
/** |
|
3181 |
* Display the link to the Windows Live Writer manifest file. |
|
3182 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3183 |
* @link https://msdn.microsoft.com/en-us/library/bb463265.aspx |
0 | 3184 |
* @since 2.3.1 |
3185 |
*/ |
|
3186 |
function wlwmanifest_link() { |
|
16 | 3187 |
echo '<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="' . includes_url( 'wlwmanifest.xml' ) . '" /> ' . "\n"; |
0 | 3188 |
} |
3189 |
||
3190 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3191 |
* Displays a noindex meta tag if required by the blog configuration. |
0 | 3192 |
* |
3193 |
* If a blog is marked as not being public then the noindex meta tag will be |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3194 |
* output to tell web robots not to index the page content. Add this to the |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3195 |
* {@see 'wp_head'} action. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3196 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3197 |
* Typical usage is as a {@see 'wp_head'} callback: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3198 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3199 |
* add_action( 'wp_head', 'noindex' ); |
0 | 3200 |
* |
3201 |
* @see wp_no_robots |
|
3202 |
* |
|
3203 |
* @since 2.1.0 |
|
3204 |
*/ |
|
3205 |
function noindex() { |
|
3206 |
// If the blog is not public, tell robots to go away. |
|
9 | 3207 |
if ( '0' == get_option( 'blog_public' ) ) { |
0 | 3208 |
wp_no_robots(); |
9 | 3209 |
} |
0 | 3210 |
} |
3211 |
||
3212 |
/** |
|
3213 |
* Display a noindex meta tag. |
|
3214 |
* |
|
3215 |
* Outputs a noindex meta tag that tells web robots not to index the page content. |
|
16 | 3216 |
* Typical usage is as a {@see 'wp_head'} callback. add_action( 'wp_head', 'wp_no_robots' ); |
0 | 3217 |
* |
3218 |
* @since 3.3.0 |
|
16 | 3219 |
* @since 5.3.0 Echo "noindex,nofollow" if search engine visibility is discouraged. |
0 | 3220 |
*/ |
3221 |
function wp_no_robots() { |
|
16 | 3222 |
if ( get_option( 'blog_public' ) ) { |
3223 |
echo "<meta name='robots' content='noindex,follow' />\n"; |
|
3224 |
return; |
|
3225 |
} |
|
3226 |
||
3227 |
echo "<meta name='robots' content='noindex,nofollow' />\n"; |
|
0 | 3228 |
} |
3229 |
||
3230 |
/** |
|
9 | 3231 |
* Display a noindex,noarchive meta tag and referrer origin-when-cross-origin meta tag. |
3232 |
* |
|
3233 |
* Outputs a noindex,noarchive meta tag that tells web robots not to index or cache the page content. |
|
3234 |
* Outputs a referrer origin-when-cross-origin meta tag that tells the browser not to send the full |
|
3235 |
* url as a referrer to other sites when cross-origin assets are loaded. |
|
3236 |
* |
|
3237 |
* Typical usage is as a wp_head callback. add_action( 'wp_head', 'wp_sensitive_page_meta' ); |
|
3238 |
* |
|
3239 |
* @since 5.0.1 |
|
3240 |
*/ |
|
3241 |
function wp_sensitive_page_meta() { |
|
3242 |
?> |
|
3243 |
<meta name='robots' content='noindex,noarchive' /> |
|
3244 |
<meta name='referrer' content='strict-origin-when-cross-origin' /> |
|
3245 |
<?php |
|
3246 |
} |
|
3247 |
||
3248 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3249 |
* Display site icon meta tags. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3250 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3251 |
* @since 4.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3252 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3253 |
* @link https://www.whatwg.org/specs/web-apps/current-work/multipage/links.html#rel-icon HTML5 specification link icon. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3254 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3255 |
function wp_site_icon() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3256 |
if ( ! has_site_icon() && ! is_customize_preview() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3257 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3258 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3259 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3260 |
$meta_tags = array(); |
9 | 3261 |
$icon_32 = get_site_icon_url( 32 ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3262 |
if ( empty( $icon_32 ) && is_customize_preview() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3263 |
$icon_32 = '/favicon.ico'; // Serve default favicon URL in customizer so element can be updated for preview. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3264 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3265 |
if ( $icon_32 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3266 |
$meta_tags[] = sprintf( '<link rel="icon" href="%s" sizes="32x32" />', esc_url( $icon_32 ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3267 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3268 |
$icon_192 = get_site_icon_url( 192 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3269 |
if ( $icon_192 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3270 |
$meta_tags[] = sprintf( '<link rel="icon" href="%s" sizes="192x192" />', esc_url( $icon_192 ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3271 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3272 |
$icon_180 = get_site_icon_url( 180 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3273 |
if ( $icon_180 ) { |
16 | 3274 |
$meta_tags[] = sprintf( '<link rel="apple-touch-icon" href="%s" />', esc_url( $icon_180 ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3275 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3276 |
$icon_270 = get_site_icon_url( 270 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3277 |
if ( $icon_270 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3278 |
$meta_tags[] = sprintf( '<meta name="msapplication-TileImage" content="%s" />', esc_url( $icon_270 ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3279 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3280 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3281 |
/** |
9 | 3282 |
* Filters the site icon meta tags, so plugins can add their own. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3283 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3284 |
* @since 4.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3285 |
* |
9 | 3286 |
* @param string[] $meta_tags Array of Site Icon meta tags. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3287 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3288 |
$meta_tags = apply_filters( 'site_icon_meta_tags', $meta_tags ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3289 |
$meta_tags = array_filter( $meta_tags ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3290 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3291 |
foreach ( $meta_tags as $meta_tag ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3292 |
echo "$meta_tag\n"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3293 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3294 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3295 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3296 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3297 |
* Prints resource hints to browsers for pre-fetching, pre-rendering |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3298 |
* and pre-connecting to web sites. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3299 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3300 |
* Gives hints to browsers to prefetch specific pages or render them |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3301 |
* in the background, to perform DNS lookups or to begin the connection |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3302 |
* handshake (DNS, TCP, TLS) in the background. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3303 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3304 |
* These performance improving indicators work by using `<link rel"…">`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3305 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3306 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3307 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3308 |
function wp_resource_hints() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3309 |
$hints = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3310 |
'dns-prefetch' => wp_dependencies_unique_hosts(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3311 |
'preconnect' => array(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3312 |
'prefetch' => array(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3313 |
'prerender' => array(), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3314 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3315 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3316 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3317 |
* Add DNS prefetch for the Emoji CDN. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3318 |
* The path is removed in the foreach loop below. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3319 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3320 |
/** This filter is documented in wp-includes/formatting.php */ |
16 | 3321 |
$hints['dns-prefetch'][] = apply_filters( 'emoji_svg_url', 'https://s.w.org/images/core/emoji/13.0.0/svg/' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3322 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3323 |
foreach ( $hints as $relation_type => $urls ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3324 |
$unique_urls = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3325 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3326 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3327 |
* Filters domains and URLs for resource hints of relation type. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3328 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3329 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3330 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3331 |
* @param array $urls URLs to print for resource hints. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3332 |
* @param string $relation_type The relation type the URLs are printed for, e.g. 'preconnect' or 'prerender'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3333 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3334 |
$urls = apply_filters( 'wp_resource_hints', $urls, $relation_type ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3335 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3336 |
foreach ( $urls as $key => $url ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3337 |
$atts = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3338 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3339 |
if ( is_array( $url ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3340 |
if ( isset( $url['href'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3341 |
$atts = $url; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3342 |
$url = $url['href']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3343 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3344 |
continue; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3345 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3346 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3347 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3348 |
$url = esc_url( $url, array( 'http', 'https' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3349 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3350 |
if ( ! $url ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3351 |
continue; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3352 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3353 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3354 |
if ( isset( $unique_urls[ $url ] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3355 |
continue; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3356 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3357 |
|
16 | 3358 |
if ( in_array( $relation_type, array( 'preconnect', 'dns-prefetch' ), true ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3359 |
$parsed = wp_parse_url( $url ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3360 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3361 |
if ( empty( $parsed['host'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3362 |
continue; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3363 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3364 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3365 |
if ( 'preconnect' === $relation_type && ! empty( $parsed['scheme'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3366 |
$url = $parsed['scheme'] . '://' . $parsed['host']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3367 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3368 |
// Use protocol-relative URLs for dns-prefetch or if scheme is missing. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3369 |
$url = '//' . $parsed['host']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3370 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3371 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3372 |
|
9 | 3373 |
$atts['rel'] = $relation_type; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3374 |
$atts['href'] = $url; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3375 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3376 |
$unique_urls[ $url ] = $atts; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3377 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3378 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3379 |
foreach ( $unique_urls as $atts ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3380 |
$html = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3381 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3382 |
foreach ( $atts as $attr => $value ) { |
16 | 3383 |
if ( ! is_scalar( $value ) |
3384 |
|| ( ! in_array( $attr, array( 'as', 'crossorigin', 'href', 'pr', 'rel', 'type' ), true ) && ! is_numeric( $attr ) ) |
|
3385 |
) { |
|
9 | 3386 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3387 |
continue; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3388 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3389 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3390 |
$value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3391 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3392 |
if ( ! is_string( $attr ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3393 |
$html .= " $value"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3394 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3395 |
$html .= " $attr='$value'"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3396 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3397 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3398 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3399 |
$html = trim( $html ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3400 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3401 |
echo "<link $html />\n"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3402 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3403 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3404 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3405 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3406 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3407 |
* Retrieves a list of unique hosts of all enqueued scripts and styles. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3408 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3409 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3410 |
* |
16 | 3411 |
* @return string[] A list of unique hosts of enqueued scripts and styles. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3412 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3413 |
function wp_dependencies_unique_hosts() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3414 |
global $wp_scripts, $wp_styles; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3415 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3416 |
$unique_hosts = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3417 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3418 |
foreach ( array( $wp_scripts, $wp_styles ) as $dependencies ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3419 |
if ( $dependencies instanceof WP_Dependencies && ! empty( $dependencies->queue ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3420 |
foreach ( $dependencies->queue as $handle ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3421 |
if ( ! isset( $dependencies->registered[ $handle ] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3422 |
continue; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3423 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3424 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3425 |
/* @var _WP_Dependency $dependency */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3426 |
$dependency = $dependencies->registered[ $handle ]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3427 |
$parsed = wp_parse_url( $dependency->src ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3428 |
|
16 | 3429 |
if ( ! empty( $parsed['host'] ) |
3430 |
&& ! in_array( $parsed['host'], $unique_hosts, true ) && $parsed['host'] !== $_SERVER['SERVER_NAME'] |
|
3431 |
) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3432 |
$unique_hosts[] = $parsed['host']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3433 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3434 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3435 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3436 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3437 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3438 |
return $unique_hosts; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3439 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3440 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3441 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3442 |
* Whether the user can access the visual editor. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3443 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3444 |
* Checks if the user can access the visual editor and that it's supported by the user's browser. |
0 | 3445 |
* |
3446 |
* @since 2.0.0 |
|
3447 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3448 |
* @global bool $wp_rich_edit Whether the user can access the visual editor. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3449 |
* @global bool $is_gecko Whether the browser is Gecko-based. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3450 |
* @global bool $is_opera Whether the browser is Opera. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3451 |
* @global bool $is_safari Whether the browser is Safari. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3452 |
* @global bool $is_chrome Whether the browser is Chrome. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3453 |
* @global bool $is_IE Whether the browser is Internet Explorer. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3454 |
* @global bool $is_edge Whether the browser is Microsoft Edge. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3455 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3456 |
* @return bool True if the user can access the visual editor, false otherwise. |
0 | 3457 |
*/ |
3458 |
function user_can_richedit() { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3459 |
global $wp_rich_edit, $is_gecko, $is_opera, $is_safari, $is_chrome, $is_IE, $is_edge; |
0 | 3460 |
|
9 | 3461 |
if ( ! isset( $wp_rich_edit ) ) { |
0 | 3462 |
$wp_rich_edit = false; |
3463 |
||
16 | 3464 |
if ( 'true' === get_user_option( 'rich_editing' ) || ! is_user_logged_in() ) { // Default to 'true' for logged out users. |
0 | 3465 |
if ( $is_safari ) { |
3466 |
$wp_rich_edit = ! wp_is_mobile() || ( preg_match( '!AppleWebKit/(\d+)!', $_SERVER['HTTP_USER_AGENT'], $match ) && intval( $match[1] ) >= 534 ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3467 |
} elseif ( $is_IE ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3468 |
$wp_rich_edit = ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Trident/7.0;' ) !== false ); |
9 | 3469 |
} elseif ( $is_gecko || $is_chrome || $is_edge || ( $is_opera && ! wp_is_mobile() ) ) { |
0 | 3470 |
$wp_rich_edit = true; |
3471 |
} |
|
3472 |
} |
|
3473 |
} |
|
3474 |
||
5 | 3475 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3476 |
* Filters whether the user can access the visual editor. |
5 | 3477 |
* |
3478 |
* @since 2.1.0 |
|
3479 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3480 |
* @param bool $wp_rich_edit Whether the user can access the visual editor. |
5 | 3481 |
*/ |
3482 |
return apply_filters( 'user_can_richedit', $wp_rich_edit ); |
|
0 | 3483 |
} |
3484 |
||
3485 |
/** |
|
3486 |
* Find out which editor should be displayed by default. |
|
3487 |
* |
|
3488 |
* Works out which of the two editors to display as the current editor for a |
|
3489 |
* user. The 'html' setting is for the "Text" editor tab. |
|
3490 |
* |
|
3491 |
* @since 2.5.0 |
|
3492 |
* |
|
3493 |
* @return string Either 'tinymce', or 'html', or 'test' |
|
3494 |
*/ |
|
3495 |
function wp_default_editor() { |
|
16 | 3496 |
$r = user_can_richedit() ? 'tinymce' : 'html'; // Defaults. |
3497 |
if ( wp_get_current_user() ) { // Look for cookie. |
|
9 | 3498 |
$ed = get_user_setting( 'editor', 'tinymce' ); |
16 | 3499 |
$r = ( in_array( $ed, array( 'tinymce', 'html', 'test' ), true ) ) ? $ed : $r; |
0 | 3500 |
} |
5 | 3501 |
|
3502 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3503 |
* Filters which editor should be displayed by default. |
5 | 3504 |
* |
3505 |
* @since 2.5.0 |
|
3506 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3507 |
* @param string $r Which editor should be displayed by default. Either 'tinymce', 'html', or 'test'. |
5 | 3508 |
*/ |
3509 |
return apply_filters( 'wp_default_editor', $r ); |
|
0 | 3510 |
} |
3511 |
||
3512 |
/** |
|
3513 |
* Renders an editor. |
|
3514 |
* |
|
3515 |
* Using this function is the proper way to output all needed components for both TinyMCE and Quicktags. |
|
5 | 3516 |
* _WP_Editors should not be used directly. See https://core.trac.wordpress.org/ticket/17144. |
0 | 3517 |
* |
3518 |
* NOTE: Once initialized the TinyMCE editor cannot be safely moved in the DOM. For that reason |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3519 |
* running wp_editor() inside of a meta box is not a good idea unless only Quicktags is used. |
0 | 3520 |
* On the post edit screen several actions can be used to include additional editors |
3521 |
* containing TinyMCE: 'edit_page_form', 'edit_form_advanced' and 'dbx_post_sidebar'. |
|
5 | 3522 |
* See https://core.trac.wordpress.org/ticket/19173 for more information. |
0 | 3523 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3524 |
* @see _WP_Editors::editor() |
16 | 3525 |
* @see _WP_Editors::parse_settings() |
0 | 3526 |
* @since 3.3.0 |
3527 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3528 |
* @param string $content Initial content for the editor. |
16 | 3529 |
* @param string $editor_id HTML ID attribute value for the textarea and TinyMCE. |
3530 |
* Should not contain square brackets. |
|
3531 |
* @param array $settings See _WP_Editors::parse_settings() for description. |
|
0 | 3532 |
*/ |
3533 |
function wp_editor( $content, $editor_id, $settings = array() ) { |
|
9 | 3534 |
if ( ! class_exists( '_WP_Editors', false ) ) { |
16 | 3535 |
require ABSPATH . WPINC . '/class-wp-editor.php'; |
9 | 3536 |
} |
3537 |
_WP_Editors::editor( $content, $editor_id, $settings ); |
|
0 | 3538 |
} |
3539 |
||
3540 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3541 |
* Outputs the editor scripts, stylesheets, and default settings. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3542 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3543 |
* The editor can be initialized when needed after page load. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3544 |
* See wp.editor.initialize() in wp-admin/js/editor.js for initialization options. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3545 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3546 |
* @uses _WP_Editors |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3547 |
* @since 4.8.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3548 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3549 |
function wp_enqueue_editor() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3550 |
if ( ! class_exists( '_WP_Editors', false ) ) { |
16 | 3551 |
require ABSPATH . WPINC . '/class-wp-editor.php'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3552 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3553 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3554 |
_WP_Editors::enqueue_default_editor(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3555 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3556 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3557 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3558 |
* Enqueue assets needed by the code editor for the given settings. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3559 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3560 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3561 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3562 |
* @see wp_enqueue_editor() |
9 | 3563 |
* @see wp_get_code_editor_settings(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3564 |
* @see _WP_Editors::parse_settings() |
9 | 3565 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3566 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3567 |
* Args. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3568 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3569 |
* @type string $type The MIME type of the file to be edited. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3570 |
* @type string $file Filename to be edited. Extension is used to sniff the type. Can be supplied as alternative to `$type` param. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3571 |
* @type WP_Theme $theme Theme being edited when on theme editor. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3572 |
* @type string $plugin Plugin being edited when on plugin editor. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3573 |
* @type array $codemirror Additional CodeMirror setting overrides. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3574 |
* @type array $csslint CSSLint rule overrides. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3575 |
* @type array $jshint JSHint rule overrides. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3576 |
* @type array $htmlhint JSHint rule overrides. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3577 |
* } |
9 | 3578 |
* @return array|false Settings for the enqueued code editor, or false if the editor was not enqueued. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3579 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3580 |
function wp_enqueue_code_editor( $args ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3581 |
if ( is_user_logged_in() && 'false' === wp_get_current_user()->syntax_highlighting ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3582 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3583 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3584 |
|
9 | 3585 |
$settings = wp_get_code_editor_settings( $args ); |
3586 |
||
3587 |
if ( empty( $settings ) || empty( $settings['codemirror'] ) ) { |
|
3588 |
return false; |
|
3589 |
} |
|
3590 |
||
3591 |
wp_enqueue_script( 'code-editor' ); |
|
3592 |
wp_enqueue_style( 'code-editor' ); |
|
3593 |
||
3594 |
if ( isset( $settings['codemirror']['mode'] ) ) { |
|
3595 |
$mode = $settings['codemirror']['mode']; |
|
3596 |
if ( is_string( $mode ) ) { |
|
3597 |
$mode = array( |
|
3598 |
'name' => $mode, |
|
3599 |
); |
|
3600 |
} |
|
3601 |
||
3602 |
if ( ! empty( $settings['codemirror']['lint'] ) ) { |
|
3603 |
switch ( $mode['name'] ) { |
|
3604 |
case 'css': |
|
3605 |
case 'text/css': |
|
3606 |
case 'text/x-scss': |
|
3607 |
case 'text/x-less': |
|
3608 |
wp_enqueue_script( 'csslint' ); |
|
3609 |
break; |
|
3610 |
case 'htmlmixed': |
|
3611 |
case 'text/html': |
|
3612 |
case 'php': |
|
3613 |
case 'application/x-httpd-php': |
|
3614 |
case 'text/x-php': |
|
3615 |
wp_enqueue_script( 'htmlhint' ); |
|
3616 |
wp_enqueue_script( 'csslint' ); |
|
3617 |
wp_enqueue_script( 'jshint' ); |
|
3618 |
if ( ! current_user_can( 'unfiltered_html' ) ) { |
|
3619 |
wp_enqueue_script( 'htmlhint-kses' ); |
|
3620 |
} |
|
3621 |
break; |
|
3622 |
case 'javascript': |
|
3623 |
case 'application/ecmascript': |
|
3624 |
case 'application/json': |
|
3625 |
case 'application/javascript': |
|
3626 |
case 'application/ld+json': |
|
3627 |
case 'text/typescript': |
|
3628 |
case 'application/typescript': |
|
3629 |
wp_enqueue_script( 'jshint' ); |
|
3630 |
wp_enqueue_script( 'jsonlint' ); |
|
3631 |
break; |
|
3632 |
} |
|
3633 |
} |
|
3634 |
} |
|
3635 |
||
3636 |
wp_add_inline_script( 'code-editor', sprintf( 'jQuery.extend( wp.codeEditor.defaultSettings, %s );', wp_json_encode( $settings ) ) ); |
|
3637 |
||
3638 |
/** |
|
3639 |
* Fires when scripts and styles are enqueued for the code editor. |
|
3640 |
* |
|
3641 |
* @since 4.9.0 |
|
3642 |
* |
|
3643 |
* @param array $settings Settings for the enqueued code editor. |
|
3644 |
*/ |
|
3645 |
do_action( 'wp_enqueue_code_editor', $settings ); |
|
3646 |
||
3647 |
return $settings; |
|
3648 |
} |
|
3649 |
||
3650 |
/** |
|
3651 |
* Generate and return code editor settings. |
|
3652 |
* |
|
3653 |
* @since 5.0.0 |
|
3654 |
* |
|
3655 |
* @see wp_enqueue_code_editor() |
|
3656 |
* |
|
3657 |
* @param array $args { |
|
3658 |
* Args. |
|
3659 |
* |
|
3660 |
* @type string $type The MIME type of the file to be edited. |
|
3661 |
* @type string $file Filename to be edited. Extension is used to sniff the type. Can be supplied as alternative to `$type` param. |
|
3662 |
* @type WP_Theme $theme Theme being edited when on theme editor. |
|
3663 |
* @type string $plugin Plugin being edited when on plugin editor. |
|
3664 |
* @type array $codemirror Additional CodeMirror setting overrides. |
|
3665 |
* @type array $csslint CSSLint rule overrides. |
|
3666 |
* @type array $jshint JSHint rule overrides. |
|
3667 |
* @type array $htmlhint JSHint rule overrides. |
|
3668 |
* } |
|
3669 |
* @return array|false Settings for the code editor. |
|
3670 |
*/ |
|
3671 |
function wp_get_code_editor_settings( $args ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3672 |
$settings = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3673 |
'codemirror' => array( |
9 | 3674 |
'indentUnit' => 4, |
3675 |
'indentWithTabs' => true, |
|
3676 |
'inputStyle' => 'contenteditable', |
|
3677 |
'lineNumbers' => true, |
|
3678 |
'lineWrapping' => true, |
|
3679 |
'styleActiveLine' => true, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3680 |
'continueComments' => true, |
9 | 3681 |
'extraKeys' => array( |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3682 |
'Ctrl-Space' => 'autocomplete', |
9 | 3683 |
'Ctrl-/' => 'toggleComment', |
3684 |
'Cmd-/' => 'toggleComment', |
|
3685 |
'Alt-F' => 'findPersistent', |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3686 |
'Ctrl-F' => 'findPersistent', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3687 |
'Cmd-F' => 'findPersistent', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3688 |
), |
9 | 3689 |
'direction' => 'ltr', // Code is shown in LTR even in RTL languages. |
3690 |
'gutters' => array(), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3691 |
), |
9 | 3692 |
'csslint' => array( |
3693 |
'errors' => true, // Parsing errors. |
|
3694 |
'box-model' => true, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3695 |
'display-property-grouping' => true, |
9 | 3696 |
'duplicate-properties' => true, |
3697 |
'known-properties' => true, |
|
3698 |
'outline-none' => true, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3699 |
), |
9 | 3700 |
'jshint' => array( |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3701 |
// The following are copied from <https://github.com/WordPress/wordpress-develop/blob/4.8.1/.jshintrc>. |
9 | 3702 |
'boss' => true, |
3703 |
'curly' => true, |
|
3704 |
'eqeqeq' => true, |
|
3705 |
'eqnull' => true, |
|
3706 |
'es3' => true, |
|
3707 |
'expr' => true, |
|
3708 |
'immed' => true, |
|
3709 |
'noarg' => true, |
|
3710 |
'nonbsp' => true, |
|
3711 |
'onevar' => true, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3712 |
'quotmark' => 'single', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3713 |
'trailing' => true, |
9 | 3714 |
'undef' => true, |
3715 |
'unused' => true, |
|
3716 |
||
3717 |
'browser' => true, |
|
3718 |
||
3719 |
'globals' => array( |
|
3720 |
'_' => false, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3721 |
'Backbone' => false, |
9 | 3722 |
'jQuery' => false, |
3723 |
'JSON' => false, |
|
3724 |
'wp' => false, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3725 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3726 |
), |
9 | 3727 |
'htmlhint' => array( |
3728 |
'tagname-lowercase' => true, |
|
3729 |
'attr-lowercase' => true, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3730 |
'attr-value-double-quotes' => false, |
9 | 3731 |
'doctype-first' => false, |
3732 |
'tag-pair' => true, |
|
3733 |
'spec-char-escape' => true, |
|
3734 |
'id-unique' => true, |
|
3735 |
'src-not-empty' => true, |
|
3736 |
'attr-no-duplication' => true, |
|
3737 |
'alt-require' => true, |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3738 |
'space-tab-mixed-disabled' => 'tab', |
9 | 3739 |
'attr-unsafe-chars' => true, |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3740 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3741 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3742 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3743 |
$type = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3744 |
if ( isset( $args['type'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3745 |
$type = $args['type']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3746 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3747 |
// Remap MIME types to ones that CodeMirror modes will recognize. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3748 |
if ( 'application/x-patch' === $type || 'text/x-patch' === $type ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3749 |
$type = 'text/x-diff'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3750 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3751 |
} elseif ( isset( $args['file'] ) && false !== strpos( basename( $args['file'] ), '.' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3752 |
$extension = strtolower( pathinfo( $args['file'], PATHINFO_EXTENSION ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3753 |
foreach ( wp_get_mime_types() as $exts => $mime ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3754 |
if ( preg_match( '!^(' . $exts . ')$!i', $extension ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3755 |
$type = $mime; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3756 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3757 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3758 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3759 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3760 |
// Supply any types that are not matched by wp_get_mime_types(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3761 |
if ( empty( $type ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3762 |
switch ( $extension ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3763 |
case 'conf': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3764 |
$type = 'text/nginx'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3765 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3766 |
case 'css': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3767 |
$type = 'text/css'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3768 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3769 |
case 'diff': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3770 |
case 'patch': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3771 |
$type = 'text/x-diff'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3772 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3773 |
case 'html': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3774 |
case 'htm': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3775 |
$type = 'text/html'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3776 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3777 |
case 'http': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3778 |
$type = 'message/http'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3779 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3780 |
case 'js': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3781 |
$type = 'text/javascript'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3782 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3783 |
case 'json': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3784 |
$type = 'application/json'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3785 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3786 |
case 'jsx': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3787 |
$type = 'text/jsx'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3788 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3789 |
case 'less': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3790 |
$type = 'text/x-less'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3791 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3792 |
case 'md': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3793 |
$type = 'text/x-gfm'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3794 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3795 |
case 'php': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3796 |
case 'phtml': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3797 |
case 'php3': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3798 |
case 'php4': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3799 |
case 'php5': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3800 |
case 'php7': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3801 |
case 'phps': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3802 |
$type = 'application/x-httpd-php'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3803 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3804 |
case 'scss': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3805 |
$type = 'text/x-scss'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3806 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3807 |
case 'sass': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3808 |
$type = 'text/x-sass'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3809 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3810 |
case 'sh': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3811 |
case 'bash': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3812 |
$type = 'text/x-sh'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3813 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3814 |
case 'sql': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3815 |
$type = 'text/x-sql'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3816 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3817 |
case 'svg': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3818 |
$type = 'application/svg+xml'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3819 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3820 |
case 'xml': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3821 |
$type = 'text/xml'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3822 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3823 |
case 'yml': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3824 |
case 'yaml': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3825 |
$type = 'text/x-yaml'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3826 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3827 |
case 'txt': |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3828 |
default: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3829 |
$type = 'text/plain'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3830 |
break; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3831 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3832 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3833 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3834 |
|
16 | 3835 |
if ( in_array( $type, array( 'text/css', 'text/x-scss', 'text/x-less', 'text/x-sass' ), true ) ) { |
9 | 3836 |
$settings['codemirror'] = array_merge( |
3837 |
$settings['codemirror'], |
|
3838 |
array( |
|
3839 |
'mode' => $type, |
|
3840 |
'lint' => false, |
|
3841 |
'autoCloseBrackets' => true, |
|
3842 |
'matchBrackets' => true, |
|
3843 |
) |
|
3844 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3845 |
} elseif ( 'text/x-diff' === $type ) { |
9 | 3846 |
$settings['codemirror'] = array_merge( |
3847 |
$settings['codemirror'], |
|
3848 |
array( |
|
3849 |
'mode' => 'diff', |
|
3850 |
) |
|
3851 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3852 |
} elseif ( 'text/html' === $type ) { |
9 | 3853 |
$settings['codemirror'] = array_merge( |
3854 |
$settings['codemirror'], |
|
3855 |
array( |
|
3856 |
'mode' => 'htmlmixed', |
|
3857 |
'lint' => true, |
|
3858 |
'autoCloseBrackets' => true, |
|
3859 |
'autoCloseTags' => true, |
|
3860 |
'matchTags' => array( |
|
3861 |
'bothTags' => true, |
|
3862 |
), |
|
3863 |
) |
|
3864 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3865 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3866 |
if ( ! current_user_can( 'unfiltered_html' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3867 |
$settings['htmlhint']['kses'] = wp_kses_allowed_html( 'post' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3868 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3869 |
} elseif ( 'text/x-gfm' === $type ) { |
9 | 3870 |
$settings['codemirror'] = array_merge( |
3871 |
$settings['codemirror'], |
|
3872 |
array( |
|
3873 |
'mode' => 'gfm', |
|
3874 |
'highlightFormatting' => true, |
|
3875 |
) |
|
3876 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3877 |
} elseif ( 'application/javascript' === $type || 'text/javascript' === $type ) { |
9 | 3878 |
$settings['codemirror'] = array_merge( |
3879 |
$settings['codemirror'], |
|
3880 |
array( |
|
3881 |
'mode' => 'javascript', |
|
3882 |
'lint' => true, |
|
3883 |
'autoCloseBrackets' => true, |
|
3884 |
'matchBrackets' => true, |
|
3885 |
) |
|
3886 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3887 |
} elseif ( false !== strpos( $type, 'json' ) ) { |
9 | 3888 |
$settings['codemirror'] = array_merge( |
3889 |
$settings['codemirror'], |
|
3890 |
array( |
|
3891 |
'mode' => array( |
|
3892 |
'name' => 'javascript', |
|
3893 |
), |
|
3894 |
'lint' => true, |
|
3895 |
'autoCloseBrackets' => true, |
|
3896 |
'matchBrackets' => true, |
|
3897 |
) |
|
3898 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3899 |
if ( 'application/ld+json' === $type ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3900 |
$settings['codemirror']['mode']['jsonld'] = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3901 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3902 |
$settings['codemirror']['mode']['json'] = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3903 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3904 |
} elseif ( false !== strpos( $type, 'jsx' ) ) { |
9 | 3905 |
$settings['codemirror'] = array_merge( |
3906 |
$settings['codemirror'], |
|
3907 |
array( |
|
3908 |
'mode' => 'jsx', |
|
3909 |
'autoCloseBrackets' => true, |
|
3910 |
'matchBrackets' => true, |
|
3911 |
) |
|
3912 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3913 |
} elseif ( 'text/x-markdown' === $type ) { |
9 | 3914 |
$settings['codemirror'] = array_merge( |
3915 |
$settings['codemirror'], |
|
3916 |
array( |
|
3917 |
'mode' => 'markdown', |
|
3918 |
'highlightFormatting' => true, |
|
3919 |
) |
|
3920 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3921 |
} elseif ( 'text/nginx' === $type ) { |
9 | 3922 |
$settings['codemirror'] = array_merge( |
3923 |
$settings['codemirror'], |
|
3924 |
array( |
|
3925 |
'mode' => 'nginx', |
|
3926 |
) |
|
3927 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3928 |
} elseif ( 'application/x-httpd-php' === $type ) { |
9 | 3929 |
$settings['codemirror'] = array_merge( |
3930 |
$settings['codemirror'], |
|
3931 |
array( |
|
3932 |
'mode' => 'php', |
|
3933 |
'autoCloseBrackets' => true, |
|
3934 |
'autoCloseTags' => true, |
|
3935 |
'matchBrackets' => true, |
|
3936 |
'matchTags' => array( |
|
3937 |
'bothTags' => true, |
|
3938 |
), |
|
3939 |
) |
|
3940 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3941 |
} elseif ( 'text/x-sql' === $type || 'text/x-mysql' === $type ) { |
9 | 3942 |
$settings['codemirror'] = array_merge( |
3943 |
$settings['codemirror'], |
|
3944 |
array( |
|
3945 |
'mode' => 'sql', |
|
3946 |
'autoCloseBrackets' => true, |
|
3947 |
'matchBrackets' => true, |
|
3948 |
) |
|
3949 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3950 |
} elseif ( false !== strpos( $type, 'xml' ) ) { |
9 | 3951 |
$settings['codemirror'] = array_merge( |
3952 |
$settings['codemirror'], |
|
3953 |
array( |
|
3954 |
'mode' => 'xml', |
|
3955 |
'autoCloseBrackets' => true, |
|
3956 |
'autoCloseTags' => true, |
|
3957 |
'matchTags' => array( |
|
3958 |
'bothTags' => true, |
|
3959 |
), |
|
3960 |
) |
|
3961 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3962 |
} elseif ( 'text/x-yaml' === $type ) { |
9 | 3963 |
$settings['codemirror'] = array_merge( |
3964 |
$settings['codemirror'], |
|
3965 |
array( |
|
3966 |
'mode' => 'yaml', |
|
3967 |
) |
|
3968 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3969 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3970 |
$settings['codemirror']['mode'] = $type; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3971 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3972 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3973 |
if ( ! empty( $settings['codemirror']['lint'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3974 |
$settings['codemirror']['gutters'][] = 'CodeMirror-lint-markers'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3975 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3976 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3977 |
// Let settings supplied via args override any defaults. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3978 |
foreach ( wp_array_slice_assoc( $args, array( 'codemirror', 'csslint', 'jshint', 'htmlhint' ) ) as $key => $value ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3979 |
$settings[ $key ] = array_merge( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3980 |
$settings[ $key ], |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3981 |
$value |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3982 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3983 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3984 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3985 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3986 |
* Filters settings that are passed into the code editor. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3987 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3988 |
* Returning a falsey value will disable the syntax-highlighting code editor. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3989 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3990 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3991 |
* |
16 | 3992 |
* @param array $settings The array of settings passed to the code editor. |
3993 |
* A falsey value disables the editor. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3994 |
* @param array $args { |
9 | 3995 |
* Args passed when calling `get_code_editor_settings()`. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3996 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3997 |
* @type string $type The MIME type of the file to be edited. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3998 |
* @type string $file Filename being edited. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3999 |
* @type WP_Theme $theme Theme being edited when on theme editor. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4000 |
* @type string $plugin Plugin being edited when on plugin editor. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4001 |
* @type array $codemirror Additional CodeMirror setting overrides. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4002 |
* @type array $csslint CSSLint rule overrides. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4003 |
* @type array $jshint JSHint rule overrides. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4004 |
* @type array $htmlhint JSHint rule overrides. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4005 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4006 |
*/ |
9 | 4007 |
return apply_filters( 'wp_code_editor_settings', $settings, $args ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4008 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4009 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4010 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4011 |
* Retrieves the contents of the search WordPress query variable. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4012 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4013 |
* The search query string is passed through esc_attr() to ensure that it is safe |
16 | 4014 |
* for placing in an HTML attribute. |
0 | 4015 |
* |
4016 |
* @since 2.3.0 |
|
4017 |
* |
|
4018 |
* @param bool $escaped Whether the result is escaped. Default true. |
|
9 | 4019 |
* Only use when you are later escaping it. Do not use unescaped. |
0 | 4020 |
* @return string |
4021 |
*/ |
|
4022 |
function get_search_query( $escaped = true ) { |
|
5 | 4023 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4024 |
* Filters the contents of the search query variable. |
5 | 4025 |
* |
4026 |
* @since 2.3.0 |
|
4027 |
* |
|
4028 |
* @param mixed $search Contents of the search query variable. |
|
4029 |
*/ |
|
0 | 4030 |
$query = apply_filters( 'get_search_query', get_query_var( 's' ) ); |
5 | 4031 |
|
9 | 4032 |
if ( $escaped ) { |
0 | 4033 |
$query = esc_attr( $query ); |
9 | 4034 |
} |
0 | 4035 |
return $query; |
4036 |
} |
|
4037 |
||
4038 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4039 |
* Displays the contents of the search query variable. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4040 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4041 |
* The search query string is passed through esc_attr() to ensure that it is safe |
16 | 4042 |
* for placing in an HTML attribute. |
0 | 4043 |
* |
4044 |
* @since 2.1.0 |
|
4045 |
*/ |
|
4046 |
function the_search_query() { |
|
5 | 4047 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4048 |
* Filters the contents of the search query variable for display. |
5 | 4049 |
* |
4050 |
* @since 2.3.0 |
|
4051 |
* |
|
4052 |
* @param mixed $search Contents of the search query variable. |
|
4053 |
*/ |
|
0 | 4054 |
echo esc_attr( apply_filters( 'the_search_query', get_search_query( false ) ) ); |
4055 |
} |
|
4056 |
||
4057 |
/** |
|
16 | 4058 |
* Gets the language attributes for the 'html' tag. |
4059 |
* |
|
4060 |
* Builds up a set of HTML attributes containing the text direction and language |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4061 |
* information for the page. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4062 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4063 |
* @since 4.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4064 |
* |
16 | 4065 |
* @param string $doctype Optional. The type of HTML document. Accepts 'xhtml' or 'html'. Default 'html'. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4066 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4067 |
function get_language_attributes( $doctype = 'html' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4068 |
$attributes = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4069 |
|
9 | 4070 |
if ( function_exists( 'is_rtl' ) && is_rtl() ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4071 |
$attributes[] = 'dir="rtl"'; |
9 | 4072 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4073 |
|
16 | 4074 |
$lang = get_bloginfo( 'language' ); |
4075 |
if ( $lang ) { |
|
4076 |
if ( 'text/html' === get_option( 'html_type' ) || 'html' === $doctype ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4077 |
$attributes[] = 'lang="' . esc_attr( $lang ) . '"'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4078 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4079 |
|
16 | 4080 |
if ( 'text/html' !== get_option( 'html_type' ) || 'xhtml' === $doctype ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4081 |
$attributes[] = 'xml:lang="' . esc_attr( $lang ) . '"'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4082 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4083 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4084 |
|
9 | 4085 |
$output = implode( ' ', $attributes ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4086 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4087 |
/** |
16 | 4088 |
* Filters the language attributes for display in the 'html' tag. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4089 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4090 |
* @since 2.5.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4091 |
* @since 4.3.0 Added the `$doctype` parameter. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4092 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4093 |
* @param string $output A space-separated list of language attributes. |
16 | 4094 |
* @param string $doctype The type of HTML document (xhtml|html). |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4095 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4096 |
return apply_filters( 'language_attributes', $output, $doctype ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4097 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4098 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4099 |
/** |
16 | 4100 |
* Displays the language attributes for the 'html' tag. |
4101 |
* |
|
4102 |
* Builds up a set of HTML attributes containing the text direction and language |
|
0 | 4103 |
* information for the page. |
4104 |
* |
|
4105 |
* @since 2.1.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4106 |
* @since 4.3.0 Converted into a wrapper for get_language_attributes(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4107 |
* |
16 | 4108 |
* @param string $doctype Optional. The type of HTML document. Accepts 'xhtml' or 'html'. Default 'html'. |
0 | 4109 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4110 |
function language_attributes( $doctype = 'html' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4111 |
echo get_language_attributes( $doctype ); |
0 | 4112 |
} |
4113 |
||
4114 |
/** |
|
4115 |
* Retrieve paginated link for archive post pages. |
|
4116 |
* |
|
4117 |
* Technically, the function can be used to create paginated link list for any |
|
4118 |
* area. The 'base' argument is used to reference the url, which will be used to |
|
4119 |
* create the paginated links. The 'format' argument is then used for replacing |
|
4120 |
* the page number. It is however, most likely and by default, to be used on the |
|
4121 |
* archive post pages. |
|
4122 |
* |
|
4123 |
* The 'type' argument controls format of the returned value. The default is |
|
4124 |
* 'plain', which is just a string with the links separated by a newline |
|
4125 |
* character. The other possible values are either 'array' or 'list'. The |
|
4126 |
* 'array' value will return an array of the paginated link list to offer full |
|
4127 |
* control of display. The 'list' value will place all of the paginated links in |
|
4128 |
* an unordered HTML list. |
|
4129 |
* |
|
4130 |
* The 'total' argument is the total amount of pages and is an integer. The |
|
4131 |
* 'current' argument is the current page number and is also an integer. |
|
4132 |
* |
|
4133 |
* An example of the 'base' argument is "http://example.com/all_posts.php%_%" |
|
4134 |
* and the '%_%' is required. The '%_%' will be replaced by the contents of in |
|
4135 |
* the 'format' argument. An example for the 'format' argument is "?page=%#%" |
|
4136 |
* and the '%#%' is also required. The '%#%' will be replaced with the page |
|
4137 |
* number. |
|
4138 |
* |
|
4139 |
* You can include the previous and next links in the list by setting the |
|
4140 |
* 'prev_next' argument to true, which it is by default. You can set the |
|
4141 |
* previous text, by using the 'prev_text' argument. You can set the next text |
|
4142 |
* by setting the 'next_text' argument. |
|
4143 |
* |
|
4144 |
* If the 'show_all' argument is set to true, then it will show all of the pages |
|
4145 |
* instead of a short list of the pages near the current page. By default, the |
|
4146 |
* 'show_all' is set to false and controlled by the 'end_size' and 'mid_size' |
|
4147 |
* arguments. The 'end_size' argument is how many numbers on either the start |
|
4148 |
* and the end list edges, by default is 1. The 'mid_size' argument is how many |
|
4149 |
* numbers to either side of current page, but not including current page. |
|
4150 |
* |
|
4151 |
* It is possible to add query vars to the link by using the 'add_args' argument |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4152 |
* and see add_query_arg() for more information. |
0 | 4153 |
* |
5 | 4154 |
* The 'before_page_number' and 'after_page_number' arguments allow users to |
4155 |
* augment the links themselves. Typically this might be to add context to the |
|
4156 |
* numbered links so that screen reader users understand what the links are for. |
|
4157 |
* The text strings are added before and after the page number - within the |
|
4158 |
* anchor tag. |
|
4159 |
* |
|
0 | 4160 |
* @since 2.1.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4161 |
* @since 4.9.0 Added the `aria_current` argument. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4162 |
* |
16 | 4163 |
* @global WP_Query $wp_query WordPress Query object. |
4164 |
* @global WP_Rewrite $wp_rewrite WordPress rewrite component. |
|
0 | 4165 |
* |
5 | 4166 |
* @param string|array $args { |
4167 |
* Optional. Array or string of arguments for generating paginated links for archives. |
|
4168 |
* |
|
4169 |
* @type string $base Base of the paginated url. Default empty. |
|
4170 |
* @type string $format Format for the pagination structure. Default empty. |
|
4171 |
* @type int $total The total amount of pages. Default is the value WP_Query's |
|
4172 |
* `max_num_pages` or 1. |
|
4173 |
* @type int $current The current page number. Default is 'paged' query var or 1. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4174 |
* @type string $aria_current The value for the aria-current attribute. Possible values are 'page', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4175 |
* 'step', 'location', 'date', 'time', 'true', 'false'. Default is 'page'. |
5 | 4176 |
* @type bool $show_all Whether to show all pages. Default false. |
4177 |
* @type int $end_size How many numbers on either the start and the end list edges. |
|
4178 |
* Default 1. |
|
4179 |
* @type int $mid_size How many numbers to either side of the current pages. Default 2. |
|
4180 |
* @type bool $prev_next Whether to include the previous and next links in the list. Default true. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4181 |
* @type bool $prev_text The previous page text. Default '« Previous'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4182 |
* @type bool $next_text The next page text. Default 'Next »'. |
5 | 4183 |
* @type string $type Controls format of the returned value. Possible values are 'plain', |
4184 |
* 'array' and 'list'. Default is 'plain'. |
|
4185 |
* @type array $add_args An array of query args to add. Default false. |
|
4186 |
* @type string $add_fragment A string to append to each link. Default empty. |
|
4187 |
* @type string $before_page_number A string to appear before the page number. Default empty. |
|
4188 |
* @type string $after_page_number A string to append after the page number. Default empty. |
|
4189 |
* } |
|
16 | 4190 |
* @return string|array|void String of page links or array of page links, depending on 'type' argument. |
4191 |
* Void if total number of pages is less than 2. |
|
0 | 4192 |
*/ |
4193 |
function paginate_links( $args = '' ) { |
|
5 | 4194 |
global $wp_query, $wp_rewrite; |
4195 |
||
4196 |
// Setting up default values based on the current URL. |
|
4197 |
$pagenum_link = html_entity_decode( get_pagenum_link() ); |
|
4198 |
$url_parts = explode( '?', $pagenum_link ); |
|
4199 |
||
4200 |
// Get max pages and current page out of the current query, if available. |
|
4201 |
$total = isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1; |
|
4202 |
$current = get_query_var( 'paged' ) ? intval( get_query_var( 'paged' ) ) : 1; |
|
4203 |
||
4204 |
// Append the format placeholder to the base URL. |
|
4205 |
$pagenum_link = trailingslashit( $url_parts[0] ) . '%_%'; |
|
4206 |
||
4207 |
// URL base depends on permalink settings. |
|
4208 |
$format = $wp_rewrite->using_index_permalinks() && ! strpos( $pagenum_link, 'index.php' ) ? 'index.php/' : ''; |
|
4209 |
$format .= $wp_rewrite->using_permalinks() ? user_trailingslashit( $wp_rewrite->pagination_base . '/%#%', 'paged' ) : '?paged=%#%'; |
|
4210 |
||
0 | 4211 |
$defaults = array( |
16 | 4212 |
'base' => $pagenum_link, // http://example.com/all_posts.php%_% : %_% is replaced by format (below). |
4213 |
'format' => $format, // ?page=%#% : %#% is replaced by the page number. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4214 |
'total' => $total, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4215 |
'current' => $current, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4216 |
'aria_current' => 'page', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4217 |
'show_all' => false, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4218 |
'prev_next' => true, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4219 |
'prev_text' => __( '« Previous' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4220 |
'next_text' => __( 'Next »' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4221 |
'end_size' => 1, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4222 |
'mid_size' => 2, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4223 |
'type' => 'plain', |
16 | 4224 |
'add_args' => array(), // Array of query args to add. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4225 |
'add_fragment' => '', |
5 | 4226 |
'before_page_number' => '', |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4227 |
'after_page_number' => '', |
0 | 4228 |
); |
4229 |
||
4230 |
$args = wp_parse_args( $args, $defaults ); |
|
5 | 4231 |
|
4232 |
if ( ! is_array( $args['add_args'] ) ) { |
|
4233 |
$args['add_args'] = array(); |
|
4234 |
} |
|
4235 |
||
4236 |
// Merge additional query vars found in the original URL into 'add_args' array. |
|
4237 |
if ( isset( $url_parts[1] ) ) { |
|
4238 |
// Find the format argument. |
|
9 | 4239 |
$format = explode( '?', str_replace( '%_%', $args['format'], $args['base'] ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4240 |
$format_query = isset( $format[1] ) ? $format[1] : ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4241 |
wp_parse_str( $format_query, $format_args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4242 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4243 |
// Find the query args of the requested URL. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4244 |
wp_parse_str( $url_parts[1], $url_query_args ); |
5 | 4245 |
|
4246 |
// Remove the format argument from the array of query arguments, to avoid overwriting custom format. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4247 |
foreach ( $format_args as $format_arg => $format_arg_value ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4248 |
unset( $url_query_args[ $format_arg ] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4249 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4250 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4251 |
$args['add_args'] = array_merge( $args['add_args'], urlencode_deep( $url_query_args ) ); |
5 | 4252 |
} |
0 | 4253 |
|
16 | 4254 |
// Who knows what else people pass in $args. |
5 | 4255 |
$total = (int) $args['total']; |
4256 |
if ( $total < 2 ) { |
|
0 | 4257 |
return; |
5 | 4258 |
} |
4259 |
$current = (int) $args['current']; |
|
16 | 4260 |
$end_size = (int) $args['end_size']; // Out of bounds? Make it the default. |
5 | 4261 |
if ( $end_size < 1 ) { |
4262 |
$end_size = 1; |
|
4263 |
} |
|
4264 |
$mid_size = (int) $args['mid_size']; |
|
4265 |
if ( $mid_size < 0 ) { |
|
4266 |
$mid_size = 2; |
|
4267 |
} |
|
16 | 4268 |
|
9 | 4269 |
$add_args = $args['add_args']; |
4270 |
$r = ''; |
|
0 | 4271 |
$page_links = array(); |
9 | 4272 |
$dots = false; |
0 | 4273 |
|
5 | 4274 |
if ( $args['prev_next'] && $current && 1 < $current ) : |
4275 |
$link = str_replace( '%_%', 2 == $current ? '' : $args['format'], $args['base'] ); |
|
4276 |
$link = str_replace( '%#%', $current - 1, $link ); |
|
9 | 4277 |
if ( $add_args ) { |
0 | 4278 |
$link = add_query_arg( $add_args, $link ); |
9 | 4279 |
} |
5 | 4280 |
$link .= $args['add_fragment']; |
4281 |
||
16 | 4282 |
$page_links[] = sprintf( |
4283 |
'<a class="prev page-numbers" href="%s">%s</a>', |
|
4284 |
/** |
|
4285 |
* Filters the paginated links for the given archive pages. |
|
4286 |
* |
|
4287 |
* @since 3.0.0 |
|
4288 |
* |
|
4289 |
* @param string $link The paginated link URL. |
|
4290 |
*/ |
|
4291 |
esc_url( apply_filters( 'paginate_links', $link ) ), |
|
4292 |
$args['prev_text'] |
|
4293 |
); |
|
0 | 4294 |
endif; |
16 | 4295 |
|
0 | 4296 |
for ( $n = 1; $n <= $total; $n++ ) : |
4297 |
if ( $n == $current ) : |
|
16 | 4298 |
$page_links[] = sprintf( |
4299 |
'<span aria-current="%s" class="page-numbers current">%s</span>', |
|
4300 |
esc_attr( $args['aria_current'] ), |
|
4301 |
$args['before_page_number'] . number_format_i18n( $n ) . $args['after_page_number'] |
|
4302 |
); |
|
4303 |
||
4304 |
$dots = true; |
|
0 | 4305 |
else : |
5 | 4306 |
if ( $args['show_all'] || ( $n <= $end_size || ( $current && $n >= $current - $mid_size && $n <= $current + $mid_size ) || $n > $total - $end_size ) ) : |
4307 |
$link = str_replace( '%_%', 1 == $n ? '' : $args['format'], $args['base'] ); |
|
4308 |
$link = str_replace( '%#%', $n, $link ); |
|
9 | 4309 |
if ( $add_args ) { |
0 | 4310 |
$link = add_query_arg( $add_args, $link ); |
9 | 4311 |
} |
5 | 4312 |
$link .= $args['add_fragment']; |
4313 |
||
16 | 4314 |
$page_links[] = sprintf( |
4315 |
'<a class="page-numbers" href="%s">%s</a>', |
|
4316 |
/** This filter is documented in wp-includes/general-template.php */ |
|
4317 |
esc_url( apply_filters( 'paginate_links', $link ) ), |
|
4318 |
$args['before_page_number'] . number_format_i18n( $n ) . $args['after_page_number'] |
|
4319 |
); |
|
4320 |
||
4321 |
$dots = true; |
|
5 | 4322 |
elseif ( $dots && ! $args['show_all'] ) : |
0 | 4323 |
$page_links[] = '<span class="page-numbers dots">' . __( '…' ) . '</span>'; |
16 | 4324 |
|
4325 |
$dots = false; |
|
0 | 4326 |
endif; |
4327 |
endif; |
|
4328 |
endfor; |
|
16 | 4329 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4330 |
if ( $args['prev_next'] && $current && $current < $total ) : |
5 | 4331 |
$link = str_replace( '%_%', $args['format'], $args['base'] ); |
4332 |
$link = str_replace( '%#%', $current + 1, $link ); |
|
9 | 4333 |
if ( $add_args ) { |
0 | 4334 |
$link = add_query_arg( $add_args, $link ); |
9 | 4335 |
} |
5 | 4336 |
$link .= $args['add_fragment']; |
4337 |
||
16 | 4338 |
$page_links[] = sprintf( |
4339 |
'<a class="next page-numbers" href="%s">%s</a>', |
|
4340 |
/** This filter is documented in wp-includes/general-template.php */ |
|
4341 |
esc_url( apply_filters( 'paginate_links', $link ) ), |
|
4342 |
$args['next_text'] |
|
4343 |
); |
|
0 | 4344 |
endif; |
16 | 4345 |
|
5 | 4346 |
switch ( $args['type'] ) { |
9 | 4347 |
case 'array': |
0 | 4348 |
return $page_links; |
5 | 4349 |
|
9 | 4350 |
case 'list': |
0 | 4351 |
$r .= "<ul class='page-numbers'>\n\t<li>"; |
9 | 4352 |
$r .= join( "</li>\n\t<li>", $page_links ); |
0 | 4353 |
$r .= "</li>\n</ul>\n"; |
4354 |
break; |
|
5 | 4355 |
|
9 | 4356 |
default: |
4357 |
$r = join( "\n", $page_links ); |
|
0 | 4358 |
break; |
5 | 4359 |
} |
16 | 4360 |
|
0 | 4361 |
return $r; |
4362 |
} |
|
4363 |
||
4364 |
/** |
|
9 | 4365 |
* Registers an admin color scheme css file. |
4366 |
* |
|
4367 |
* Allows a plugin to register a new admin color scheme. For example: |
|
5 | 4368 |
* |
4369 |
* wp_admin_css_color( 'classic', __( 'Classic' ), admin_url( "css/colors-classic.css" ), array( |
|
4370 |
* '#07273E', '#14568A', '#D54E21', '#2683AE' |
|
4371 |
* ) ); |
|
0 | 4372 |
* |
4373 |
* @since 2.5.0 |
|
4374 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4375 |
* @global array $_wp_admin_css_colors |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4376 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4377 |
* @param string $key The unique key for this theme. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4378 |
* @param string $name The name of the theme. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4379 |
* @param string $url The URL of the CSS file containing the color scheme. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4380 |
* @param array $colors Optional. An array of CSS color definition strings which are used |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4381 |
* to give the user a feel for the theme. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4382 |
* @param array $icons { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4383 |
* Optional. CSS color definitions used to color any SVG icons. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4384 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4385 |
* @type string $base SVG icon base color. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4386 |
* @type string $focus SVG icon color on focus. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4387 |
* @type string $current SVG icon color of current admin menu link. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4388 |
* } |
0 | 4389 |
*/ |
5 | 4390 |
function wp_admin_css_color( $key, $name, $url, $colors = array(), $icons = array() ) { |
0 | 4391 |
global $_wp_admin_css_colors; |
4392 |
||
9 | 4393 |
if ( ! isset( $_wp_admin_css_colors ) ) { |
0 | 4394 |
$_wp_admin_css_colors = array(); |
9 | 4395 |
} |
4396 |
||
4397 |
$_wp_admin_css_colors[ $key ] = (object) array( |
|
4398 |
'name' => $name, |
|
4399 |
'url' => $url, |
|
4400 |
'colors' => $colors, |
|
5 | 4401 |
'icon_colors' => $icons, |
4402 |
); |
|
0 | 4403 |
} |
4404 |
||
4405 |
/** |
|
9 | 4406 |
* Registers the default admin color schemes. |
4407 |
* |
|
4408 |
* Registers the initial set of eight color schemes in the Profile section |
|
4409 |
* of the dashboard which allows for styling the admin menu and toolbar. |
|
4410 |
* |
|
4411 |
* @see wp_admin_css_color() |
|
0 | 4412 |
* |
4413 |
* @since 3.0.0 |
|
4414 |
*/ |
|
4415 |
function register_admin_color_schemes() { |
|
9 | 4416 |
$suffix = is_rtl() ? '-rtl' : ''; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4417 |
$suffix .= SCRIPT_DEBUG ? '' : '.min'; |
5 | 4418 |
|
9 | 4419 |
wp_admin_css_color( |
4420 |
'fresh', |
|
4421 |
_x( 'Default', 'admin color scheme' ), |
|
5 | 4422 |
false, |
4423 |
array( '#222', '#333', '#0073aa', '#00a0d2' ), |
|
9 | 4424 |
array( |
4425 |
'base' => '#a0a5aa', |
|
4426 |
'focus' => '#00a0d2', |
|
4427 |
'current' => '#fff', |
|
4428 |
) |
|
5 | 4429 |
); |
4430 |
||
9 | 4431 |
wp_admin_css_color( |
4432 |
'light', |
|
4433 |
_x( 'Light', 'admin color scheme' ), |
|
5 | 4434 |
admin_url( "css/colors/light/colors$suffix.css" ), |
4435 |
array( '#e5e5e5', '#999', '#d64e07', '#04a4cc' ), |
|
9 | 4436 |
array( |
4437 |
'base' => '#999', |
|
4438 |
'focus' => '#ccc', |
|
4439 |
'current' => '#ccc', |
|
4440 |
) |
|
5 | 4441 |
); |
4442 |
||
9 | 4443 |
wp_admin_css_color( |
16 | 4444 |
'modern', |
4445 |
_x( 'Modern', 'admin color scheme' ), |
|
4446 |
admin_url( "css/colors/modern/colors$suffix.css" ), |
|
4447 |
array( '#1e1e1e', '#3858e9', '#33f078' ), |
|
4448 |
array( |
|
4449 |
'base' => '#f3f1f1', |
|
4450 |
'focus' => '#fff', |
|
4451 |
'current' => '#fff', |
|
4452 |
) |
|
4453 |
); |
|
4454 |
||
4455 |
wp_admin_css_color( |
|
9 | 4456 |
'blue', |
4457 |
_x( 'Blue', 'admin color scheme' ), |
|
5 | 4458 |
admin_url( "css/colors/blue/colors$suffix.css" ), |
4459 |
array( '#096484', '#4796b3', '#52accc', '#74B6CE' ), |
|
9 | 4460 |
array( |
4461 |
'base' => '#e5f8ff', |
|
4462 |
'focus' => '#fff', |
|
4463 |
'current' => '#fff', |
|
4464 |
) |
|
5 | 4465 |
); |
4466 |
||
9 | 4467 |
wp_admin_css_color( |
4468 |
'midnight', |
|
4469 |
_x( 'Midnight', 'admin color scheme' ), |
|
5 | 4470 |
admin_url( "css/colors/midnight/colors$suffix.css" ), |
4471 |
array( '#25282b', '#363b3f', '#69a8bb', '#e14d43' ), |
|
9 | 4472 |
array( |
4473 |
'base' => '#f1f2f3', |
|
4474 |
'focus' => '#fff', |
|
4475 |
'current' => '#fff', |
|
4476 |
) |
|
5 | 4477 |
); |
4478 |
||
9 | 4479 |
wp_admin_css_color( |
4480 |
'sunrise', |
|
4481 |
_x( 'Sunrise', 'admin color scheme' ), |
|
5 | 4482 |
admin_url( "css/colors/sunrise/colors$suffix.css" ), |
4483 |
array( '#b43c38', '#cf4944', '#dd823b', '#ccaf0b' ), |
|
9 | 4484 |
array( |
4485 |
'base' => '#f3f1f1', |
|
4486 |
'focus' => '#fff', |
|
4487 |
'current' => '#fff', |
|
4488 |
) |
|
5 | 4489 |
); |
4490 |
||
9 | 4491 |
wp_admin_css_color( |
4492 |
'ectoplasm', |
|
4493 |
_x( 'Ectoplasm', 'admin color scheme' ), |
|
5 | 4494 |
admin_url( "css/colors/ectoplasm/colors$suffix.css" ), |
4495 |
array( '#413256', '#523f6d', '#a3b745', '#d46f15' ), |
|
9 | 4496 |
array( |
4497 |
'base' => '#ece6f6', |
|
4498 |
'focus' => '#fff', |
|
4499 |
'current' => '#fff', |
|
4500 |
) |
|
5 | 4501 |
); |
4502 |
||
9 | 4503 |
wp_admin_css_color( |
4504 |
'ocean', |
|
4505 |
_x( 'Ocean', 'admin color scheme' ), |
|
5 | 4506 |
admin_url( "css/colors/ocean/colors$suffix.css" ), |
4507 |
array( '#627c83', '#738e96', '#9ebaa0', '#aa9d88' ), |
|
9 | 4508 |
array( |
4509 |
'base' => '#f2fcff', |
|
4510 |
'focus' => '#fff', |
|
4511 |
'current' => '#fff', |
|
4512 |
) |
|
5 | 4513 |
); |
4514 |
||
9 | 4515 |
wp_admin_css_color( |
4516 |
'coffee', |
|
4517 |
_x( 'Coffee', 'admin color scheme' ), |
|
5 | 4518 |
admin_url( "css/colors/coffee/colors$suffix.css" ), |
4519 |
array( '#46403c', '#59524c', '#c7a589', '#9ea476' ), |
|
9 | 4520 |
array( |
4521 |
'base' => '#f3f2f1', |
|
4522 |
'focus' => '#fff', |
|
4523 |
'current' => '#fff', |
|
4524 |
) |
|
5 | 4525 |
); |
4526 |
||
0 | 4527 |
} |
4528 |
||
4529 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4530 |
* Displays the URL of a WordPress admin CSS file. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4531 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4532 |
* @see WP_Styles::_css_href and its {@see 'style_loader_src'} filter. |
0 | 4533 |
* |
4534 |
* @since 2.3.0 |
|
4535 |
* |
|
4536 |
* @param string $file file relative to wp-admin/ without its ".css" extension. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4537 |
* @return string |
0 | 4538 |
*/ |
4539 |
function wp_admin_css_uri( $file = 'wp-admin' ) { |
|
9 | 4540 |
if ( defined( 'WP_INSTALLING' ) ) { |
0 | 4541 |
$_file = "./$file.css"; |
4542 |
} else { |
|
9 | 4543 |
$_file = admin_url( "$file.css" ); |
0 | 4544 |
} |
9 | 4545 |
$_file = add_query_arg( 'version', get_bloginfo( 'version' ), $_file ); |
0 | 4546 |
|
5 | 4547 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4548 |
* Filters the URI of a WordPress admin CSS file. |
5 | 4549 |
* |
4550 |
* @since 2.3.0 |
|
4551 |
* |
|
4552 |
* @param string $_file Relative path to the file with query arguments attached. |
|
4553 |
* @param string $file Relative path to the file, minus its ".css" extension. |
|
4554 |
*/ |
|
0 | 4555 |
return apply_filters( 'wp_admin_css_uri', $_file, $file ); |
4556 |
} |
|
4557 |
||
4558 |
/** |
|
4559 |
* Enqueues or directly prints a stylesheet link to the specified CSS file. |
|
4560 |
* |
|
4561 |
* "Intelligently" decides to enqueue or to print the CSS file. If the |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4562 |
* {@see 'wp_print_styles'} action has *not* yet been called, the CSS file will be |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4563 |
* enqueued. If the {@see 'wp_print_styles'} action has been called, the CSS link will |
0 | 4564 |
* be printed. Printing may be forced by passing true as the $force_echo |
4565 |
* (second) parameter. |
|
4566 |
* |
|
4567 |
* For backward compatibility with WordPress 2.3 calling method: If the $file |
|
4568 |
* (first) parameter does not correspond to a registered CSS file, we assume |
|
4569 |
* $file is a file relative to wp-admin/ without its ".css" extension. A |
|
4570 |
* stylesheet link to that generated URL is printed. |
|
4571 |
* |
|
4572 |
* @since 2.3.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4573 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4574 |
* @param string $file Optional. Style handle name or file name (without ".css" extension) relative |
9 | 4575 |
* to wp-admin/. Defaults to 'wp-admin'. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4576 |
* @param bool $force_echo Optional. Force the stylesheet link to be printed rather than enqueued. |
0 | 4577 |
*/ |
4578 |
function wp_admin_css( $file = 'wp-admin', $force_echo = false ) { |
|
16 | 4579 |
// For backward compatibility. |
0 | 4580 |
$handle = 0 === strpos( $file, 'css/' ) ? substr( $file, 4 ) : $file; |
4581 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4582 |
if ( wp_styles()->query( $handle ) ) { |
16 | 4583 |
if ( $force_echo || did_action( 'wp_print_styles' ) ) { |
4584 |
// We already printed the style queue. Print this one immediately. |
|
0 | 4585 |
wp_print_styles( $handle ); |
16 | 4586 |
} else { |
4587 |
// Add to style queue. |
|
0 | 4588 |
wp_enqueue_style( $handle ); |
9 | 4589 |
} |
0 | 4590 |
return; |
4591 |
} |
|
4592 |
||
16 | 4593 |
$stylesheet_link = sprintf( |
4594 |
"<link rel='stylesheet' href='%s' type='text/css' />\n", |
|
4595 |
esc_url( wp_admin_css_uri( $file ) ) |
|
4596 |
); |
|
4597 |
||
5 | 4598 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4599 |
* Filters the stylesheet link to the specified CSS file. |
5 | 4600 |
* |
4601 |
* If the site is set to display right-to-left, the RTL stylesheet link |
|
4602 |
* will be used instead. |
|
4603 |
* |
|
4604 |
* @since 2.3.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4605 |
* @param string $stylesheet_link HTML link element for the stylesheet. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4606 |
* @param string $file Style handle name or filename (without ".css" extension) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4607 |
* relative to wp-admin/. Defaults to 'wp-admin'. |
5 | 4608 |
*/ |
16 | 4609 |
echo apply_filters( 'wp_admin_css', $stylesheet_link, $file ); |
5 | 4610 |
|
4611 |
if ( function_exists( 'is_rtl' ) && is_rtl() ) { |
|
16 | 4612 |
$rtl_stylesheet_link = sprintf( |
4613 |
"<link rel='stylesheet' href='%s' type='text/css' />\n", |
|
4614 |
esc_url( wp_admin_css_uri( "$file-rtl" ) ) |
|
4615 |
); |
|
4616 |
||
5 | 4617 |
/** This filter is documented in wp-includes/general-template.php */ |
16 | 4618 |
echo apply_filters( 'wp_admin_css', $rtl_stylesheet_link, "$file-rtl" ); |
5 | 4619 |
} |
0 | 4620 |
} |
4621 |
||
4622 |
/** |
|
4623 |
* Enqueues the default ThickBox js and css. |
|
4624 |
* |
|
4625 |
* If any of the settings need to be changed, this can be done with another js |
|
4626 |
* file similar to media-upload.js. That file should |
|
4627 |
* require array('thickbox') to ensure it is loaded after. |
|
4628 |
* |
|
4629 |
* @since 2.5.0 |
|
4630 |
*/ |
|
4631 |
function add_thickbox() { |
|
4632 |
wp_enqueue_script( 'thickbox' ); |
|
4633 |
wp_enqueue_style( 'thickbox' ); |
|
4634 |
||
9 | 4635 |
if ( is_network_admin() ) { |
0 | 4636 |
add_action( 'admin_head', '_thickbox_path_admin_subfolder' ); |
9 | 4637 |
} |
0 | 4638 |
} |
4639 |
||
4640 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4641 |
* Displays the XHTML generator that is generated on the wp_head hook. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4642 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4643 |
* See {@see 'wp_head'}. |
0 | 4644 |
* |
4645 |
* @since 2.5.0 |
|
4646 |
*/ |
|
4647 |
function wp_generator() { |
|
5 | 4648 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4649 |
* Filters the output of the XHTML generator tag. |
5 | 4650 |
* |
4651 |
* @since 2.5.0 |
|
4652 |
* |
|
4653 |
* @param string $generator_type The XHTML generator. |
|
4654 |
*/ |
|
0 | 4655 |
the_generator( apply_filters( 'wp_generator_type', 'xhtml' ) ); |
4656 |
} |
|
4657 |
||
4658 |
/** |
|
4659 |
* Display the generator XML or Comment for RSS, ATOM, etc. |
|
4660 |
* |
|
4661 |
* Returns the correct generator type for the requested output format. Allows |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4662 |
* for a plugin to filter generators overall the {@see 'the_generator'} filter. |
0 | 4663 |
* |
4664 |
* @since 2.5.0 |
|
4665 |
* |
|
4666 |
* @param string $type The type of generator to output - (html|xhtml|atom|rss2|rdf|comment|export). |
|
4667 |
*/ |
|
4668 |
function the_generator( $type ) { |
|
5 | 4669 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4670 |
* Filters the output of the XHTML generator tag for display. |
5 | 4671 |
* |
4672 |
* @since 2.5.0 |
|
4673 |
* |
|
4674 |
* @param string $generator_type The generator output. |
|
4675 |
* @param string $type The type of generator to output. Accepts 'html', |
|
4676 |
* 'xhtml', 'atom', 'rss2', 'rdf', 'comment', 'export'. |
|
4677 |
*/ |
|
9 | 4678 |
echo apply_filters( 'the_generator', get_the_generator( $type ), $type ) . "\n"; |
0 | 4679 |
} |
4680 |
||
4681 |
/** |
|
4682 |
* Creates the generator XML or Comment for RSS, ATOM, etc. |
|
4683 |
* |
|
4684 |
* Returns the correct generator type for the requested output format. Allows |
|
4685 |
* for a plugin to filter generators on an individual basis using the |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4686 |
* {@see 'get_the_generator_$type'} filter. |
0 | 4687 |
* |
4688 |
* @since 2.5.0 |
|
4689 |
* |
|
4690 |
* @param string $type The type of generator to return - (html|xhtml|atom|rss2|rdf|comment|export). |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4691 |
* @return string|void The HTML content for the generator. |
0 | 4692 |
*/ |
4693 |
function get_the_generator( $type = '' ) { |
|
4694 |
if ( empty( $type ) ) { |
|
4695 |
||
4696 |
$current_filter = current_filter(); |
|
9 | 4697 |
if ( empty( $current_filter ) ) { |
0 | 4698 |
return; |
9 | 4699 |
} |
0 | 4700 |
|
4701 |
switch ( $current_filter ) { |
|
9 | 4702 |
case 'rss2_head': |
4703 |
case 'commentsrss2_head': |
|
0 | 4704 |
$type = 'rss2'; |
4705 |
break; |
|
9 | 4706 |
case 'rss_head': |
4707 |
case 'opml_head': |
|
0 | 4708 |
$type = 'comment'; |
4709 |
break; |
|
9 | 4710 |
case 'rdf_header': |
0 | 4711 |
$type = 'rdf'; |
4712 |
break; |
|
9 | 4713 |
case 'atom_head': |
4714 |
case 'comments_atom_head': |
|
4715 |
case 'app_head': |
|
0 | 4716 |
$type = 'atom'; |
4717 |
break; |
|
4718 |
} |
|
4719 |
} |
|
4720 |
||
4721 |
switch ( $type ) { |
|
4722 |
case 'html': |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4723 |
$gen = '<meta name="generator" content="WordPress ' . esc_attr( get_bloginfo( 'version' ) ) . '">'; |
0 | 4724 |
break; |
4725 |
case 'xhtml': |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4726 |
$gen = '<meta name="generator" content="WordPress ' . esc_attr( get_bloginfo( 'version' ) ) . '" />'; |
0 | 4727 |
break; |
4728 |
case 'atom': |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4729 |
$gen = '<generator uri="https://wordpress.org/" version="' . esc_attr( get_bloginfo_rss( 'version' ) ) . '">WordPress</generator>'; |
0 | 4730 |
break; |
4731 |
case 'rss2': |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4732 |
$gen = '<generator>' . esc_url_raw( 'https://wordpress.org/?v=' . get_bloginfo_rss( 'version' ) ) . '</generator>'; |
0 | 4733 |
break; |
4734 |
case 'rdf': |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4735 |
$gen = '<admin:generatorAgent rdf:resource="' . esc_url_raw( 'https://wordpress.org/?v=' . get_bloginfo_rss( 'version' ) ) . '" />'; |
0 | 4736 |
break; |
4737 |
case 'comment': |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4738 |
$gen = '<!-- generator="WordPress/' . esc_attr( get_bloginfo( 'version' ) ) . '" -->'; |
0 | 4739 |
break; |
4740 |
case 'export': |
|
16 | 4741 |
$gen = '<!-- generator="WordPress/' . esc_attr( get_bloginfo_rss( 'version' ) ) . '" created="' . gmdate( 'Y-m-d H:i' ) . '" -->'; |
0 | 4742 |
break; |
4743 |
} |
|
5 | 4744 |
|
4745 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4746 |
* Filters the HTML for the retrieved generator type. |
5 | 4747 |
* |
4748 |
* The dynamic portion of the hook name, `$type`, refers to the generator type. |
|
4749 |
* |
|
4750 |
* @since 2.5.0 |
|
4751 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4752 |
* @param string $gen The HTML markup output to wp_head(). |
5 | 4753 |
* @param string $type The type of generator. Accepts 'html', 'xhtml', 'atom', |
4754 |
* 'rss2', 'rdf', 'comment', 'export'. |
|
4755 |
*/ |
|
0 | 4756 |
return apply_filters( "get_the_generator_{$type}", $gen, $type ); |
4757 |
} |
|
4758 |
||
4759 |
/** |
|
16 | 4760 |
* Outputs the HTML checked attribute. |
0 | 4761 |
* |
4762 |
* Compares the first two arguments and if identical marks as checked |
|
4763 |
* |
|
4764 |
* @since 1.0.0 |
|
4765 |
* |
|
4766 |
* @param mixed $checked One of the values to compare |
|
4767 |
* @param mixed $current (true) The other value to compare if not just true |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4768 |
* @param bool $echo Whether to echo or just return the string |
16 | 4769 |
* @return string HTML attribute or empty string |
0 | 4770 |
*/ |
4771 |
function checked( $checked, $current = true, $echo = true ) { |
|
4772 |
return __checked_selected_helper( $checked, $current, $echo, 'checked' ); |
|
4773 |
} |
|
4774 |
||
4775 |
/** |
|
16 | 4776 |
* Outputs the HTML selected attribute. |
0 | 4777 |
* |
4778 |
* Compares the first two arguments and if identical marks as selected |
|
4779 |
* |
|
4780 |
* @since 1.0.0 |
|
4781 |
* |
|
4782 |
* @param mixed $selected One of the values to compare |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4783 |
* @param mixed $current (true) The other value to compare if not just true |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4784 |
* @param bool $echo Whether to echo or just return the string |
16 | 4785 |
* @return string HTML attribute or empty string |
0 | 4786 |
*/ |
4787 |
function selected( $selected, $current = true, $echo = true ) { |
|
4788 |
return __checked_selected_helper( $selected, $current, $echo, 'selected' ); |
|
4789 |
} |
|
4790 |
||
4791 |
/** |
|
16 | 4792 |
* Outputs the HTML disabled attribute. |
0 | 4793 |
* |
4794 |
* Compares the first two arguments and if identical marks as disabled |
|
4795 |
* |
|
4796 |
* @since 3.0.0 |
|
4797 |
* |
|
4798 |
* @param mixed $disabled One of the values to compare |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4799 |
* @param mixed $current (true) The other value to compare if not just true |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4800 |
* @param bool $echo Whether to echo or just return the string |
16 | 4801 |
* @return string HTML attribute or empty string |
0 | 4802 |
*/ |
4803 |
function disabled( $disabled, $current = true, $echo = true ) { |
|
4804 |
return __checked_selected_helper( $disabled, $current, $echo, 'disabled' ); |
|
4805 |
} |
|
4806 |
||
4807 |
/** |
|
16 | 4808 |
* Outputs the HTML readonly attribute. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4809 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4810 |
* Compares the first two arguments and if identical marks as readonly |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4811 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4812 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4813 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4814 |
* @param mixed $readonly One of the values to compare |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4815 |
* @param mixed $current (true) The other value to compare if not just true |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4816 |
* @param bool $echo Whether to echo or just return the string |
16 | 4817 |
* @return string HTML attribute or empty string |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4818 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4819 |
function readonly( $readonly, $current = true, $echo = true ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4820 |
return __checked_selected_helper( $readonly, $current, $echo, 'readonly' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4821 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4822 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4823 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4824 |
* Private helper function for checked, selected, disabled and readonly. |
0 | 4825 |
* |
4826 |
* Compares the first two arguments and if identical marks as $type |
|
4827 |
* |
|
4828 |
* @since 2.8.0 |
|
4829 |
* @access private |
|
4830 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4831 |
* @param mixed $helper One of the values to compare |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4832 |
* @param mixed $current (true) The other value to compare if not just true |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4833 |
* @param bool $echo Whether to echo or just return the string |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4834 |
* @param string $type The type of checked|selected|disabled|readonly we are doing |
16 | 4835 |
* @return string HTML attribute or empty string |
0 | 4836 |
*/ |
16 | 4837 |
function __checked_selected_helper( $helper, $current, $echo, $type ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionDoubleUnderscore,PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.FunctionDoubleUnderscore |
9 | 4838 |
if ( (string) $helper === (string) $current ) { |
0 | 4839 |
$result = " $type='$type'"; |
9 | 4840 |
} else { |
0 | 4841 |
$result = ''; |
9 | 4842 |
} |
4843 |
||
4844 |
if ( $echo ) { |
|
0 | 4845 |
echo $result; |
9 | 4846 |
} |
0 | 4847 |
|
4848 |
return $result; |
|
4849 |
} |
|
4850 |
||
4851 |
/** |
|
4852 |
* Default settings for heartbeat |
|
4853 |
* |
|
4854 |
* Outputs the nonce used in the heartbeat XHR |
|
4855 |
* |
|
4856 |
* @since 3.6.0 |
|
4857 |
* |
|
4858 |
* @param array $settings |
|
16 | 4859 |
* @return array Heartbeat settings. |
0 | 4860 |
*/ |
4861 |
function wp_heartbeat_settings( $settings ) { |
|
9 | 4862 |
if ( ! is_admin() ) { |
0 | 4863 |
$settings['ajaxurl'] = admin_url( 'admin-ajax.php', 'relative' ); |
9 | 4864 |
} |
4865 |
||
4866 |
if ( is_user_logged_in() ) { |
|
0 | 4867 |
$settings['nonce'] = wp_create_nonce( 'heartbeat-nonce' ); |
9 | 4868 |
} |
0 | 4869 |
|
4870 |
return $settings; |
|
4871 |
} |