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