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