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