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