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