esource hints. * @param string $relation_type The relation type the URLs are printed for, e.g. 'preconnect' or 'prerender'. */ $urls = apply_filters( 'wp_resource_hints', $urls, $relation_type ); foreach ( $urls as $key => $url ) { $atts = array(); if ( is_array( $url ) ) { if ( isset( $url['href'] ) ) { $atts = $url; $url = $url['href']; } else { continue; } } $url = esc_url( $url, array( 'http', 'https' ) ); if ( ! $url ) { continue; } if ( isset( $unique_urls[ $url ] ) ) { continue; } if ( in_array( $relation_type, array( 'preconnect', 'dns-prefetch' ) ) ) { $parsed = wp_parse_url( $url ); if ( empty( $parsed['host'] ) ) { continue; } if ( 'preconnect' === $relation_type && ! empty( $parsed['scheme'] ) ) { $url = $parsed['scheme'] . '://' . $parsed['host']; } else { // Use protocol-relative URLs for dns-prefetch or if scheme is missing. $url = '//' . $parsed['host']; } } $atts['rel'] = $relation_type; $atts['href'] = $url; $unique_urls[ $url ] = $atts; } foreach ( $unique_urls as $atts ) { $html = ''; foreach ( $atts as $attr => $value ) { if ( ! is_scalar( $value ) || ( ! in_array( $attr, array( 'as', 'crossorigin', 'href', 'pr', 'rel', 'type' ), true ) && ! is_numeric( $attr )) ) { continue; } $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value ); if ( ! is_string( $attr ) ) { $html .= " $value"; } else { $html .= " $attr='$value'"; } } $html = trim( $html ); echo "\n"; } } } /** * Retrieves a list of unique hosts of all enqueued scripts and styles. * * @since 4.6.0 * * @return array A list of unique hosts of enqueued scripts and styles. */ function wp_dependencies_unique_hosts() { global $wp_scripts, $wp_styles; $unique_hosts = array(); foreach ( array( $wp_scripts, $wp_styles ) as $dependencies ) { if ( $dependencies instanceof WP_Dependencies && ! empty( $dependencies->queue ) ) { foreach ( $dependencies->queue as $handle ) { if ( ! isset( $dependencies->registered[ $handle ] ) ) { continue; } /* @var _WP_Dependency $dependency */ $dependency = $dependencies->registered[ $handle ]; $parsed = wp_parse_url( $dependency->src ); if ( ! empty( $parsed['host'] ) && ! in_array( $parsed['host'], $unique_hosts ) && $parsed['host'] !== $_SERVER['SERVER_NAME'] ) { $unique_hosts[] = $parsed['host']; } } } } return $unique_hosts; } /** * Whether the user can access the visual editor. * * Checks if the user can access the visual editor and that it's supported by the user's browser. * * @since 2.0.0 * * @global bool $wp_rich_edit Whether the user can access the visual editor. * @global bool $is_gecko Whether the browser is Gecko-based. * @global bool $is_opera Whether the browser is Opera. * @global bool $is_safari Whether the browser is Safari. * @global bool $is_chrome Whether the browser is Chrome. * @global bool $is_IE Whether the browser is Internet Explorer. * @global bool $is_edge Whether the browser is Microsoft Edge. * * @return bool True if the user can access the visual editor, false otherwise. */ 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) ) { $wp_rich_edit = false; if ( get_user_option( 'rich_editing' ) == 'true' || ! is_user_logged_in() ) { // default to 'true' for logged out users if ( $is_safari ) { $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'], 'MSIE ' ) === false ); } elseif ( $is_gecko || $is_chrome || $is_edge || ( $is_opera && !wp_is_mobile() ) ) { $wp_rich_edit = true; } } } /** * Filters whether the user can access the visual editor. * * @since 2.1.0 * * @param bool $wp_rich_edit Whether the user can access the visual editor. */ return apply_filters( 'user_can_richedit', $wp_rich_edit ); } /** * Find out which editor should be displayed by default. * * Works out which of the two editors to display as the current editor for a * user. The 'html' setting is for the "Text" editor tab. * * @since 2.5.0 * * @return string Either 'tinymce', or 'html', or 'test' */ 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; } /** * Filters which editor should be displayed by default. * * @since 2.5.0 * * @param string $r Which editor should be displayed by default. Either 'tinymce', 'html', or 'test'. */ return apply_filters( 'wp_default_editor', $r ); } /** * Renders an editor. * * Using this function is the proper way to output all needed components for both TinyMCE and Quicktags. * _WP_Editors should not be used directly. See https://core.trac.wordpress.org/ticket/17144. * * NOTE: Once initialized the TinyMCE editor cannot be safely moved in the DOM. For that reason * running wp_editor() inside of a meta box is not a good idea unless only Quicktags is used. * On the post edit screen several actions can be used to include additional editors * containing TinyMCE: 'edit_page_form', 'edit_form_advanced' and 'dbx_post_sidebar'. * See https://core.trac.wordpress.org/ticket/19173 for more information. * * @see _WP_Editors::editor() * @since 3.3.0 * * @param string $content Initial content for the editor. * @param string $editor_id HTML ID attribute value for the textarea and TinyMCE. Can only be /[a-z]+/. * @param array $settings See _WP_Editors::editor(). */ function wp_editor( $content, $editor_id, $settings = array() ) { if ( ! class_exists( '_WP_Editors', false ) ) require( ABSPATH . WPINC . '/class-wp-editor.php' ); _WP_Editors::editor($content, $editor_id, $settings); } /** * Outputs the editor scripts, stylesheets, and default settings. * * The editor can be initialized when needed after page load. * See wp.editor.initialize() in wp-admin/js/editor.js for initialization options. * * @uses _WP_Editors * @since 4.8.0 */ function wp_enqueue_editor() { if ( ! class_exists( '_WP_Editors', false ) ) { require( ABSPATH . WPINC . '/class-wp-editor.php' ); } _WP_Editors::enqueue_default_editor(); } /** * Retrieves the contents of the search WordPress query variable. * * The search query string is passed through esc_attr() to ensure that it is safe * for placing in an html attribute. * * @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. * @return string */ function get_search_query( $escaped = true ) { /** * Filters the contents of the search query variable. * * @since 2.3.0 * * @param mixed $search Contents of the search query variable. */ $query = apply_filters( 'get_search_query', get_query_var( 's' ) ); if ( $escaped ) $query = esc_attr( $query ); return $query; } /** * Displays the contents of the search query variable. * * The search query string is passed through esc_attr() to ensure that it is safe * for placing in an html attribute. * * @since 2.1.0 */ function the_search_query() { /** * Filters the contents of the search query variable for display. * * @since 2.3.0 * * @param mixed $search Contents of the search query variable. */ echo esc_attr( apply_filters( 'the_search_query', get_search_query( false ) ) ); } /** * Gets the language attributes for the html tag. * * Builds up a set of html attributes containing the text direction and language * information for the page. * * @since 4.3.0 * * @param string $doctype Optional. The type of html document. Accepts 'xhtml' or 'html'. Default 'html'. */ function get_language_attributes( $doctype = 'html' ) { $attributes = array(); if ( function_exists( 'is_rtl' ) && is_rtl() ) $attributes[] = 'dir="rtl"'; if ( $lang = get_bloginfo( 'language' ) ) { if ( get_option( 'html_type' ) == 'text/html' || $doctype == 'html' ) { $attributes[] = 'lang="' . esc_attr( $lang ) . '"'; } if ( get_option( 'html_type' ) != 'text/html' || $doctype == 'xhtml' ) { $attributes[] = 'xml:lang="' . esc_attr( $lang ) . '"'; } } $output = implode(' ', $attributes); /** * Filters the language attributes for display in the html tag. * * @since 2.5.0 * @since 4.3.0 Added the `$doctype` parameter. * * @param string $output A space-separated list of language attributes. * @param string $doctype The type of html document (xhtml|html). */ return apply_filters( 'language_attributes', $output, $doctype ); } /** * Displays the language attributes for the html tag. * * Builds up a set of html attributes containing the text direction and language * information for the page. * * @since 2.1.0 * @since 4.3.0 Converted into a wrapper for get_language_attributes(). * * @param string $doctype Optional. The type of html document. Accepts 'xhtml' or 'html'. Default 'html'. */ function language_attributes( $doctype = 'html' ) { echo get_language_attributes( $doctype ); } /** * Retrieve paginated link for archive post pages. * * Technically, the function can be used to create paginated link list for any * area. The 'base' argument is used to reference the url, which will be used to * create the paginated links. The 'format' argument is then used for replacing * the page number. It is however, most likely and by default, to be used on the * archive post pages. * * The 'type' argument controls format of the returned value. The default is * 'plain', which is just a string with the links separated by a newline * character. The other possible values are either 'array' or 'list'. The * 'array' value will return an array of the paginated link list to offer full * control of display. The 'list' value will place all of the paginated links in * an unordered HTML list. * * The 'total' argument is the total amount of pages and is an integer. The * 'current' argument is the current page number and is also an integer. * * An example of the 'base' argument is "http://example.com/all_posts.php%_%" * and the '%_%' is required. The '%_%' will be replaced by the contents of in * the 'format' argument. An example for the 'format' argument is "?page=%#%" * and the '%#%' is also required. The '%#%' will be replaced with the page * number. * * You can include the previous and next links in the list by setting the * 'prev_next' argument to true, which it is by default. You can set the * previous text, by using the 'prev_text' argument. You can set the next text * by setting the 'next_text' argument. * * If the 'show_all' argument is set to true, then it will show all of the pages * instead of a short list of the pages near the current page. By default, the * 'show_all' is set to false and controlled by the 'end_size' and 'mid_size' * arguments. The 'end_size' argument is how many numbers on either the start * and the end list edges, by default is 1. The 'mid_size' argument is how many * numbers to either side of current page, but not including current page. * * It is possible to add query vars to the link by using the 'add_args' argument * and see add_query_arg() for more information. * * The 'before_page_number' and 'after_page_number' arguments allow users to * augment the links themselves. Typically this might be to add context to the * numbered links so that screen reader users understand what the links are for. * The text strings are added before and after the page number - within the * anchor tag. * * @since 2.1.0 * * @global WP_Query $wp_query * @global WP_Rewrite $wp_rewrite * * @param string|array $args { * Optional. Array or string of arguments for generating paginated links for archives. * * @type string $base Base of the paginated url. Default empty. * @type string $format Format for the pagination structure. Default empty. * @type int $total The total amount of pages. Default is the value WP_Query's * `max_num_pages` or 1. * @type int $current The current page number. Default is 'paged' query var or 1. * @type bool $show_all Whether to show all pages. Default false. * @type int $end_size How many numbers on either the start and the end list edges. * Default 1. * @type int $mid_size How many numbers to either side of the current pages. Default 2. * @type bool $prev_next Whether to include the previous and next links in the list. Default true. * @type bool $prev_text The previous page text. Default '« Previous'. * @type bool $next_text The next page text. Default 'Next »'. * @type string $type Controls format of the returned value. Possible values are 'plain', * 'array' and 'list'. Default is 'plain'. * @type array $add_args An array of query args to add. Default false. * @type string $add_fragment A string to append to each link. Default empty. * @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. */ function paginate_links( $args = '' ) { global $wp_query, $wp_rewrite; // Setting up default values based on the current URL. $pagenum_link = html_entity_decode( get_pagenum_link() ); $url_parts = explode( '?', $pagenum_link ); // Get max pages and current page out of the current query, if available. $total = isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1; $current = get_query_var( 'paged' ) ? intval( get_query_var( 'paged' ) ) : 1; // Append the format placeholder to the base URL. $pagenum_link = trailingslashit( $url_parts[0] ) . '%_%'; // URL base depends on permalink settings. $format = $wp_rewrite->using_index_permalinks() && ! strpos( $pagenum_link, 'index.php' ) ? 'index.php/' : ''; $format .= $wp_rewrite->using_permalinks() ? user_trailingslashit( $wp_rewrite->pagination_base . '/%#%', 'paged' ) : '?paged=%#%'; $defaults = array( 'base' => $pagenum_link, // http://example.com/all_posts.php%_% : %_% is replaced by format (below) 'format' => $format, // ?page=%#% : %#% is replaced by the page number 'total' => $total, 'current' => $current, 'show_all' => false, 'prev_next' => true, 'prev_text' => __('« Previous'), 'next_text' => __('Next »'), 'end_size' => 1, 'mid_size' => 2, 'type' => 'plain', 'add_args' => array(), // array of query args to add 'add_fragment' => '', 'before_page_number' => '', 'after_page_number' => '' ); $args = wp_parse_args( $args, $defaults ); if ( ! is_array( $args['add_args'] ) ) { $args['add_args'] = array(); } // 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_query = isset( $format[1] ) ? $format[1] : ''; wp_parse_str( $format_query, $format_args ); // Find the query args of the requested URL. wp_parse_str( $url_parts[1], $url_query_args ); // Remove the format argument from the array of query arguments, to avoid overwriting custom format. foreach ( $format_args as $format_arg => $format_arg_value ) { unset( $url_query_args[ $format_arg ] ); } $args['add_args'] = array_merge( $args['add_args'], urlencode_deep( $url_query_args ) ); } // Who knows what else people pass in $args $total = (int) $args['total']; if ( $total < 2 ) { return; } $current = (int) $args['current']; $end_size = (int) $args['end_size']; // Out of bounds? Make it the default. if ( $end_size < 1 ) { $end_size = 1; } $mid_size = (int) $args['mid_size']; if ( $mid_size < 0 ) { $mid_size = 2; } $add_args = $args['add_args']; $r = ''; $page_links = array(); $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 ) $link = add_query_arg( $add_args, $link ); $link .= $args['add_fragment']; /** * Filters the paginated links for the given archive pages. * * @since 3.0.0 * * @param string $link The paginated link URL. */ $page_links[] = '' . $args['prev_text'] . ''; 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; 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 ) $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; elseif ( $dots && ! $args['show_all'] ) : $page_links[] = '' . __( '…' ) . ''; $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 ) $link = add_query_arg( $add_args, $link ); $link .= $args['add_fragment']; /** This filter is documented in wp-includes/general-template.php */ $page_links[] = '' . $args['next_text'] . ''; endif; switch ( $args['type'] ) { case 'array' : return $page_links; case 'list' : $r .= "