home *** CD-ROM | disk | FTP | other *** search
/ HTML Examples / WP.iso / wordpress2 / wp-includes / general-template.php < prev    next >
Encoding:
PHP Script  |  2018-01-31  |  135.7 KB  |  4,262 lines

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