diff -r c7c34916027a -r 177826044cd9 wp/wp-includes/general-template.php --- a/wp/wp-includes/general-template.php Mon Oct 14 18:06:33 2019 +0200 +++ b/wp/wp-includes/general-template.php Mon Oct 14 18:28:13 2019 +0200 @@ -31,7 +31,7 @@ do_action( 'get_header', $name ); $templates = array(); - $name = (string) $name; + $name = (string) $name; if ( '' !== $name ) { $templates[] = "header-{$name}.php"; } @@ -66,12 +66,12 @@ do_action( 'get_footer', $name ); $templates = array(); - $name = (string) $name; + $name = (string) $name; if ( '' !== $name ) { $templates[] = "footer-{$name}.php"; } - $templates[] = 'footer.php'; + $templates[] = 'footer.php'; locate_template( $templates, true ); } @@ -101,9 +101,10 @@ do_action( 'get_sidebar', $name ); $templates = array(); - $name = (string) $name; - if ( '' !== $name ) + $name = (string) $name; + if ( '' !== $name ) { $templates[] = "sidebar-{$name}.php"; + } $templates[] = 'sidebar.php'; @@ -146,13 +147,25 @@ do_action( "get_template_part_{$slug}", $slug, $name ); $templates = array(); - $name = (string) $name; - if ( '' !== $name ) + $name = (string) $name; + if ( '' !== $name ) { $templates[] = "{$slug}-{$name}.php"; + } $templates[] = "{$slug}.php"; - locate_template($templates, true, false); + /** + * Fires before a template part is loaded. + * + * @since 5.2.0 + * + * @param string $slug The slug name for the generic template. + * @param string $name The name of the specialized template. + * @param string[] $templates Array of template files to search for, in order. + */ + do_action( 'get_template_part', $slug, $name, $templates ); + + locate_template( $templates, true, false ); } /** @@ -173,11 +186,19 @@ * search. To give a few examples of what it can be used for. * * @since 2.7.0 - * - * @param bool $echo Default to echo and not return the form. - * @return string|void String when $echo is false. + * @since 5.2.0 The $args array parameter was added in place of an $echo boolean flag. + * + * @param array $args { + * Optional. Array of display arguments. + * + * @type bool $echo Whether to echo or return the form. Default true. + * @type string $aria_label ARIA label for the search form. Useful to distinguish + * multiple search forms on the same page and improve + * accessibility. Default empty. + * } + * @return string|void String when the $echo param is false. */ -function get_search_form( $echo = true ) { +function get_search_form( $args = array() ) { /** * Fires before the search form is retrieved, at the start of get_search_form(). * @@ -188,6 +209,37 @@ */ do_action( 'pre_get_search_form' ); + $echo = true; + + if ( ! is_array( $args ) ) { + /* + * Back compat: to ensure previous uses of get_search_form() continue to + * function as expected, we handle a value for the boolean $echo param removed + * in 5.2.0. Then we deal with the $args array and cast its defaults. + */ + $echo = (bool) $args; + + // Set an empty array and allow default arguments to take over. + $args = array(); + } + + // Defaults are to echo and to output no custom label on the form. + $defaults = array( + 'echo' => $echo, + 'aria_label' => '', + ); + + $args = wp_parse_args( $args, $defaults ); + + /** + * Filters the array of arguments used when generating the search form. + * + * @since 5.2.0 + * + * @param array $args The array of arguments for building the search form. + */ + $args = apply_filters( 'search_form_args', $args ); + $format = current_theme_supports( 'html5', 'search-form' ) ? 'html5' : 'xhtml'; /** @@ -206,20 +258,30 @@ require( $search_form_template ); $form = ob_get_clean(); } else { + // Build a string containing an aria-label to use for the search form. + if ( isset( $args['aria_label'] ) && $args['aria_label'] ) { + $aria_label = 'aria-label="' . esc_attr( $args['aria_label'] ) . '" '; + } else { + /* + * If there's no custom aria-label, we can set a default here. At the + * moment it's empty as there's uncertainty about what the default should be. + */ + $aria_label = ''; + } if ( 'html5' == $format ) { - $form = ''; } else { - $form = ''; } @@ -234,13 +296,15 @@ */ $result = apply_filters( 'get_search_form', $form ); - if ( null === $result ) + if ( null === $result ) { $result = $form; - - if ( $echo ) + } + + if ( isset( $args['echo'] ) && $args['echo'] ) { echo $result; - else + } else { return $result; + } } /** @@ -255,11 +319,12 @@ * @param bool $echo Default to echo and not return the link. * @return string|void String when retrieving. */ -function wp_loginout($redirect = '', $echo = true) { - if ( ! is_user_logged_in() ) - $link = '' . __('Log in') . ''; - else - $link = '' . __('Log out') . ''; +function wp_loginout( $redirect = '', $echo = true ) { + if ( ! is_user_logged_in() ) { + $link = '' . __( 'Log in' ) . ''; + } else { + $link = '' . __( 'Log out' ) . ''; + } if ( $echo ) { /** @@ -286,13 +351,13 @@ * @param string $redirect Path to redirect to on logout. * @return string The logout URL. Note: HTML-encoded via esc_html() in wp_nonce_url(). */ -function wp_logout_url($redirect = '') { +function wp_logout_url( $redirect = '' ) { $args = array( 'action' => 'logout' ); - if ( !empty($redirect) ) { + if ( ! empty( $redirect ) ) { $args['redirect_to'] = urlencode( $redirect ); } - $logout_url = add_query_arg($args, site_url('wp-login.php', 'login')); + $logout_url = add_query_arg( $args, site_url( 'wp-login.php', 'login' ) ); $logout_url = wp_nonce_url( $logout_url, 'log-out' ); /** @@ -316,14 +381,16 @@ * Default false. * @return string The login URL. Not HTML-encoded. */ -function wp_login_url($redirect = '', $force_reauth = false) { - $login_url = site_url('wp-login.php', 'login'); - - if ( !empty($redirect) ) - $login_url = add_query_arg('redirect_to', urlencode($redirect), $login_url); - - if ( $force_reauth ) - $login_url = add_query_arg('reauth', '1', $login_url); +function wp_login_url( $redirect = '', $force_reauth = false ) { + $login_url = site_url( 'wp-login.php', 'login' ); + + if ( ! empty( $redirect ) ) { + $login_url = add_query_arg( 'redirect_to', urlencode( $redirect ), $login_url ); + } + + if ( $force_reauth ) { + $login_url = add_query_arg( 'reauth', '1', $login_url ); + } /** * Filters the login URL. @@ -389,19 +456,19 @@ */ function wp_login_form( $args = array() ) { $defaults = array( - 'echo' => true, + 'echo' => true, // Default 'redirect' value takes the user back to the request URI. - 'redirect' => ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], - 'form_id' => 'loginform', + 'redirect' => ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], + 'form_id' => 'loginform', 'label_username' => __( 'Username or Email Address' ), 'label_password' => __( 'Password' ), 'label_remember' => __( 'Remember Me' ), - 'label_log_in' => __( 'Log In' ), - 'id_username' => 'user_login', - 'id_password' => 'user_pass', - 'id_remember' => 'rememberme', - 'id_submit' => 'wp-submit', - 'remember' => true, + 'label_log_in' => __( 'Log In' ), + 'id_username' => 'user_login', + 'id_password' => 'user_pass', + 'id_remember' => 'rememberme', + 'id_submit' => 'wp-submit', + 'remember' => true, 'value_username' => '', // Set 'value_remember' to true to default the "Remember me" checkbox to checked. 'value_remember' => false, @@ -475,10 +542,11 @@ ' . $login_form_bottom . ' '; - if ( $args['echo'] ) + if ( $args['echo'] ) { echo $form; - else + } else { return $form; + } } /** @@ -491,11 +559,11 @@ */ function wp_lostpassword_url( $redirect = '' ) { $args = array( 'action' => 'lostpassword' ); - if ( !empty($redirect) ) { + if ( ! empty( $redirect ) ) { $args['redirect_to'] = urlencode( $redirect ); } - $lostpassword_url = add_query_arg( $args, network_site_url('wp-login.php', 'login') ); + $lostpassword_url = add_query_arg( $args, network_site_url( 'wp-login.php', 'login' ) ); /** * Filters the Lost Password URL. @@ -523,12 +591,13 @@ */ function wp_register( $before = '
  • ', $after = '
  • ', $echo = true ) { if ( ! is_user_logged_in() ) { - if ( get_option('users_can_register') ) - $link = $before . '' . __('Register') . '' . $after; - else + if ( get_option( 'users_can_register' ) ) { + $link = $before . '' . __( 'Register' ) . '' . $after; + } else { $link = ''; + } } elseif ( current_user_can( 'read' ) ) { - $link = $before . '' . __('Site Admin') . '' . $after; + $link = $before . '' . __( 'Site Admin' ) . '' . $after; } else { $link = ''; } @@ -609,7 +678,7 @@ * child theme will NOT take precedence over this value * - 'pingback_url' - The pingback XML-RPC file URL (xmlrpc.php) * - 'atom_url' - The Atom feed URL (/feed/atom) - * - 'rdf_url' - The RDF/RSS 1.0 feed URL (/feed/rfd) + * - 'rdf_url' - The RDF/RSS 1.0 feed URL (/feed/rdf) * - 'rss_url' - The RSS 0.92 feed URL (/feed/rss) * - 'rss2_url' - The RSS 2.0 feed URL (/feed) * - 'comments_atom_url' - The comments Atom feed URL (/comments/feed) @@ -632,42 +701,47 @@ * @return string Mostly string values, might be empty. */ function get_bloginfo( $show = '', $filter = 'raw' ) { - switch( $show ) { - case 'home' : // DEPRECATED - case 'siteurl' : // DEPRECATED - _deprecated_argument( __FUNCTION__, '2.2.0', sprintf( - /* translators: 1: 'siteurl'/'home' argument, 2: bloginfo() function name, 3: 'url' argument */ - __( 'The %1$s option is deprecated for the family of %2$s functions. Use the %3$s option instead.' ), - '' . $show . '', - 'bloginfo()', - 'url' - ) ); - case 'url' : + switch ( $show ) { + case 'home': // DEPRECATED + case 'siteurl': // DEPRECATED + _deprecated_argument( + __FUNCTION__, + '2.2.0', + sprintf( + /* translators: 1: 'siteurl'/'home' argument, 2: bloginfo() function name, 3: 'url' argument */ + __( 'The %1$s option is deprecated for the family of %2$s functions. Use the %3$s option instead.' ), + '' . $show . '', + 'bloginfo()', + 'url' + ) + ); + // Intentional fall-through to be handled by the 'url' case. + case 'url': $output = home_url(); break; - case 'wpurl' : + case 'wpurl': $output = site_url(); break; case 'description': - $output = get_option('blogdescription'); + $output = get_option( 'blogdescription' ); break; case 'rdf_url': - $output = get_feed_link('rdf'); + $output = get_feed_link( 'rdf' ); break; case 'rss_url': - $output = get_feed_link('rss'); + $output = get_feed_link( 'rss' ); break; case 'rss2_url': - $output = get_feed_link('rss2'); + $output = get_feed_link( 'rss2' ); break; case 'atom_url': - $output = get_feed_link('atom'); + $output = get_feed_link( 'atom' ); break; case 'comments_atom_url': - $output = get_feed_link('comments_atom'); + $output = get_feed_link( 'comments_atom' ); break; case 'comments_rss2_url': - $output = get_feed_link('comments_rss2'); + $output = get_feed_link( 'comments_rss2' ); break; case 'pingback_url': $output = site_url( 'xmlrpc.php' ); @@ -683,14 +757,16 @@ $output = get_template_directory_uri(); break; case 'admin_email': - $output = get_option('admin_email'); + $output = get_option( 'admin_email' ); break; case 'charset': - $output = get_option('blog_charset'); - if ('' == $output) $output = 'UTF-8'; + $output = get_option( 'blog_charset' ); + if ( '' == $output ) { + $output = 'UTF-8'; + } break; - case 'html_type' : - $output = get_option('html_type'); + case 'html_type': + $output = get_option( 'html_type' ); break; case 'version': global $wp_version; @@ -703,18 +779,22 @@ */ $output = __( 'html_lang_attribute' ); if ( 'html_lang_attribute' === $output || preg_match( '/[^a-zA-Z0-9-]/', $output ) ) { - $output = is_admin() ? get_user_locale() : get_locale(); + $output = determine_locale(); $output = str_replace( '_', '-', $output ); } break; case 'text_direction': - _deprecated_argument( __FUNCTION__, '2.2.0', sprintf( - /* translators: 1: 'text_direction' argument, 2: bloginfo() function name, 3: is_rtl() function name */ - __( 'The %1$s option is deprecated for the family of %2$s functions. Use the %3$s function instead.' ), - '' . $show . '', - 'bloginfo()', - 'is_rtl()' - ) ); + _deprecated_argument( + __FUNCTION__, + '2.2.0', + sprintf( + /* translators: 1: 'text_direction' argument, 2: bloginfo() function name, 3: is_rtl() function name */ + __( 'The %1$s option is deprecated for the family of %2$s functions. Use the %3$s function instead.' ), + '' . $show . '', + 'bloginfo()', + 'is_rtl()' + ) + ); if ( function_exists( 'is_rtl' ) ) { $output = is_rtl() ? 'rtl' : 'ltr'; } else { @@ -723,15 +803,16 @@ break; case 'name': default: - $output = get_option('blogname'); + $output = get_option( 'blogname' ); break; } $url = true; - if (strpos($show, 'url') === false && - strpos($show, 'directory') === false && - strpos($show, 'home') === false) + if ( strpos( $show, 'url' ) === false && + strpos( $show, 'directory' ) === false && + strpos( $show, 'home' ) === false ) { $url = false; + } if ( 'display' == $filter ) { if ( $url ) { @@ -864,7 +945,7 @@ * @return string Custom logo markup. */ function get_custom_logo( $blog_id = 0 ) { - $html = ''; + $html = ''; $switched_blog = false; if ( is_multisite() && ! empty( $blog_id ) && (int) $blog_id !== get_current_blog_id() ) { @@ -877,8 +958,7 @@ // We have a logo. Logo is go. if ( $custom_logo_id ) { $custom_logo_attr = array( - 'class' => 'custom-logo', - 'itemprop' => 'logo', + 'class' => 'custom-logo', ); /* @@ -894,15 +974,15 @@ * If the alt attribute is not empty, there's no need to explicitly pass * it because wp_get_attachment_image() already adds the alt attribute. */ - $html = sprintf( '', + $html = sprintf( + '%2$s', esc_url( home_url( '/' ) ), wp_get_attachment_image( $custom_logo_id, 'full', false, $custom_logo_attr ) ); - } - - // If no logo is set but we're in the Customizer, leave a placeholder (needed for the live preview). - elseif ( is_customize_preview() ) { - $html = sprintf( '', + } elseif ( is_customize_preview() ) { + // If no logo is set but we're in the Customizer, leave a placeholder (needed for the live preview). + $html = sprintf( + '', esc_url( home_url( '/' ) ) ); } @@ -971,39 +1051,39 @@ if ( is_404() ) { $title['title'] = __( 'Page not found' ); - // If it's a search, use a dynamic search results title. + // If it's a search, use a dynamic search results title. } elseif ( is_search() ) { /* translators: %s: search phrase */ $title['title'] = sprintf( __( 'Search Results for “%s”' ), get_search_query() ); - // If on the front page, use the site title. + // If on the front page, use the site title. } elseif ( is_front_page() ) { $title['title'] = get_bloginfo( 'name', 'display' ); - // If on a post type archive, use the post type archive title. + // If on a post type archive, use the post type archive title. } elseif ( is_post_type_archive() ) { $title['title'] = post_type_archive_title( '', false ); - // If on a taxonomy archive, use the term title. + // If on a taxonomy archive, use the term title. } elseif ( is_tax() ) { $title['title'] = single_term_title( '', false ); - /* - * If we're on the blog page that is not the homepage or - * a single post of any post type, use the post title. - */ + /* + * If we're on the blog page that is not the homepage or + * a single post of any post type, use the post title. + */ } elseif ( is_home() || is_singular() ) { $title['title'] = single_post_title( '', false ); - // If on a category or tag archive, use the term title. + // If on a category or tag archive, use the term title. } elseif ( is_category() || is_tag() ) { $title['title'] = single_term_title( '', false ); - // If on an author archive, use the author's display name. + // If on an author archive, use the author's display name. } elseif ( is_author() && $author = get_queried_object() ) { $title['title'] = $author->display_name; - // If it's a date archive, use the date as the title. + // If it's a date archive, use the date as the title. } elseif ( is_year() ) { $title['title'] = get_the_date( _x( 'Y', 'yearly archives date format' ) ); @@ -1247,8 +1327,9 @@ function single_post_title( $prefix = '', $display = true ) { $_post = get_queried_object(); - if ( !isset($_post->post_title) ) + if ( ! isset( $_post->post_title ) ) { return; + } /** * Filters the page title for a single post. @@ -1259,10 +1340,11 @@ * @param object $_post The current queried object as returned by get_queried_object(). */ $title = apply_filters( 'single_post_title', $_post->post_title, $_post ); - if ( $display ) + if ( $display ) { echo $prefix . $title; - else + } else { return $prefix . $title; + } } /** @@ -1278,12 +1360,14 @@ * @return string|void Title when retrieving, null when displaying or failure. */ function post_type_archive_title( $prefix = '', $display = true ) { - if ( ! is_post_type_archive() ) + if ( ! is_post_type_archive() ) { return; + } $post_type = get_query_var( 'post_type' ); - if ( is_array( $post_type ) ) + if ( is_array( $post_type ) ) { $post_type = reset( $post_type ); + } $post_type_obj = get_post_type_object( $post_type ); @@ -1297,10 +1381,11 @@ */ $title = apply_filters( 'post_type_archive_title', $post_type_obj->labels->name, $post_type ); - if ( $display ) + if ( $display ) { echo $prefix . $title; - else + } else { return $prefix . $title; + } } /** @@ -1353,8 +1438,9 @@ function single_term_title( $prefix = '', $display = true ) { $term = get_queried_object(); - if ( !$term ) + if ( ! $term ) { return; + } if ( is_category() ) { /** @@ -1387,13 +1473,15 @@ return; } - if ( empty( $term_name ) ) + if ( empty( $term_name ) ) { return; - - if ( $display ) + } + + if ( $display ) { echo $prefix . $term_name; - else + } else { return $prefix . $term_name; + } } /** @@ -1412,28 +1500,30 @@ * @param bool $display Optional, default is true. Whether to display or retrieve title. * @return string|void Title when retrieving. */ -function single_month_title($prefix = '', $display = true ) { +function single_month_title( $prefix = '', $display = true ) { global $wp_locale; - $m = get_query_var('m'); - $year = get_query_var('year'); - $monthnum = get_query_var('monthnum'); - - if ( !empty($monthnum) && !empty($year) ) { - $my_year = $year; - $my_month = $wp_locale->get_month($monthnum); - } elseif ( !empty($m) ) { - $my_year = substr($m, 0, 4); - $my_month = $wp_locale->get_month(substr($m, 4, 2)); + $m = get_query_var( 'm' ); + $year = get_query_var( 'year' ); + $monthnum = get_query_var( 'monthnum' ); + + if ( ! empty( $monthnum ) && ! empty( $year ) ) { + $my_year = $year; + $my_month = $wp_locale->get_month( $monthnum ); + } elseif ( ! empty( $m ) ) { + $my_year = substr( $m, 0, 4 ); + $my_month = $wp_locale->get_month( substr( $m, 4, 2 ) ); } - if ( empty($my_month) ) + if ( empty( $my_month ) ) { return false; + } $result = $prefix . $my_month . $prefix . $my_year; - if ( !$display ) + if ( ! $display ) { return $result; + } echo $result; } @@ -1464,22 +1554,22 @@ */ function get_the_archive_title() { if ( is_category() ) { - /* translators: Category archive title. 1: Category name */ + /* translators: Category archive title. %s: Category name */ $title = sprintf( __( 'Category: %s' ), single_cat_title( '', false ) ); } elseif ( is_tag() ) { - /* translators: Tag archive title. 1: Tag name */ + /* translators: Tag archive title. %s: Tag name */ $title = sprintf( __( 'Tag: %s' ), single_tag_title( '', false ) ); } elseif ( is_author() ) { - /* translators: Author archive title. 1: Author name */ + /* translators: Author archive title. %s: Author name */ $title = sprintf( __( 'Author: %s' ), '' . get_the_author() . '' ); } elseif ( is_year() ) { - /* translators: Yearly archive title. 1: Year */ + /* translators: Yearly archive title. %s: Year */ $title = sprintf( __( 'Year: %s' ), get_the_date( _x( 'Y', 'yearly archives date format' ) ) ); } elseif ( is_month() ) { - /* translators: Monthly archive title. 1: Month name and year */ + /* translators: Monthly archive title. %s: Month name and year */ $title = sprintf( __( 'Month: %s' ), get_the_date( _x( 'F Y', 'monthly archives date format' ) ) ); } elseif ( is_day() ) { - /* translators: Daily archive title. 1: Date */ + /* translators: Daily archive title. %s: Date */ $title = sprintf( __( 'Day: %s' ), get_the_date( _x( 'F j, Y', 'daily archives date format' ) ) ); } elseif ( is_tax( 'post_format' ) ) { if ( is_tax( 'post_format', 'post-format-aside' ) ) { @@ -1502,7 +1592,7 @@ $title = _x( 'Chats', 'post format archive title' ); } } elseif ( is_post_type_archive() ) { - /* translators: Post type archive title. 1: Post type name */ + /* translators: Post type archive title. %s: Post type name */ $title = sprintf( __( 'Archives: %s' ), post_type_archive_title( '', false ) ); } elseif ( is_tax() ) { $tax = get_taxonomy( get_queried_object()->taxonomy ); @@ -1628,32 +1718,37 @@ * three values for the format are not used, then custom format is assumed. * * @since 1.0.0 - * - * @param string $url URL to archive. - * @param string $text Archive text description. - * @param string $format Optional, default is 'html'. Can be 'link', 'option', 'html', or custom. - * @param string $before Optional. Content to prepend to the description. Default empty. - * @param string $after Optional. Content to append to the description. Default empty. + * @since 5.2.0 Added the `$selected` parameter. + * + * @param string $url URL to archive. + * @param string $text Archive text description. + * @param string $format Optional, default is 'html'. Can be 'link', 'option', 'html', or custom. + * @param string $before Optional. Content to prepend to the description. Default empty. + * @param string $after Optional. Content to append to the description. Default empty. + * @param bool $selected Optional. Set to true if the current page is the selected archive page. * @return string HTML link content for archive. */ -function get_archives_link($url, $text, $format = 'html', $before = '', $after = '') { - $text = wptexturize($text); - $url = esc_url($url); - - if ('link' == $format) +function get_archives_link( $url, $text, $format = 'html', $before = '', $after = '', $selected = false ) { + $text = wptexturize( $text ); + $url = esc_url( $url ); + + if ( 'link' == $format ) { $link_html = "\t\n"; - elseif ('option' == $format) - $link_html = "\t\n"; - elseif ('html' == $format) + } elseif ( 'option' == $format ) { + $selected_attr = $selected ? " selected='selected'" : ''; + $link_html = "\t\n"; + } elseif ( 'html' == $format ) { $link_html = "\t
  • $before$text$after
  • \n"; - else // custom + } else { // custom $link_html = "\t$before$text$after\n"; + } /** * Filters the archive link content. * * @since 2.6.0 * @since 4.5.0 Added the `$url`, `$text`, `$format`, `$before`, and `$after` parameters. + * @since 5.2.0 Added the `$selected` parameter. * * @param string $link_html The archive HTML link content. * @param string $url URL to archive. @@ -1661,15 +1756,17 @@ * @param string $format Link format. Can be 'link', 'option', 'html', or custom. * @param string $before Content to prepend to the description. * @param string $after Content to append to the description. + * @param bool $selected True if the current page is the selected archive. */ - return apply_filters( 'get_archives_link', $link_html, $url, $text, $format, $before, $after ); + return apply_filters( 'get_archives_link', $link_html, $url, $text, $format, $before, $after, $selected ); } /** * Display archive links based on type and format. * * @since 1.2.0 - * @since 4.4.0 $post_type arg was added. + * @since 4.4.0 The `$post_type` argument was added. + * @since 5.2.0 The `$year`, `$monthnum`, `$day`, and `$w` arguments were added. * * @see get_archives_link() * @@ -1697,6 +1794,10 @@ * @type string $order Whether to use ascending or descending order. Accepts 'ASC', or 'DESC'. * Default 'DESC'. * @type string $post_type Post type. Default 'post'. + * @type string $year Year. Default current year. + * @type string $monthnum Month number. Default current month number. + * @type string $day Day. Default current day. + * @type string $w Week. Default current week. * } * @return string|void String when retrieving. */ @@ -1704,11 +1805,19 @@ global $wpdb, $wp_locale; $defaults = array( - 'type' => 'monthly', 'limit' => '', - 'format' => 'html', 'before' => '', - 'after' => '', 'show_post_count' => false, - 'echo' => 1, 'order' => 'DESC', - 'post_type' => 'post' + 'type' => 'monthly', + 'limit' => '', + 'format' => 'html', + 'before' => '', + 'after' => '', + 'show_post_count' => false, + 'echo' => 1, + 'order' => 'DESC', + 'post_type' => 'post', + 'year' => get_query_var( 'year' ), + 'monthnum' => get_query_var( 'monthnum' ), + 'day' => get_query_var( 'day' ), + 'w' => get_query_var( 'w' ), ); $r = wp_parse_args( $args, $defaults ); @@ -1766,8 +1875,8 @@ if ( 'monthly' == $r['type'] ) { $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"; - $key = md5( $query ); - $key = "wp_get_archives:$key:$last_changed"; + $key = md5( $query ); + $key = "wp_get_archives:$key:$last_changed"; if ( ! $results = wp_cache_get( $key, 'posts' ) ) { $results = $wpdb->get_results( $query ); wp_cache_set( $key, $results, 'posts' ); @@ -1784,20 +1893,21 @@ if ( $r['show_post_count'] ) { $r['after'] = ' (' . $result->posts . ')' . $after; } - $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] ); + $selected = is_archive() && (string) $r['year'] === $result->year && (string) $r['monthnum'] === $result->month; + $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'], $selected ); } } } elseif ( 'yearly' == $r['type'] ) { $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"; - $key = md5( $query ); - $key = "wp_get_archives:$key:$last_changed"; + $key = md5( $query ); + $key = "wp_get_archives:$key:$last_changed"; if ( ! $results = wp_cache_get( $key, 'posts' ) ) { $results = $wpdb->get_results( $query ); wp_cache_set( $key, $results, 'posts' ); } if ( $results ) { $after = $r['after']; - foreach ( (array) $results as $result) { + foreach ( (array) $results as $result ) { $url = get_year_link( $result->year ); if ( 'post' !== $r['post_type'] ) { $url = add_query_arg( 'post_type', $r['post_type'], $url ); @@ -1806,13 +1916,14 @@ if ( $r['show_post_count'] ) { $r['after'] = ' (' . $result->posts . ')' . $after; } - $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] ); + $selected = is_archive() && (string) $r['year'] === $result->year; + $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'], $selected ); } } } elseif ( 'daily' == $r['type'] ) { $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"; - $key = md5( $query ); - $key = "wp_get_archives:$key:$last_changed"; + $key = md5( $query ); + $key = "wp_get_archives:$key:$last_changed"; if ( ! $results = wp_cache_get( $key, 'posts' ) ) { $results = $wpdb->get_results( $query ); wp_cache_set( $key, $results, 'posts' ); @@ -1820,7 +1931,7 @@ if ( $results ) { $after = $r['after']; foreach ( (array) $results as $result ) { - $url = get_day_link( $result->year, $result->month, $result->dayofmonth ); + $url = get_day_link( $result->year, $result->month, $result->dayofmonth ); if ( 'post' !== $r['post_type'] ) { $url = add_query_arg( 'post_type', $r['post_type'], $url ); } @@ -1829,14 +1940,15 @@ if ( $r['show_post_count'] ) { $r['after'] = ' (' . $result->posts . ')' . $after; } - $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] ); + $selected = is_archive() && (string) $r['year'] === $result->year && (string) $r['monthnum'] === $result->month && (string) $r['day'] === $result->dayofmonth; + $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'], $selected ); } } } elseif ( 'weekly' == $r['type'] ) { - $week = _wp_mysql_week( '`post_date`' ); + $week = _wp_mysql_week( '`post_date`' ); $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"; - $key = md5( $query ); - $key = "wp_get_archives:$key:$last_changed"; + $key = md5( $query ); + $key = "wp_get_archives:$key:$last_changed"; if ( ! $results = wp_cache_get( $key, 'posts' ) ) { $results = $wpdb->get_results( $query ); wp_cache_set( $key, $results, 'posts' ); @@ -1851,23 +1963,30 @@ $arc_week = get_weekstartend( $result->yyyymmdd, get_option( 'start_of_week' ) ); $arc_week_start = date_i18n( get_option( 'date_format' ), $arc_week['start'] ); $arc_week_end = date_i18n( get_option( 'date_format' ), $arc_week['end'] ); - $url = add_query_arg( array( 'm' => $arc_year, 'w' => $result->week, ), home_url( '/' ) ); + $url = add_query_arg( + array( + 'm' => $arc_year, + 'w' => $result->week, + ), + home_url( '/' ) + ); if ( 'post' !== $r['post_type'] ) { $url = add_query_arg( 'post_type', $r['post_type'], $url ); } - $text = $arc_week_start . $archive_week_separator . $arc_week_end; + $text = $arc_week_start . $archive_week_separator . $arc_week_end; if ( $r['show_post_count'] ) { $r['after'] = ' (' . $result->posts . ')' . $after; } - $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] ); + $selected = is_archive() && (string) $r['year'] === $result->yr && (string) $r['w'] === $result->week; + $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'], $selected ); } } } - } elseif ( ( 'postbypost' == $r['type'] ) || ('alpha' == $r['type'] ) ) { + } elseif ( ( 'postbypost' == $r['type'] ) || ( 'alpha' == $r['type'] ) ) { $orderby = ( 'alpha' == $r['type'] ) ? 'post_title ASC ' : 'post_date DESC, ID DESC '; - $query = "SELECT * FROM $wpdb->posts $join $where ORDER BY $orderby $limit"; - $key = md5( $query ); - $key = "wp_get_archives:$key:$last_changed"; + $query = "SELECT * FROM $wpdb->posts $join $where ORDER BY $orderby $limit"; + $key = md5( $query ); + $key = "wp_get_archives:$key:$last_changed"; if ( ! $results = wp_cache_get( $key, 'posts' ) ) { $results = $wpdb->get_results( $query ); wp_cache_set( $key, $results, 'posts' ); @@ -1882,7 +2001,8 @@ } else { $text = $result->ID; } - $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] ); + $selected = $result->ID === get_the_ID(); + $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'], $selected ); } } } @@ -1902,9 +2022,9 @@ * @param int $num Number of day. * @return float Days since the start of the week. */ -function calendar_week_mod($num) { +function calendar_week_mod( $num ) { $base = 7; - return ($num - $base*floor($num/$base)); + return ( $num - $base * floor( $num / $base ) ); } /** @@ -1929,7 +2049,7 @@ function get_calendar( $initial = true, $echo = true ) { global $wpdb, $m, $monthnum, $year, $wp_locale, $posts; - $key = md5( $m . $monthnum . $year ); + $key = md5( $m . $monthnum . $year ); $cache = wp_cache_get( 'get_calendar', 'calendar' ); if ( $cache && is_array( $cache ) && isset( $cache[ $key ] ) ) { @@ -1950,7 +2070,7 @@ // Quick check. If we have no posts at all, abort! if ( ! $posts ) { - $gotsome = $wpdb->get_var("SELECT 1 as test FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 1"); + $gotsome = $wpdb->get_var( "SELECT 1 as test FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 1" ); if ( ! $gotsome ) { $cache[ $key ] = ''; wp_cache_set( 'get_calendar', $cache, 'calendar' ); @@ -1963,18 +2083,17 @@ } // week_begins = 0 stands for Sunday $week_begins = (int) get_option( 'start_of_week' ); - $ts = current_time( 'timestamp' ); // Let's figure out when we are if ( ! empty( $monthnum ) && ! empty( $year ) ) { $thismonth = zeroise( intval( $monthnum ), 2 ); - $thisyear = (int) $year; + $thisyear = (int) $year; } elseif ( ! empty( $w ) ) { // We need to get the month from MySQL $thisyear = (int) substr( $m, 0, 4 ); //it seems MySQL's weeks disagree with PHP's - $d = ( ( $w - 1 ) * 7 ) + 6; - $thismonth = $wpdb->get_var("SELECT DATE_FORMAT((DATE_ADD('{$thisyear}0101', INTERVAL $d DAY) ), '%m')"); + $d = ( ( $w - 1 ) * 7 ) + 6; + $thismonth = $wpdb->get_var( "SELECT DATE_FORMAT((DATE_ADD('{$thisyear}0101', INTERVAL $d DAY) ), '%m')" ); } elseif ( ! empty( $m ) ) { $thisyear = (int) substr( $m, 0, 4 ); if ( strlen( $m ) < 6 ) { @@ -1983,30 +2102,34 @@ $thismonth = zeroise( (int) substr( $m, 4, 2 ), 2 ); } } else { - $thisyear = gmdate( 'Y', $ts ); - $thismonth = gmdate( 'm', $ts ); + $thisyear = current_time( 'Y' ); + $thismonth = current_time( 'm' ); } - $unixmonth = mktime( 0, 0 , 0, $thismonth, 1, $thisyear ); - $last_day = date( 't', $unixmonth ); + $unixmonth = mktime( 0, 0, 0, $thismonth, 1, $thisyear ); + $last_day = date( 't', $unixmonth ); // Get the next and previous month and year with at least one post - $previous = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year + $previous = $wpdb->get_row( + "SELECT MONTH(post_date) AS month, YEAR(post_date) AS year FROM $wpdb->posts WHERE post_date < '$thisyear-$thismonth-01' AND post_type = 'post' AND post_status = 'publish' ORDER BY post_date DESC - LIMIT 1"); - $next = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year + LIMIT 1" + ); + $next = $wpdb->get_row( + "SELECT MONTH(post_date) AS month, YEAR(post_date) AS year FROM $wpdb->posts WHERE post_date > '$thisyear-$thismonth-{$last_day} 23:59:59' AND post_type = 'post' AND post_status = 'publish' ORDER BY post_date ASC - LIMIT 1"); + LIMIT 1" + ); /* translators: Calendar caption: 1: month name, 2: 4-digit year */ - $calendar_caption = _x('%1$s %2$s', 'calendar caption'); - $calendar_output = ' + $calendar_caption = _x( '%1$s %2$s', 'calendar caption' ); + $calendar_output = '
    "; } @@ -2035,21 +2158,21 @@ '; if ( $previous ) { - $calendar_output .= "\n\t\t".''; } else { - $calendar_output .= "\n\t\t".''; + $calendar_output .= "\n\t\t" . ''; } - $calendar_output .= "\n\t\t".''; + $calendar_output .= "\n\t\t" . ''; if ( $next ) { - $calendar_output .= "\n\t\t".''; } else { - $calendar_output .= "\n\t\t".''; + $calendar_output .= "\n\t\t" . ''; } $calendar_output .= ' @@ -2062,10 +2185,13 @@ $daywithpost = array(); // Get days with posts - $dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date) + $dayswithposts = $wpdb->get_results( + "SELECT DISTINCT DAYOFMONTH(post_date) FROM $wpdb->posts WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00' AND post_type = 'post' AND post_status = 'publish' - AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59'", ARRAY_N); + AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59'", + ARRAY_N + ); if ( $dayswithposts ) { foreach ( (array) $dayswithposts as $daywith ) { $daywithpost[] = $daywith[0]; @@ -2075,21 +2201,21 @@ // See how much we should pad in the beginning $pad = calendar_week_mod( date( 'w', $unixmonth ) - $week_begins ); if ( 0 != $pad ) { - $calendar_output .= "\n\t\t".''; + $calendar_output .= "\n\t\t" . ''; } - $newrow = false; + $newrow = false; $daysinmonth = (int) date( 't', $unixmonth ); for ( $day = 1; $day <= $daysinmonth; ++$day ) { - if ( isset($newrow) && $newrow ) { + if ( isset( $newrow ) && $newrow ) { $calendar_output .= "\n\t\n\t\n\t\t"; } $newrow = false; - if ( $day == gmdate( 'j', $ts ) && - $thismonth == gmdate( 'm', $ts ) && - $thisyear == gmdate( 'Y', $ts ) ) { + if ( $day == current_time( 'j' ) && + $thismonth == current_time( 'm' ) && + $thisyear == current_time( 'Y' ) ) { $calendar_output .= ''; - if ( 6 == calendar_week_mod( date( 'w', mktime(0, 0 , 0, $thismonth, $day, $thisyear ) ) - $week_begins ) ) { + if ( 6 == calendar_week_mod( date( 'w', mktime( 0, 0, 0, $thismonth, $day, $thisyear ) ) - $week_begins ) ) { $newrow = true; } } - $pad = 7 - calendar_week_mod( date( 'w', mktime( 0, 0 , 0, $thismonth, $day, $thisyear ) ) - $week_begins ); + $pad = 7 - calendar_week_mod( date( 'w', mktime( 0, 0, 0, $thismonth, $day, $thisyear ) ) - $week_begins ); if ( $pad != 0 && $pad != 7 ) { - $calendar_output .= "\n\t\t".''; + $calendar_output .= "\n\t\t" . ''; } $calendar_output .= "\n\t\n\t\n\t
    ' . sprintf( $calendar_caption, $wp_locale->get_month( $thismonth ), @@ -2022,8 +2145,8 @@ } foreach ( $myweek as $wd ) { - $day_name = $initial ? $wp_locale->get_weekday_initial( $wd ) : $wp_locale->get_weekday_abbrev( $wd ); - $wd = esc_attr( $wd ); + $day_name = $initial ? $wp_locale->get_weekday_initial( $wd ) : $wp_locale->get_weekday_abbrev( $wd ); + $wd = esc_attr( $wd ); $calendar_output .= "\n\t\t
    $day_name
    « ' . + $calendar_output .= "\n\t\t" . '« ' . $wp_locale->get_month_abbrev( $wp_locale->get_month( $previous->month ) ) . '    ' . + $calendar_output .= "\n\t\t" . '' . $wp_locale->get_month_abbrev( $wp_locale->get_month( $next->month ) ) . ' »    
    '; } else { $calendar_output .= ''; @@ -2098,8 +2224,8 @@ if ( in_array( $day, $daywithpost ) ) { // any posts today? $date_format = date( _x( 'F j, Y', 'daily archives date format' ), strtotime( "{$thisyear}-{$thismonth}-{$day}" ) ); - /* translators: Post calendar label. 1: Date */ - $label = sprintf( __( 'Posts published on %s' ), $date_format ); + /* translators: Post calendar label. %s: Date */ + $label = sprintf( __( 'Posts published on %s' ), $date_format ); $calendar_output .= sprintf( '%s', get_day_link( $thisyear, $thismonth, $day ), @@ -2111,14 +2237,14 @@ } $calendar_output .= '  
    "; @@ -2166,10 +2292,10 @@ global $allowedtags; $allowed = ''; foreach ( (array) $allowedtags as $tag => $attributes ) { - $allowed .= '<'.$tag; - if ( 0 < count($attributes) ) { + $allowed .= '<' . $tag; + if ( 0 < count( $attributes ) ) { foreach ( $attributes as $attribute => $limits ) { - $allowed .= ' '.$attribute.'=""'; + $allowed .= ' ' . $attribute . '=""'; } } $allowed .= '> '; @@ -2177,7 +2303,7 @@ return htmlentities( $allowed ); } -/***** Date/Time tags *****/ +/***** Date/Time tags */ /** * Outputs the date in iso8601 format for xml files. @@ -2215,7 +2341,7 @@ global $currentday, $previousday; if ( is_new_day() ) { - $the_date = $before . get_the_date( $d ) . $after; + $the_date = $before . get_the_date( $d ) . $after; $previousday = $currentday; /** @@ -2231,10 +2357,11 @@ */ $the_date = apply_filters( 'the_date', $the_date, $d, $before, $after ); - if ( $echo ) + if ( $echo ) { echo $the_date; - else + } else { return $the_date; + } } } @@ -2258,9 +2385,9 @@ } if ( '' == $d ) { - $the_date = mysql2date( get_option( 'date_format' ), $post->post_date ); + $the_date = get_post_time( get_option( 'date_format' ), false, $post, true ); } else { - $the_date = mysql2date( $d, $post->post_date ); + $the_date = get_post_time( $d, false, $post, true ); } /** @@ -2288,7 +2415,7 @@ * @return string|void String if retrieving. */ function the_modified_date( $d = '', $before = '', $after = '', $echo = true ) { - $the_modified_date = $before . get_the_modified_date($d) . $after; + $the_modified_date = $before . get_the_modified_date( $d ) . $after; /** * Filters the date a post was last modified for display. @@ -2303,10 +2430,11 @@ */ $the_modified_date = apply_filters( 'the_modified_date', $the_modified_date, $d, $before, $after ); - if ( $echo ) + if ( $echo ) { echo $the_modified_date; - else + } else { return $the_modified_date; + } } @@ -2375,19 +2503,20 @@ * was written. Either 'G', 'U', or php date format defaults * to the value specified in the time_format option. Default empty. * @param int|WP_Post $post WP_Post object or ID. Default is global $post object. - * @return string|int|false Formatted date string or Unix timestamp if `$id` is 'U' or 'G'. False on failure. + * @return string|int|false Formatted date string or Unix timestamp if `$d` is 'U' or 'G'. False on failure. */ function get_the_time( $d = '', $post = null ) { - $post = get_post($post); + $post = get_post( $post ); if ( ! $post ) { return false; } - if ( '' == $d ) - $the_time = get_post_time(get_option('time_format'), false, $post, true); - else - $the_time = get_post_time($d, false, $post, true); + if ( '' == $d ) { + $the_time = get_post_time( get_option( 'time_format' ), false, $post, true ); + } else { + $the_time = get_post_time( $d, false, $post, true ); + } /** * Filters the time a post was written. @@ -2413,21 +2542,22 @@ * @param bool $gmt Optional. Whether to retrieve the GMT time. Default false. * @param int|WP_Post $post WP_Post object or ID. Default is global $post object. * @param bool $translate Whether to translate the time string. Default false. - * @return string|int|false Formatted date string or Unix timestamp if `$id` is 'U' or 'G'. False on failure. + * @return string|int|false Formatted date string or Unix timestamp if `$d` is 'U' or 'G'. False on failure. */ function get_post_time( $d = 'U', $gmt = false, $post = null, $translate = false ) { - $post = get_post($post); + $post = get_post( $post ); if ( ! $post ) { return false; } - if ( $gmt ) + if ( $gmt ) { $time = $post->post_date_gmt; - else + } else { $time = $post->post_date; - - $time = mysql2date($d, $time, $translate); + } + + $time = mysql2date( $d, $time, $translate ); /** * Filters the localized time a post was written. @@ -2449,7 +2579,7 @@ * * @param string $d Optional Either 'G', 'U', or php date format defaults to the value specified in the time_format option. */ -function the_modified_time($d = '') { +function the_modified_time( $d = '' ) { /** * Filters the localized time a post was last modified, for display. * @@ -2460,7 +2590,7 @@ * or php date format. Defaults to value * specified in 'time_format' option. */ - echo apply_filters( 'the_modified_time', get_the_modified_time($d), $d ); + echo apply_filters( 'the_modified_time', get_the_modified_time( $d ), $d ); } /** @@ -2512,20 +2642,21 @@ * @param bool $gmt Optional. Whether to retrieve the GMT time. Default false. * @param int|WP_Post $post WP_Post object or ID. Default is global $post object. * @param bool $translate Whether to translate the time string. Default false. - * @return string|int|false Formatted date string or Unix timestamp if `$id` is 'U' or 'G'. False on failure. + * @return string|int|false Formatted date string or Unix timestamp if `$d` is 'U' or 'G'. False on failure. */ function get_post_modified_time( $d = 'U', $gmt = false, $post = null, $translate = false ) { - $post = get_post($post); + $post = get_post( $post ); if ( ! $post ) { return false; } - if ( $gmt ) + if ( $gmt ) { $time = $post->post_modified_gmt; - else + } else { $time = $post->post_modified; - $time = mysql2date($d, $time, $translate); + } + $time = mysql2date( $d, $time, $translate ); /** * Filters the localized time a post was last modified. @@ -2575,14 +2706,14 @@ * @param string $before Optional Output before the date. * @param string $after Optional Output after the date. */ -function the_weekday_date($before='',$after='') { +function the_weekday_date( $before = '', $after = '' ) { global $wp_locale, $currentday, $previousweekday; $the_weekday_date = ''; if ( $currentday != $previousweekday ) { $the_weekday_date .= $before; $the_weekday_date .= $wp_locale->get_weekday( mysql2date( 'w', get_post()->post_date, false ) ); $the_weekday_date .= $after; - $previousweekday = $currentday; + $previousweekday = $currentday; } /** @@ -2631,6 +2762,22 @@ } /** + * Fire the wp_body_open action. + * + * * See {@see 'wp_body_open'}. + * + * @since 5.2.0 + */ +function wp_body_open() { + /** + * Triggered after the opening tag. + * + * @since 5.2.0 + */ + do_action( 'wp_body_open' ); +} + +/** * Display the links to the general feeds. * * @since 2.8.0 @@ -2638,16 +2785,17 @@ * @param array $args Optional arguments. */ function feed_links( $args = array() ) { - if ( !current_theme_supports('automatic-feed-links') ) + if ( ! current_theme_supports( 'automatic-feed-links' ) ) { return; + } $defaults = array( /* translators: Separator between blog name and feed type in feed links */ - 'separator' => _x('»', 'feed link'), + 'separator' => _x( '»', 'feed link' ), /* translators: 1: blog title, 2: separator (raquo) */ - 'feedtitle' => __('%1$s %2$s Feed'), + 'feedtitle' => __( '%1$s %2$s Feed' ), /* translators: 1: blog title, 2: separator (raquo) */ - 'comstitle' => __('%1$s %2$s Comments Feed'), + 'comstitle' => __( '%1$s %2$s Comments Feed' ), ); $args = wp_parse_args( $args, $defaults ); @@ -2685,77 +2833,80 @@ function feed_links_extra( $args = array() ) { $defaults = array( /* translators: Separator between blog name and feed type in feed links */ - 'separator' => _x('»', 'feed link'), + 'separator' => _x( '»', 'feed link' ), /* translators: 1: blog name, 2: separator(raquo), 3: post title */ - 'singletitle' => __('%1$s %2$s %3$s Comments Feed'), + 'singletitle' => __( '%1$s %2$s %3$s Comments Feed' ), /* translators: 1: blog name, 2: separator(raquo), 3: category name */ - 'cattitle' => __('%1$s %2$s %3$s Category Feed'), + 'cattitle' => __( '%1$s %2$s %3$s Category Feed' ), /* translators: 1: blog name, 2: separator(raquo), 3: tag name */ - 'tagtitle' => __('%1$s %2$s %3$s Tag Feed'), + 'tagtitle' => __( '%1$s %2$s %3$s Tag Feed' ), /* translators: 1: blog name, 2: separator(raquo), 3: term name, 4: taxonomy singular name */ - 'taxtitle' => __('%1$s %2$s %3$s %4$s Feed'), + 'taxtitle' => __( '%1$s %2$s %3$s %4$s Feed' ), /* translators: 1: blog name, 2: separator(raquo), 3: author name */ - 'authortitle' => __('%1$s %2$s Posts by %3$s Feed'), + 'authortitle' => __( '%1$s %2$s Posts by %3$s Feed' ), /* translators: 1: blog name, 2: separator(raquo), 3: search phrase */ - 'searchtitle' => __('%1$s %2$s Search Results for “%3$s” Feed'), + 'searchtitle' => __( '%1$s %2$s Search Results for “%3$s” Feed' ), /* translators: 1: blog name, 2: separator(raquo), 3: post type name */ - 'posttypetitle' => __('%1$s %2$s %3$s Feed'), + 'posttypetitle' => __( '%1$s %2$s %3$s Feed' ), ); $args = wp_parse_args( $args, $defaults ); if ( is_singular() ) { - $id = 0; + $id = 0; $post = get_post( $id ); if ( comments_open() || pings_open() || $post->comment_count > 0 ) { - $title = sprintf( $args['singletitle'], get_bloginfo('name'), $args['separator'], the_title_attribute( array( 'echo' => false ) ) ); - $href = get_post_comments_feed_link( $post->ID ); + $title = sprintf( $args['singletitle'], get_bloginfo( 'name' ), $args['separator'], the_title_attribute( array( 'echo' => false ) ) ); + $href = get_post_comments_feed_link( $post->ID ); } } elseif ( is_post_type_archive() ) { $post_type = get_query_var( 'post_type' ); - if ( is_array( $post_type ) ) + if ( is_array( $post_type ) ) { $post_type = reset( $post_type ); + } $post_type_obj = get_post_type_object( $post_type ); - $title = sprintf( $args['posttypetitle'], get_bloginfo( 'name' ), $args['separator'], $post_type_obj->labels->name ); - $href = get_post_type_archive_feed_link( $post_type_obj->name ); + $title = sprintf( $args['posttypetitle'], get_bloginfo( 'name' ), $args['separator'], $post_type_obj->labels->name ); + $href = get_post_type_archive_feed_link( $post_type_obj->name ); } elseif ( is_category() ) { $term = get_queried_object(); if ( $term ) { - $title = sprintf( $args['cattitle'], get_bloginfo('name'), $args['separator'], $term->name ); - $href = get_category_feed_link( $term->term_id ); + $title = sprintf( $args['cattitle'], get_bloginfo( 'name' ), $args['separator'], $term->name ); + $href = get_category_feed_link( $term->term_id ); } } elseif ( is_tag() ) { $term = get_queried_object(); if ( $term ) { - $title = sprintf( $args['tagtitle'], get_bloginfo('name'), $args['separator'], $term->name ); - $href = get_tag_feed_link( $term->term_id ); + $title = sprintf( $args['tagtitle'], get_bloginfo( 'name' ), $args['separator'], $term->name ); + $href = get_tag_feed_link( $term->term_id ); } } elseif ( is_tax() ) { - $term = get_queried_object(); - $tax = get_taxonomy( $term->taxonomy ); - $title = sprintf( $args['taxtitle'], get_bloginfo('name'), $args['separator'], $term->name, $tax->labels->singular_name ); - $href = get_term_feed_link( $term->term_id, $term->taxonomy ); + $term = get_queried_object(); + $tax = get_taxonomy( $term->taxonomy ); + $title = sprintf( $args['taxtitle'], get_bloginfo( 'name' ), $args['separator'], $term->name, $tax->labels->singular_name ); + $href = get_term_feed_link( $term->term_id, $term->taxonomy ); } elseif ( is_author() ) { - $author_id = intval( get_query_var('author') ); - - $title = sprintf( $args['authortitle'], get_bloginfo('name'), $args['separator'], get_the_author_meta( 'display_name', $author_id ) ); - $href = get_author_feed_link( $author_id ); + $author_id = intval( get_query_var( 'author' ) ); + + $title = sprintf( $args['authortitle'], get_bloginfo( 'name' ), $args['separator'], get_the_author_meta( 'display_name', $author_id ) ); + $href = get_author_feed_link( $author_id ); } elseif ( is_search() ) { - $title = sprintf( $args['searchtitle'], get_bloginfo('name'), $args['separator'], get_search_query( false ) ); - $href = get_search_feed_link(); + $title = sprintf( $args['searchtitle'], get_bloginfo( 'name' ), $args['separator'], get_search_query( false ) ); + $href = get_search_feed_link(); } elseif ( is_post_type_archive() ) { - $title = sprintf( $args['posttypetitle'], get_bloginfo('name'), $args['separator'], post_type_archive_title( '', false ) ); + $title = sprintf( $args['posttypetitle'], get_bloginfo( 'name' ), $args['separator'], post_type_archive_title( '', false ) ); $post_type_obj = get_queried_object(); - if ( $post_type_obj ) + if ( $post_type_obj ) { $href = get_post_type_archive_feed_link( $post_type_obj->name ); + } } - if ( isset($title) && isset($href) ) + if ( isset( $title ) && isset( $href ) ) { echo '' . "\n"; + } } /** @@ -2796,8 +2947,9 @@ */ function noindex() { // If the blog is not public, tell robots to go away. - if ( '0' == get_option('blog_public') ) + if ( '0' == get_option( 'blog_public' ) ) { wp_no_robots(); + } } /** @@ -2813,6 +2965,24 @@ } /** + * Display a noindex,noarchive meta tag and referrer origin-when-cross-origin meta tag. + * + * Outputs a noindex,noarchive meta tag that tells web robots not to index or cache the page content. + * Outputs a referrer origin-when-cross-origin meta tag that tells the browser not to send the full + * url as a referrer to other sites when cross-origin assets are loaded. + * + * Typical usage is as a wp_head callback. add_action( 'wp_head', 'wp_sensitive_page_meta' ); + * + * @since 5.0.1 + */ +function wp_sensitive_page_meta() { + ?> + + + $urls ) { $unique_urls = array(); @@ -2937,7 +3107,7 @@ } } - $atts['rel'] = $relation_type; + $atts['rel'] = $relation_type; $atts['href'] = $url; $unique_urls[ $url ] = $atts; @@ -2948,8 +3118,8 @@ foreach ( $atts as $attr => $value ) { if ( ! is_scalar( $value ) || - ( ! in_array( $attr, array( 'as', 'crossorigin', 'href', 'pr', 'rel', 'type' ), true ) && ! is_numeric( $attr )) - ) { + ( ! in_array( $attr, array( 'as', 'crossorigin', 'href', 'pr', 'rel', 'type' ), true ) && ! is_numeric( $attr ) ) ) { + continue; } @@ -3022,7 +3192,7 @@ function user_can_richedit() { global $wp_rich_edit, $is_gecko, $is_opera, $is_safari, $is_chrome, $is_IE, $is_edge; - if ( !isset($wp_rich_edit) ) { + if ( ! isset( $wp_rich_edit ) ) { $wp_rich_edit = false; if ( get_user_option( 'rich_editing' ) == 'true' || ! is_user_logged_in() ) { // default to 'true' for logged out users @@ -3030,7 +3200,7 @@ $wp_rich_edit = ! wp_is_mobile() || ( preg_match( '!AppleWebKit/(\d+)!', $_SERVER['HTTP_USER_AGENT'], $match ) && intval( $match[1] ) >= 534 ); } elseif ( $is_IE ) { $wp_rich_edit = ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Trident/7.0;' ) !== false ); - } elseif ( $is_gecko || $is_chrome || $is_edge || ( $is_opera && !wp_is_mobile() ) ) { + } elseif ( $is_gecko || $is_chrome || $is_edge || ( $is_opera && ! wp_is_mobile() ) ) { $wp_rich_edit = true; } } @@ -3059,8 +3229,8 @@ function wp_default_editor() { $r = user_can_richedit() ? 'tinymce' : 'html'; // defaults if ( wp_get_current_user() ) { // look for cookie - $ed = get_user_setting('editor', 'tinymce'); - $r = ( in_array($ed, array('tinymce', 'html', 'test') ) ) ? $ed : $r; + $ed = get_user_setting( 'editor', 'tinymce' ); + $r = ( in_array( $ed, array( 'tinymce', 'html', 'test' ) ) ) ? $ed : $r; } /** @@ -3093,9 +3263,10 @@ * @param array $settings See _WP_Editors::editor(). */ function wp_editor( $content, $editor_id, $settings = array() ) { - if ( ! class_exists( '_WP_Editors', false ) ) + if ( ! class_exists( '_WP_Editors', false ) ) { require( ABSPATH . WPINC . '/class-wp-editor.php' ); - _WP_Editors::editor($content, $editor_id, $settings); + } + _WP_Editors::editor( $content, $editor_id, $settings ); } /** @@ -3121,7 +3292,9 @@ * @since 4.9.0 * * @see wp_enqueue_editor() + * @see wp_get_code_editor_settings(); * @see _WP_Editors::parse_settings() + * * @param array $args { * Args. * @@ -3134,81 +3307,168 @@ * @type array $jshint JSHint rule overrides. * @type array $htmlhint JSHint rule overrides. * } - * @returns array|false Settings for the enqueued code editor, or false if the editor was not enqueued . + * @return array|false Settings for the enqueued code editor, or false if the editor was not enqueued. */ function wp_enqueue_code_editor( $args ) { if ( is_user_logged_in() && 'false' === wp_get_current_user()->syntax_highlighting ) { return false; } + $settings = wp_get_code_editor_settings( $args ); + + if ( empty( $settings ) || empty( $settings['codemirror'] ) ) { + return false; + } + + wp_enqueue_script( 'code-editor' ); + wp_enqueue_style( 'code-editor' ); + + if ( isset( $settings['codemirror']['mode'] ) ) { + $mode = $settings['codemirror']['mode']; + if ( is_string( $mode ) ) { + $mode = array( + 'name' => $mode, + ); + } + + if ( ! empty( $settings['codemirror']['lint'] ) ) { + switch ( $mode['name'] ) { + case 'css': + case 'text/css': + case 'text/x-scss': + case 'text/x-less': + wp_enqueue_script( 'csslint' ); + break; + case 'htmlmixed': + case 'text/html': + case 'php': + case 'application/x-httpd-php': + case 'text/x-php': + wp_enqueue_script( 'htmlhint' ); + wp_enqueue_script( 'csslint' ); + wp_enqueue_script( 'jshint' ); + if ( ! current_user_can( 'unfiltered_html' ) ) { + wp_enqueue_script( 'htmlhint-kses' ); + } + break; + case 'javascript': + case 'application/ecmascript': + case 'application/json': + case 'application/javascript': + case 'application/ld+json': + case 'text/typescript': + case 'application/typescript': + wp_enqueue_script( 'jshint' ); + wp_enqueue_script( 'jsonlint' ); + break; + } + } + } + + wp_add_inline_script( 'code-editor', sprintf( 'jQuery.extend( wp.codeEditor.defaultSettings, %s );', wp_json_encode( $settings ) ) ); + + /** + * Fires when scripts and styles are enqueued for the code editor. + * + * @since 4.9.0 + * + * @param array $settings Settings for the enqueued code editor. + */ + do_action( 'wp_enqueue_code_editor', $settings ); + + return $settings; +} + +/** + * Generate and return code editor settings. + * + * @since 5.0.0 + * + * @see wp_enqueue_code_editor() + * + * @param array $args { + * Args. + * + * @type string $type The MIME type of the file to be edited. + * @type string $file Filename to be edited. Extension is used to sniff the type. Can be supplied as alternative to `$type` param. + * @type WP_Theme $theme Theme being edited when on theme editor. + * @type string $plugin Plugin being edited when on plugin editor. + * @type array $codemirror Additional CodeMirror setting overrides. + * @type array $csslint CSSLint rule overrides. + * @type array $jshint JSHint rule overrides. + * @type array $htmlhint JSHint rule overrides. + * } + * @return array|false Settings for the code editor. + */ +function wp_get_code_editor_settings( $args ) { $settings = array( 'codemirror' => array( - 'indentUnit' => 4, - 'indentWithTabs' => true, - 'inputStyle' => 'contenteditable', - 'lineNumbers' => true, - 'lineWrapping' => true, - 'styleActiveLine' => true, + 'indentUnit' => 4, + 'indentWithTabs' => true, + 'inputStyle' => 'contenteditable', + 'lineNumbers' => true, + 'lineWrapping' => true, + 'styleActiveLine' => true, 'continueComments' => true, - 'extraKeys' => array( + 'extraKeys' => array( 'Ctrl-Space' => 'autocomplete', - 'Ctrl-/' => 'toggleComment', - 'Cmd-/' => 'toggleComment', - 'Alt-F' => 'findPersistent', + 'Ctrl-/' => 'toggleComment', + 'Cmd-/' => 'toggleComment', + 'Alt-F' => 'findPersistent', 'Ctrl-F' => 'findPersistent', 'Cmd-F' => 'findPersistent', ), - 'direction' => 'ltr', // Code is shown in LTR even in RTL languages. - 'gutters' => array(), + 'direction' => 'ltr', // Code is shown in LTR even in RTL languages. + 'gutters' => array(), ), - 'csslint' => array( - 'errors' => true, // Parsing errors. - 'box-model' => true, + 'csslint' => array( + 'errors' => true, // Parsing errors. + 'box-model' => true, 'display-property-grouping' => true, - 'duplicate-properties' => true, - 'known-properties' => true, - 'outline-none' => true, + 'duplicate-properties' => true, + 'known-properties' => true, + 'outline-none' => true, ), - 'jshint' => array( + 'jshint' => array( // The following are copied from . - 'boss' => true, - 'curly' => true, - 'eqeqeq' => true, - 'eqnull' => true, - 'es3' => true, - 'expr' => true, - 'immed' => true, - 'noarg' => true, - 'nonbsp' => true, - 'onevar' => true, + 'boss' => true, + 'curly' => true, + 'eqeqeq' => true, + 'eqnull' => true, + 'es3' => true, + 'expr' => true, + 'immed' => true, + 'noarg' => true, + 'nonbsp' => true, + 'onevar' => true, 'quotmark' => 'single', 'trailing' => true, - 'undef' => true, - 'unused' => true, - - 'browser' => true, - - 'globals' => array( - '_' => false, + 'undef' => true, + 'unused' => true, + + 'browser' => true, + + 'globals' => array( + '_' => false, 'Backbone' => false, - 'jQuery' => false, - 'JSON' => false, - 'wp' => false, + 'jQuery' => false, + 'JSON' => false, + 'wp' => false, ), ), - 'htmlhint' => array( - 'tagname-lowercase' => true, - 'attr-lowercase' => true, + 'htmlhint' => array( + 'tagname-lowercase' => true, + 'attr-lowercase' => true, 'attr-value-double-quotes' => false, - 'doctype-first' => false, - 'tag-pair' => true, - 'spec-char-escape' => true, - 'id-unique' => true, - 'src-not-empty' => true, - 'attr-no-duplication' => true, - 'alt-require' => true, + 'doctype-first' => false, + 'tag-pair' => true, + 'spec-char-escape' => true, + 'id-unique' => true, + 'src-not-empty' => true, + 'attr-no-duplication' => true, + 'alt-require' => true, 'space-tab-mixed-disabled' => 'tab', - 'attr-unsafe-chars' => true, + 'attr-unsafe-chars' => true, ), ); @@ -3305,107 +3565,149 @@ } if ( 'text/css' === $type ) { - $settings['codemirror'] = array_merge( $settings['codemirror'], array( - 'mode' => 'css', - 'lint' => true, - 'autoCloseBrackets' => true, - 'matchBrackets' => true, - ) ); + $settings['codemirror'] = array_merge( + $settings['codemirror'], + array( + 'mode' => 'css', + 'lint' => true, + 'autoCloseBrackets' => true, + 'matchBrackets' => true, + ) + ); } elseif ( 'text/x-scss' === $type || 'text/x-less' === $type || 'text/x-sass' === $type ) { - $settings['codemirror'] = array_merge( $settings['codemirror'], array( - 'mode' => $type, - 'lint' => false, - 'autoCloseBrackets' => true, - 'matchBrackets' => true, - ) ); + $settings['codemirror'] = array_merge( + $settings['codemirror'], + array( + 'mode' => $type, + 'lint' => false, + 'autoCloseBrackets' => true, + 'matchBrackets' => true, + ) + ); } elseif ( 'text/x-diff' === $type ) { - $settings['codemirror'] = array_merge( $settings['codemirror'], array( - 'mode' => 'diff', - ) ); + $settings['codemirror'] = array_merge( + $settings['codemirror'], + array( + 'mode' => 'diff', + ) + ); } elseif ( 'text/html' === $type ) { - $settings['codemirror'] = array_merge( $settings['codemirror'], array( - 'mode' => 'htmlmixed', - 'lint' => true, - 'autoCloseBrackets' => true, - 'autoCloseTags' => true, - 'matchTags' => array( - 'bothTags' => true, - ), - ) ); + $settings['codemirror'] = array_merge( + $settings['codemirror'], + array( + 'mode' => 'htmlmixed', + 'lint' => true, + 'autoCloseBrackets' => true, + 'autoCloseTags' => true, + 'matchTags' => array( + 'bothTags' => true, + ), + ) + ); if ( ! current_user_can( 'unfiltered_html' ) ) { $settings['htmlhint']['kses'] = wp_kses_allowed_html( 'post' ); } } elseif ( 'text/x-gfm' === $type ) { - $settings['codemirror'] = array_merge( $settings['codemirror'], array( - 'mode' => 'gfm', - 'highlightFormatting' => true, - ) ); + $settings['codemirror'] = array_merge( + $settings['codemirror'], + array( + 'mode' => 'gfm', + 'highlightFormatting' => true, + ) + ); } elseif ( 'application/javascript' === $type || 'text/javascript' === $type ) { - $settings['codemirror'] = array_merge( $settings['codemirror'], array( - 'mode' => 'javascript', - 'lint' => true, - 'autoCloseBrackets' => true, - 'matchBrackets' => true, - ) ); + $settings['codemirror'] = array_merge( + $settings['codemirror'], + array( + 'mode' => 'javascript', + 'lint' => true, + 'autoCloseBrackets' => true, + 'matchBrackets' => true, + ) + ); } elseif ( false !== strpos( $type, 'json' ) ) { - $settings['codemirror'] = array_merge( $settings['codemirror'], array( - 'mode' => array( - 'name' => 'javascript', - ), - 'lint' => true, - 'autoCloseBrackets' => true, - 'matchBrackets' => true, - ) ); + $settings['codemirror'] = array_merge( + $settings['codemirror'], + array( + 'mode' => array( + 'name' => 'javascript', + ), + 'lint' => true, + 'autoCloseBrackets' => true, + 'matchBrackets' => true, + ) + ); if ( 'application/ld+json' === $type ) { $settings['codemirror']['mode']['jsonld'] = true; } else { $settings['codemirror']['mode']['json'] = true; } } elseif ( false !== strpos( $type, 'jsx' ) ) { - $settings['codemirror'] = array_merge( $settings['codemirror'], array( - 'mode' => 'jsx', - 'autoCloseBrackets' => true, - 'matchBrackets' => true, - ) ); + $settings['codemirror'] = array_merge( + $settings['codemirror'], + array( + 'mode' => 'jsx', + 'autoCloseBrackets' => true, + 'matchBrackets' => true, + ) + ); } elseif ( 'text/x-markdown' === $type ) { - $settings['codemirror'] = array_merge( $settings['codemirror'], array( - 'mode' => 'markdown', - 'highlightFormatting' => true, - ) ); + $settings['codemirror'] = array_merge( + $settings['codemirror'], + array( + 'mode' => 'markdown', + 'highlightFormatting' => true, + ) + ); } elseif ( 'text/nginx' === $type ) { - $settings['codemirror'] = array_merge( $settings['codemirror'], array( - 'mode' => 'nginx', - ) ); + $settings['codemirror'] = array_merge( + $settings['codemirror'], + array( + 'mode' => 'nginx', + ) + ); } elseif ( 'application/x-httpd-php' === $type ) { - $settings['codemirror'] = array_merge( $settings['codemirror'], array( - 'mode' => 'php', - 'autoCloseBrackets' => true, - 'autoCloseTags' => true, - 'matchBrackets' => true, - 'matchTags' => array( - 'bothTags' => true, - ), - ) ); + $settings['codemirror'] = array_merge( + $settings['codemirror'], + array( + 'mode' => 'php', + 'autoCloseBrackets' => true, + 'autoCloseTags' => true, + 'matchBrackets' => true, + 'matchTags' => array( + 'bothTags' => true, + ), + ) + ); } elseif ( 'text/x-sql' === $type || 'text/x-mysql' === $type ) { - $settings['codemirror'] = array_merge( $settings['codemirror'], array( - 'mode' => 'sql', - 'autoCloseBrackets' => true, - 'matchBrackets' => true, - ) ); + $settings['codemirror'] = array_merge( + $settings['codemirror'], + array( + 'mode' => 'sql', + 'autoCloseBrackets' => true, + 'matchBrackets' => true, + ) + ); } elseif ( false !== strpos( $type, 'xml' ) ) { - $settings['codemirror'] = array_merge( $settings['codemirror'], array( - 'mode' => 'xml', - 'autoCloseBrackets' => true, - 'autoCloseTags' => true, - 'matchTags' => array( - 'bothTags' => true, - ), - ) ); + $settings['codemirror'] = array_merge( + $settings['codemirror'], + array( + 'mode' => 'xml', + 'autoCloseBrackets' => true, + 'autoCloseTags' => true, + 'matchTags' => array( + 'bothTags' => true, + ), + ) + ); } elseif ( 'text/x-yaml' === $type ) { - $settings['codemirror'] = array_merge( $settings['codemirror'], array( - 'mode' => 'yaml', - ) ); + $settings['codemirror'] = array_merge( + $settings['codemirror'], + array( + 'mode' => 'yaml', + ) + ); } else { $settings['codemirror']['mode'] = $type; } @@ -3431,7 +3733,7 @@ * * @param array $settings The array of settings passed to the code editor. A falsey value disables the editor. * @param array $args { - * Args passed when calling `wp_enqueue_code_editor()`. + * Args passed when calling `get_code_editor_settings()`. * * @type string $type The MIME type of the file to be edited. * @type string $file Filename being edited. @@ -3443,69 +3745,7 @@ * @type array $htmlhint JSHint rule overrides. * } */ - $settings = apply_filters( 'wp_code_editor_settings', $settings, $args ); - - if ( empty( $settings ) || empty( $settings['codemirror'] ) ) { - return false; - } - - wp_enqueue_script( 'code-editor' ); - wp_enqueue_style( 'code-editor' ); - - if ( isset( $settings['codemirror']['mode'] ) ) { - $mode = $settings['codemirror']['mode']; - if ( is_string( $mode ) ) { - $mode = array( - 'name' => $mode, - ); - } - - if ( ! empty( $settings['codemirror']['lint'] ) ) { - switch ( $mode['name'] ) { - case 'css': - case 'text/css': - case 'text/x-scss': - case 'text/x-less': - wp_enqueue_script( 'csslint' ); - break; - case 'htmlmixed': - case 'text/html': - case 'php': - case 'application/x-httpd-php': - case 'text/x-php': - wp_enqueue_script( 'htmlhint' ); - wp_enqueue_script( 'csslint' ); - wp_enqueue_script( 'jshint' ); - if ( ! current_user_can( 'unfiltered_html' ) ) { - wp_enqueue_script( 'htmlhint-kses' ); - } - break; - case 'javascript': - case 'application/ecmascript': - case 'application/json': - case 'application/javascript': - case 'application/ld+json': - case 'text/typescript': - case 'application/typescript': - wp_enqueue_script( 'jshint' ); - wp_enqueue_script( 'jsonlint' ); - break; - } - } - } - - wp_add_inline_script( 'code-editor', sprintf( 'jQuery.extend( wp.codeEditor.defaultSettings, %s );', wp_json_encode( $settings ) ) ); - - /** - * Fires when scripts and styles are enqueued for the code editor. - * - * @since 4.9.0 - * - * @param array $settings Settings for the enqueued code editor. - */ - do_action( 'wp_enqueue_code_editor', $settings ); - - return $settings; + return apply_filters( 'wp_code_editor_settings', $settings, $args ); } /** @@ -3517,7 +3757,7 @@ * @since 2.3.0 * * @param bool $escaped Whether the result is escaped. Default true. - * Only use when you are later escaping it. Do not use unescaped. + * Only use when you are later escaping it. Do not use unescaped. * @return string */ function get_search_query( $escaped = true ) { @@ -3530,8 +3770,9 @@ */ $query = apply_filters( 'get_search_query', get_query_var( 's' ) ); - if ( $escaped ) + if ( $escaped ) { $query = esc_attr( $query ); + } return $query; } @@ -3567,8 +3808,9 @@ function get_language_attributes( $doctype = 'html' ) { $attributes = array(); - if ( function_exists( 'is_rtl' ) && is_rtl() ) + if ( function_exists( 'is_rtl' ) && is_rtl() ) { $attributes[] = 'dir="rtl"'; + } if ( $lang = get_bloginfo( 'language' ) ) { if ( get_option( 'html_type' ) == 'text/html' || $doctype == 'html' ) { @@ -3580,7 +3822,7 @@ } } - $output = implode(' ', $attributes); + $output = implode( ' ', $attributes ); /** * Filters the language attributes for display in the html tag. @@ -3685,7 +3927,7 @@ * @type string $before_page_number A string to appear before the page number. Default empty. * @type string $after_page_number A string to append after the page number. Default empty. * } - * @return array|string|void String of page links or array of page links. + * @return string|array|void String of page links or array of page links. */ function paginate_links( $args = '' ) { global $wp_query, $wp_rewrite; @@ -3733,7 +3975,7 @@ // Merge additional query vars found in the original URL into 'add_args' array. if ( isset( $url_parts[1] ) ) { // Find the format argument. - $format = explode( '?', str_replace( '%_%', $args['format'], $args['base'] ) ); + $format = explode( '?', str_replace( '%_%', $args['format'], $args['base'] ) ); $format_query = isset( $format[1] ) ? $format[1] : ''; wp_parse_str( $format_query, $format_args ); @@ -3762,16 +4004,17 @@ if ( $mid_size < 0 ) { $mid_size = 2; } - $add_args = $args['add_args']; - $r = ''; + $add_args = $args['add_args']; + $r = ''; $page_links = array(); - $dots = false; + $dots = false; if ( $args['prev_next'] && $current && 1 < $current ) : $link = str_replace( '%_%', 2 == $current ? '' : $args['format'], $args['base'] ); $link = str_replace( '%#%', $current - 1, $link ); - if ( $add_args ) + if ( $add_args ) { $link = add_query_arg( $add_args, $link ); + } $link .= $args['add_fragment']; /** @@ -3785,56 +4028,58 @@ endif; for ( $n = 1; $n <= $total; $n++ ) : if ( $n == $current ) : - $page_links[] = "" . $args['before_page_number'] . number_format_i18n( $n ) . $args['after_page_number'] . ""; - $dots = true; + $page_links[] = "" . $args['before_page_number'] . number_format_i18n( $n ) . $args['after_page_number'] . ''; + $dots = true; else : if ( $args['show_all'] || ( $n <= $end_size || ( $current && $n >= $current - $mid_size && $n <= $current + $mid_size ) || $n > $total - $end_size ) ) : $link = str_replace( '%_%', 1 == $n ? '' : $args['format'], $args['base'] ); $link = str_replace( '%#%', $n, $link ); - if ( $add_args ) + if ( $add_args ) { $link = add_query_arg( $add_args, $link ); + } $link .= $args['add_fragment']; /** This filter is documented in wp-includes/general-template.php */ - $page_links[] = "" . $args['before_page_number'] . number_format_i18n( $n ) . $args['after_page_number'] . ""; - $dots = true; + $page_links[] = "" . $args['before_page_number'] . number_format_i18n( $n ) . $args['after_page_number'] . ''; + $dots = true; elseif ( $dots && ! $args['show_all'] ) : $page_links[] = '' . __( '…' ) . ''; - $dots = false; + $dots = false; endif; endif; endfor; if ( $args['prev_next'] && $current && $current < $total ) : $link = str_replace( '%_%', $args['format'], $args['base'] ); $link = str_replace( '%#%', $current + 1, $link ); - if ( $add_args ) + if ( $add_args ) { $link = add_query_arg( $add_args, $link ); + } $link .= $args['add_fragment']; /** This filter is documented in wp-includes/general-template.php */ $page_links[] = ''; endif; switch ( $args['type'] ) { - case 'array' : + case 'array': return $page_links; - case 'list' : + case 'list': $r .= "\n"; break; - default : - $r = join("\n", $page_links); + default: + $r = join( "\n", $page_links ); break; } return $r; } /** - * Registers an admin colour scheme css file. - * - * Allows a plugin to register a new admin colour scheme. For example: + * Registers an admin color scheme css file. + * + * Allows a plugin to register a new admin color scheme. For example: * * wp_admin_css_color( 'classic', __( 'Classic' ), admin_url( "css/colors-classic.css" ), array( * '#07273E', '#14568A', '#D54E21', '#2683AE' @@ -3860,30 +4105,42 @@ function wp_admin_css_color( $key, $name, $url, $colors = array(), $icons = array() ) { global $_wp_admin_css_colors; - if ( !isset($_wp_admin_css_colors) ) + if ( ! isset( $_wp_admin_css_colors ) ) { $_wp_admin_css_colors = array(); - - $_wp_admin_css_colors[$key] = (object) array( - 'name' => $name, - 'url' => $url, - 'colors' => $colors, + } + + $_wp_admin_css_colors[ $key ] = (object) array( + 'name' => $name, + 'url' => $url, + 'colors' => $colors, 'icon_colors' => $icons, ); } /** - * Registers the default Admin color schemes + * Registers the default admin color schemes. + * + * Registers the initial set of eight color schemes in the Profile section + * of the dashboard which allows for styling the admin menu and toolbar. + * + * @see wp_admin_css_color() * * @since 3.0.0 */ function register_admin_color_schemes() { - $suffix = is_rtl() ? '-rtl' : ''; + $suffix = is_rtl() ? '-rtl' : ''; $suffix .= SCRIPT_DEBUG ? '' : '.min'; - wp_admin_css_color( 'fresh', _x( 'Default', 'admin color scheme' ), + wp_admin_css_color( + 'fresh', + _x( 'Default', 'admin color scheme' ), false, array( '#222', '#333', '#0073aa', '#00a0d2' ), - array( 'base' => '#82878c', 'focus' => '#00a0d2', 'current' => '#fff' ) + array( + 'base' => '#a0a5aa', + 'focus' => '#00a0d2', + 'current' => '#fff', + ) ); // Other color schemes are not available when running out of src @@ -3891,46 +4148,88 @@ return; } - wp_admin_css_color( 'light', _x( 'Light', 'admin color scheme' ), + wp_admin_css_color( + 'light', + _x( 'Light', 'admin color scheme' ), admin_url( "css/colors/light/colors$suffix.css" ), array( '#e5e5e5', '#999', '#d64e07', '#04a4cc' ), - array( 'base' => '#999', 'focus' => '#ccc', 'current' => '#ccc' ) + array( + 'base' => '#999', + 'focus' => '#ccc', + 'current' => '#ccc', + ) ); - wp_admin_css_color( 'blue', _x( 'Blue', 'admin color scheme' ), + wp_admin_css_color( + 'blue', + _x( 'Blue', 'admin color scheme' ), admin_url( "css/colors/blue/colors$suffix.css" ), array( '#096484', '#4796b3', '#52accc', '#74B6CE' ), - array( 'base' => '#e5f8ff', 'focus' => '#fff', 'current' => '#fff' ) + array( + 'base' => '#e5f8ff', + 'focus' => '#fff', + 'current' => '#fff', + ) ); - wp_admin_css_color( 'midnight', _x( 'Midnight', 'admin color scheme' ), + wp_admin_css_color( + 'midnight', + _x( 'Midnight', 'admin color scheme' ), admin_url( "css/colors/midnight/colors$suffix.css" ), array( '#25282b', '#363b3f', '#69a8bb', '#e14d43' ), - array( 'base' => '#f1f2f3', 'focus' => '#fff', 'current' => '#fff' ) + array( + 'base' => '#f1f2f3', + 'focus' => '#fff', + 'current' => '#fff', + ) ); - wp_admin_css_color( 'sunrise', _x( 'Sunrise', 'admin color scheme' ), + wp_admin_css_color( + 'sunrise', + _x( 'Sunrise', 'admin color scheme' ), admin_url( "css/colors/sunrise/colors$suffix.css" ), array( '#b43c38', '#cf4944', '#dd823b', '#ccaf0b' ), - array( 'base' => '#f3f1f1', 'focus' => '#fff', 'current' => '#fff' ) + array( + 'base' => '#f3f1f1', + 'focus' => '#fff', + 'current' => '#fff', + ) ); - wp_admin_css_color( 'ectoplasm', _x( 'Ectoplasm', 'admin color scheme' ), + wp_admin_css_color( + 'ectoplasm', + _x( 'Ectoplasm', 'admin color scheme' ), admin_url( "css/colors/ectoplasm/colors$suffix.css" ), array( '#413256', '#523f6d', '#a3b745', '#d46f15' ), - array( 'base' => '#ece6f6', 'focus' => '#fff', 'current' => '#fff' ) + array( + 'base' => '#ece6f6', + 'focus' => '#fff', + 'current' => '#fff', + ) ); - wp_admin_css_color( 'ocean', _x( 'Ocean', 'admin color scheme' ), + wp_admin_css_color( + 'ocean', + _x( 'Ocean', 'admin color scheme' ), admin_url( "css/colors/ocean/colors$suffix.css" ), array( '#627c83', '#738e96', '#9ebaa0', '#aa9d88' ), - array( 'base' => '#f2fcff', 'focus' => '#fff', 'current' => '#fff' ) + array( + 'base' => '#f2fcff', + 'focus' => '#fff', + 'current' => '#fff', + ) ); - wp_admin_css_color( 'coffee', _x( 'Coffee', 'admin color scheme' ), + wp_admin_css_color( + 'coffee', + _x( 'Coffee', 'admin color scheme' ), admin_url( "css/colors/coffee/colors$suffix.css" ), array( '#46403c', '#59524c', '#c7a589', '#9ea476' ), - array( 'base' => '#f3f2f1', 'focus' => '#fff', 'current' => '#fff' ) + array( + 'base' => '#f3f2f1', + 'focus' => '#fff', + 'current' => '#fff', + ) ); } @@ -3946,12 +4245,12 @@ * @return string */ function wp_admin_css_uri( $file = 'wp-admin' ) { - if ( defined('WP_INSTALLING') ) { + if ( defined( 'WP_INSTALLING' ) ) { $_file = "./$file.css"; } else { - $_file = admin_url("$file.css"); + $_file = admin_url( "$file.css" ); } - $_file = add_query_arg( 'version', get_bloginfo( 'version' ), $_file ); + $_file = add_query_arg( 'version', get_bloginfo( 'version' ), $_file ); /** * Filters the URI of a WordPress admin CSS file. @@ -3981,7 +4280,7 @@ * @since 2.3.0 * * @param string $file Optional. Style handle name or file name (without ".css" extension) relative - * to wp-admin/. Defaults to 'wp-admin'. + * to wp-admin/. Defaults to 'wp-admin'. * @param bool $force_echo Optional. Force the stylesheet link to be printed rather than enqueued. */ function wp_admin_css( $file = 'wp-admin', $force_echo = false ) { @@ -3989,10 +4288,11 @@ $handle = 0 === strpos( $file, 'css/' ) ? substr( $file, 4 ) : $file; if ( wp_styles()->query( $handle ) ) { - if ( $force_echo || did_action( 'wp_print_styles' ) ) // we already printed the style queue. Print this one immediately + if ( $force_echo || did_action( 'wp_print_styles' ) ) { // we already printed the style queue. Print this one immediately wp_print_styles( $handle ); - else // Add to style queue + } else { // Add to style queue wp_enqueue_style( $handle ); + } return; } @@ -4028,8 +4328,9 @@ wp_enqueue_script( 'thickbox' ); wp_enqueue_style( 'thickbox' ); - if ( is_network_admin() ) + if ( is_network_admin() ) { add_action( 'admin_head', '_thickbox_path_admin_subfolder' ); + } } /** @@ -4070,7 +4371,7 @@ * @param string $type The type of generator to output. Accepts 'html', * 'xhtml', 'atom', 'rss2', 'rdf', 'comment', 'export'. */ - echo apply_filters( 'the_generator', get_the_generator($type), $type ) . "\n"; + echo apply_filters( 'the_generator', get_the_generator( $type ), $type ) . "\n"; } /** @@ -4089,24 +4390,25 @@ if ( empty( $type ) ) { $current_filter = current_filter(); - if ( empty( $current_filter ) ) + if ( empty( $current_filter ) ) { return; + } switch ( $current_filter ) { - case 'rss2_head' : - case 'commentsrss2_head' : + case 'rss2_head': + case 'commentsrss2_head': $type = 'rss2'; break; - case 'rss_head' : - case 'opml_head' : + case 'rss_head': + case 'opml_head': $type = 'comment'; break; - case 'rdf_header' : + case 'rdf_header': $type = 'rdf'; break; - case 'atom_head' : - case 'comments_atom_head' : - case 'app_head' : + case 'atom_head': + case 'comments_atom_head': + case 'app_head': $type = 'atom'; break; } @@ -4229,13 +4531,15 @@ * @return string html attribute or empty string */ function __checked_selected_helper( $helper, $current, $echo, $type ) { - if ( (string) $helper === (string) $current ) + if ( (string) $helper === (string) $current ) { $result = " $type='$type'"; - else + } else { $result = ''; - - if ( $echo ) + } + + if ( $echo ) { echo $result; + } return $result; } @@ -4251,11 +4555,13 @@ * @return array $settings */ function wp_heartbeat_settings( $settings ) { - if ( ! is_admin() ) + if ( ! is_admin() ) { $settings['ajaxurl'] = admin_url( 'admin-ajax.php', 'relative' ); - - if ( is_user_logged_in() ) + } + + if ( is_user_logged_in() ) { $settings['nonce'] = wp_create_nonce( 'heartbeat-nonce' ); + } return $settings; }