Make WordPress Core

Ticket #39763: general-template.php

File general-template.php, 125.7 KB (added by Harry Milatz, 8 years ago)

"correctet" file without produce the error

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