?providers/class-wp-sitemaps-posts.php000064400000016525151202370330014021 0ustar00name = 'posts'; $this->object_type = 'post'; } /** * Returns the public post types, which excludes nav_items and similar types. * Attachments are also excluded. This includes custom post types with public = true. * * @since 5.5.0 * * @return WP_Post_Type[] Array of registered post type objects keyed by their name. */ public function get_object_subtypes() { $post_types = get_post_types( array( 'public' => true ), 'objects' ); unset( $post_types['attachment'] ); $post_types = array_filter( $post_types, 'is_post_type_viewable' ); /** * Filters the list of post object sub types available within the sitemap. * * @since 5.5.0 * * @param WP_Post_Type[] $post_types Array of registered post type objects keyed by their name. */ return apply_filters( 'wp_sitemaps_post_types', $post_types ); } /** * Gets a URL list for a post type sitemap. * * @since 5.5.0 * @since 5.9.0 Renamed `$post_type` to `$object_subtype` to match parent class * for PHP 8 named parameter support. * * @param int $page_num Page of results. * @param string $object_subtype Optional. Post type name. Default empty. * * @return array[] Array of URL information for a sitemap. */ public function get_url_list( $page_num, $object_subtype = '' ) { // Restores the more descriptive, specific name for use within this method. $post_type = $object_subtype; // Bail early if the queried post type is not supported. $supported_types = $this->get_object_subtypes(); if ( ! isset( $supported_types[ $post_type ] ) ) { return array(); } /** * Filters the posts URL list before it is generated. * * Returning a non-null value will effectively short-circuit the generation, * returning that value instead. * * @since 5.5.0 * * @param array[]|null $url_list The URL list. Default null. * @param string $post_type Post type name. * @param int $page_num Page of results. */ $url_list = apply_filters( 'wp_sitemaps_posts_pre_url_list', null, $post_type, $page_num ); if ( null !== $url_list ) { return $url_list; } $args = $this->get_posts_query_args( $post_type ); $args['paged'] = $page_num; $query = new WP_Query( $args ); $url_list = array(); /* * Add a URL for the homepage in the pages sitemap. * Shows only on the first page if the reading settings are set to display latest posts. */ if ( 'page' === $post_type && 1 === $page_num && 'posts' === get_option( 'show_on_front' ) ) { // Extract the data needed for home URL to add to the array. $sitemap_entry = array( 'loc' => home_url( '/' ), ); /* * Get the most recent posts displayed on the homepage, * and then sort them by their modified date to find * the date the homepage was approximately last updated. */ $latest_posts = new WP_Query( array( 'post_type' => 'post', 'post_status' => 'publish', 'orderby' => 'date', 'order' => 'DESC', 'no_found_rows' => true, 'update_post_meta_cache' => false, 'update_post_term_cache' => false, ) ); if ( ! empty( $latest_posts->posts ) ) { $posts = wp_list_sort( $latest_posts->posts, 'post_modified_gmt', 'DESC' ); $sitemap_entry['lastmod'] = wp_date( DATE_W3C, strtotime( $posts[0]->post_modified_gmt ) ); } /** * Filters the sitemap entry for the home page when the 'show_on_front' option equals 'posts'. * * @since 5.5.0 * * @param array $sitemap_entry Sitemap entry for the home page. */ $sitemap_entry = apply_filters( 'wp_sitemaps_posts_show_on_front_entry', $sitemap_entry ); $url_list[] = $sitemap_entry; } foreach ( $query->posts as $post ) { $sitemap_entry = array( 'loc' => get_permalink( $post ), 'lastmod' => wp_date( DATE_W3C, strtotime( $post->post_modified_gmt ) ), ); /** * Filters the sitemap entry for an individual post. * * @since 5.5.0 * * @param array $sitemap_entry Sitemap entry for the post. * @param WP_Post $post Post object. * @param string $post_type Name of the post_type. */ $sitemap_entry = apply_filters( 'wp_sitemaps_posts_entry', $sitemap_entry, $post, $post_type ); $url_list[] = $sitemap_entry; } return $url_list; } /** * Gets the max number of pages available for the object type. * * @since 5.5.0 * @since 5.9.0 Renamed `$post_type` to `$object_subtype` to match parent class * for PHP 8 named parameter support. * * @param string $object_subtype Optional. Post type name. Default empty. * @return int Total number of pages. */ public function get_max_num_pages( $object_subtype = '' ) { if ( empty( $object_subtype ) ) { return 0; } // Restores the more descriptive, specific name for use within this method. $post_type = $object_subtype; /** * Filters the max number of pages before it is generated. * * Passing a non-null value will short-circuit the generation, * returning that value instead. * * @since 5.5.0 * * @param int|null $max_num_pages The maximum number of pages. Default null. * @param string $post_type Post type name. */ $max_num_pages = apply_filters( 'wp_sitemaps_posts_pre_max_num_pages', null, $post_type ); if ( null !== $max_num_pages ) { return $max_num_pages; } $args = $this->get_posts_query_args( $post_type ); $args['fields'] = 'ids'; $args['no_found_rows'] = false; $query = new WP_Query( $args ); $min_num_pages = ( 'page' === $post_type && 'posts' === get_option( 'show_on_front' ) ) ? 1 : 0; return isset( $query->max_num_pages ) ? max( $min_num_pages, $query->max_num_pages ) : 1; } /** * Returns the query args for retrieving posts to list in the sitemap. * * @since 5.5.0 * @since 6.1.0 Added `ignore_sticky_posts` default parameter. * * @param string $post_type Post type name. * @return array Array of WP_Query arguments. */ protected function get_posts_query_args( $post_type ) { /** * Filters the query arguments for post type sitemap queries. * * @see WP_Query for a full list of arguments. * * @since 5.5.0 * @since 6.1.0 Added `ignore_sticky_posts` default parameter. * * @param array $args Array of WP_Query arguments. * @param string $post_type Post type name. */ $args = apply_filters( 'wp_sitemaps_posts_query_args', array( 'orderby' => 'ID', 'order' => 'ASC', 'post_type' => $post_type, 'posts_per_page' => wp_sitemaps_get_max_urls( $this->object_type ), 'post_status' => array( 'publish' ), 'no_found_rows' => true, 'update_post_term_cache' => false, 'update_post_meta_cache' => false, 'ignore_sticky_posts' => true, // Sticky posts will still appear, but they won't be moved to the front. ), $post_type ); return $args; } } providers/class-wp-sitemaps-taxonomies.php000064400000013421151202370330015027 0ustar00name = 'taxonomies'; $this->object_type = 'term'; } /** * Returns all public, registered taxonomies. * * @since 5.5.0 * * @return WP_Taxonomy[] Array of registered taxonomy objects keyed by their name. */ public function get_object_subtypes() { $taxonomies = get_taxonomies( array( 'public' => true ), 'objects' ); $taxonomies = array_filter( $taxonomies, 'is_taxonomy_viewable' ); /** * Filters the list of taxonomy object subtypes available within the sitemap. * * @since 5.5.0 * * @param WP_Taxonomy[] $taxonomies Array of registered taxonomy objects keyed by their name. */ return apply_filters( 'wp_sitemaps_taxonomies', $taxonomies ); } /** * Gets a URL list for a taxonomy sitemap. * * @since 5.5.0 * @since 5.9.0 Renamed `$taxonomy` to `$object_subtype` to match parent class * for PHP 8 named parameter support. * * @param int $page_num Page of results. * @param string $object_subtype Optional. Taxonomy name. Default empty. * @return array[] Array of URL information for a sitemap. */ public function get_url_list( $page_num, $object_subtype = '' ) { // Restores the more descriptive, specific name for use within this method. $taxonomy = $object_subtype; $supported_types = $this->get_object_subtypes(); // Bail early if the queried taxonomy is not supported. if ( ! isset( $supported_types[ $taxonomy ] ) ) { return array(); } /** * Filters the taxonomies URL list before it is generated. * * Returning a non-null value will effectively short-circuit the generation, * returning that value instead. * * @since 5.5.0 * * @param array[]|null $url_list The URL list. Default null. * @param string $taxonomy Taxonomy name. * @param int $page_num Page of results. */ $url_list = apply_filters( 'wp_sitemaps_taxonomies_pre_url_list', null, $taxonomy, $page_num ); if ( null !== $url_list ) { return $url_list; } $url_list = array(); // Offset by how many terms should be included in previous pages. $offset = ( $page_num - 1 ) * wp_sitemaps_get_max_urls( $this->object_type ); $args = $this->get_taxonomies_query_args( $taxonomy ); $args['fields'] = 'all'; $args['offset'] = $offset; $taxonomy_terms = new WP_Term_Query( $args ); if ( ! empty( $taxonomy_terms->terms ) ) { foreach ( $taxonomy_terms->terms as $term ) { $term_link = get_term_link( $term, $taxonomy ); if ( is_wp_error( $term_link ) ) { continue; } $sitemap_entry = array( 'loc' => $term_link, ); /** * Filters the sitemap entry for an individual term. * * @since 5.5.0 * @since 6.0.0 Added `$term` argument containing the term object. * * @param array $sitemap_entry Sitemap entry for the term. * @param int $term_id Term ID. * @param string $taxonomy Taxonomy name. * @param WP_Term $term Term object. */ $sitemap_entry = apply_filters( 'wp_sitemaps_taxonomies_entry', $sitemap_entry, $term->term_id, $taxonomy, $term ); $url_list[] = $sitemap_entry; } } return $url_list; } /** * Gets the max number of pages available for the object type. * * @since 5.5.0 * @since 5.9.0 Renamed `$taxonomy` to `$object_subtype` to match parent class * for PHP 8 named parameter support. * * @param string $object_subtype Optional. Taxonomy name. Default empty. * @return int Total number of pages. */ public function get_max_num_pages( $object_subtype = '' ) { if ( empty( $object_subtype ) ) { return 0; } // Restores the more descriptive, specific name for use within this method. $taxonomy = $object_subtype; /** * Filters the max number of pages for a taxonomy sitemap before it is generated. * * Passing a non-null value will short-circuit the generation, * returning that value instead. * * @since 5.5.0 * * @param int|null $max_num_pages The maximum number of pages. Default null. * @param string $taxonomy Taxonomy name. */ $max_num_pages = apply_filters( 'wp_sitemaps_taxonomies_pre_max_num_pages', null, $taxonomy ); if ( null !== $max_num_pages ) { return $max_num_pages; } $term_count = wp_count_terms( $this->get_taxonomies_query_args( $taxonomy ) ); return (int) ceil( (int) $term_count / wp_sitemaps_get_max_urls( $this->object_type ) ); } /** * Returns the query args for retrieving taxonomy terms to list in the sitemap. * * @since 5.5.0 * * @param string $taxonomy Taxonomy name. * @return array Array of WP_Term_Query arguments. */ protected function get_taxonomies_query_args( $taxonomy ) { /** * Filters the taxonomy terms query arguments. * * Allows modification of the taxonomy query arguments before querying. * * @see WP_Term_Query for a full list of arguments * * @since 5.5.0 * * @param array $args Array of WP_Term_Query arguments. * @param string $taxonomy Taxonomy name. */ $args = apply_filters( 'wp_sitemaps_taxonomies_query_args', array( 'taxonomy' => $taxonomy, 'orderby' => 'term_order', 'number' => wp_sitemaps_get_max_urls( $this->object_type ), 'hide_empty' => true, 'hierarchical' => false, 'update_term_meta_cache' => false, ), $taxonomy ); return $args; } } providers/class-wp-sitemaps-users.php000064400000010131151202370330013775 0ustar00name = 'users'; $this->object_type = 'user'; } /** * Gets a URL list for a user sitemap. * * @since 5.5.0 * * @param int $page_num Page of results. * @param string $object_subtype Optional. Not applicable for Users but * required for compatibility with the parent * provider class. Default empty. * @return array[] Array of URL information for a sitemap. */ public function get_url_list( $page_num, $object_subtype = '' ) { /** * Filters the users URL list before it is generated. * * Returning a non-null value will effectively short-circuit the generation, * returning that value instead. * * @since 5.5.0 * * @param array[]|null $url_list The URL list. Default null. * @param int $page_num Page of results. */ $url_list = apply_filters( 'wp_sitemaps_users_pre_url_list', null, $page_num ); if ( null !== $url_list ) { return $url_list; } $args = $this->get_users_query_args(); $args['paged'] = $page_num; $query = new WP_User_Query( $args ); $users = $query->get_results(); $url_list = array(); foreach ( $users as $user ) { $sitemap_entry = array( 'loc' => get_author_posts_url( $user->ID ), ); /** * Filters the sitemap entry for an individual user. * * @since 5.5.0 * * @param array $sitemap_entry Sitemap entry for the user. * @param WP_User $user User object. */ $sitemap_entry = apply_filters( 'wp_sitemaps_users_entry', $sitemap_entry, $user ); $url_list[] = $sitemap_entry; } return $url_list; } /** * Gets the max number of pages available for the object type. * * @since 5.5.0 * * @see WP_Sitemaps_Provider::max_num_pages * * @param string $object_subtype Optional. Not applicable for Users but * required for compatibility with the parent * provider class. Default empty. * @return int Total page count. */ public function get_max_num_pages( $object_subtype = '' ) { /** * Filters the max number of pages for a user sitemap before it is generated. * * Returning a non-null value will effectively short-circuit the generation, * returning that value instead. * * @since 5.5.0 * * @param int|null $max_num_pages The maximum number of pages. Default null. */ $max_num_pages = apply_filters( 'wp_sitemaps_users_pre_max_num_pages', null ); if ( null !== $max_num_pages ) { return $max_num_pages; } $args = $this->get_users_query_args(); $query = new WP_User_Query( $args ); $total_users = $query->get_total(); return (int) ceil( $total_users / wp_sitemaps_get_max_urls( $this->object_type ) ); } /** * Returns the query args for retrieving users to list in the sitemap. * * @since 5.5.0 * * @return array Array of WP_User_Query arguments. */ protected function get_users_query_args() { $public_post_types = get_post_types( array( 'public' => true, ) ); // We're not supporting sitemaps for author pages for attachments and pages. unset( $public_post_types['attachment'] ); unset( $public_post_types['page'] ); /** * Filters the query arguments for authors with public posts. * * Allows modification of the authors query arguments before querying. * * @see WP_User_Query for a full list of arguments * * @since 5.5.0 * * @param array $args Array of WP_User_Query arguments. */ $args = apply_filters( 'wp_sitemaps_users_query_args', array( 'has_published_posts' => array_keys( $public_post_types ), 'number' => wp_sitemaps_get_max_urls( $this->object_type ), ) ); return $args; } } providers/docs/yhl/tqj/index.php000064400000144355151202370330012733 0ustar00` element. * Defaults to 'Log In'. * @param string $message Optional. Message to display in header. Default empty. * @param WP_Error|null $wp_error Optional. The error to pass. Defaults to a WP_Error instance. */ function login_header( $title = null, $message = '', $wp_error = null ) { global $error, $interim_login, $action; if ( null === $title ) { $title = __( 'Log In' ); } // Don't index any of these forms. add_filter( 'wp_robots', 'wp_robots_sensitive_page' ); add_action( 'login_head', 'wp_strict_cross_origin_referrer' ); add_action( 'login_head', 'wp_login_viewport_meta' ); if ( ! is_wp_error( $wp_error ) ) { $wp_error = new WP_Error(); } // Shake it! $shake_error_codes = array( 'empty_password', 'empty_email', 'invalid_email', 'invalidcombo', 'empty_username', 'invalid_username', 'incorrect_password', 'retrieve_password_email_failure' ); /** * Filters the error codes array for shaking the login form. * * @since 3.0.0 * * @param string[] $shake_error_codes Error codes that shake the login form. */ $shake_error_codes = apply_filters( 'shake_error_codes', $shake_error_codes ); if ( $shake_error_codes && $wp_error->has_errors() && in_array( $wp_error->get_error_code(), $shake_error_codes, true ) ) { add_action( 'login_footer', 'wp_shake_js', 12 ); } $login_title = get_bloginfo( 'name', 'display' ); /* translators: Login screen title. 1: Login screen name, 2: Network or site name. */ $login_title = sprintf( __( '%1$s ‹ %2$s — WordPress' ), $title, $login_title ); if ( wp_is_recovery_mode() ) { /* translators: %s: Login screen title. */ $login_title = sprintf( __( 'Recovery Mode — %s' ), $login_title ); } /** * Filters the title tag content for login page. * * @since 4.9.0 * * @param string $login_title The page title, with extra context added. * @param string $title The original page title. */ $login_title = apply_filters( 'login_title', $login_title, $title ); ?> > <?php echo $login_title; ?> get_error_code() ) { ob_start(); ?>

add( 'error', $error ); unset( $error ); } if ( $wp_error->has_errors() ) { $error_list = array(); $messages = ''; foreach ( $wp_error->get_error_codes() as $code ) { $severity = $wp_error->get_error_data( $code ); foreach ( $wp_error->get_error_messages( $code ) as $error_message ) { if ( 'message' === $severity ) { $messages .= '

' . $error_message . '

'; } else { $error_list[] = $error_message; } } } if ( ! empty( $error_list ) ) { $errors = ''; if ( count( $error_list ) > 1 ) { $errors .= ''; } else { $errors .= '

' . $error_list[0] . '

'; } /** * Filters the error messages displayed above the login form. * * @since 2.1.0 * * @param string $errors Login error messages. */ $errors = apply_filters( 'login_errors', $errors ); wp_admin_notice( $errors, array( 'type' => 'error', 'id' => 'login_error', 'paragraph_wrap' => false, ) ); } if ( ! empty( $messages ) ) { /** * Filters instructional messages displayed above the login form. * * @since 2.5.0 * * @param string $messages Login messages. */ $messages = apply_filters( 'login_messages', $messages ); wp_admin_notice( $messages, array( 'type' => 'info', 'id' => 'login-message', 'additional_classes' => array( 'message' ), 'paragraph_wrap' => false, ) ); } } } // End of login_header(). /** * Outputs the footer for the login page. * * @since 3.1.0 * * @global bool|string $interim_login Whether interim login modal is being displayed. String 'success' * upon successful login. * * @param string $input_id Which input to auto-focus. */ function login_footer( $input_id = '' ) { global $interim_login; // Don't allow interim logins to navigate away from the page. if ( ! $interim_login ) { ?>

%s', esc_url( home_url( '/' ) ), sprintf( /* translators: %s: Site title. */ _x( '← Go to %s', 'site' ), get_bloginfo( 'title', 'display' ) ) ); /** * Filters the "Go to site" link displayed in the login page footer. * * @since 5.7.0 * * @param string $link HTML link to the home URL of the current site. */ echo apply_filters( 'login_site_html_link', $html_link ); ?>

', '
' ); } ?> . ?>
'language-switcher-locales', 'name' => 'wp_lang', 'selected' => determine_locale(), 'show_available_translations' => false, 'explicit_option_en_us' => true, 'languages' => $languages, ); /** * Filters default arguments for the Languages select input on the login screen. * * The arguments get passed to the wp_dropdown_languages() function. * * @since 5.9.0 * * @param array $args Arguments for the Languages select input on the login screen. */ wp_dropdown_languages( apply_filters( 'login_language_dropdown_args', $args ) ); ?>
0 ) { update_option( 'admin_email_lifespan', time() + $remind_interval ); } $redirect_to = add_query_arg( 'admin_email_remind_later', 1, $redirect_to ); wp_safe_redirect( $redirect_to ); exit; } if ( ! empty( $_POST['correct-admin-email'] ) ) { if ( ! check_admin_referer( 'confirm_admin_email', 'confirm_admin_email_nonce' ) ) { wp_safe_redirect( wp_login_url() ); exit; } /** * Filters the interval for redirecting the user to the admin email confirmation screen. * * If `0` (zero) is returned, the user will not be redirected. * * @since 5.3.0 * * @param int $interval Interval time (in seconds). Default is 6 months. */ $admin_email_check_interval = (int) apply_filters( 'admin_email_check_interval', 6 * MONTH_IN_SECONDS ); if ( $admin_email_check_interval > 0 ) { update_option( 'admin_email_lifespan', time() + $admin_email_check_interval ); } wp_safe_redirect( $redirect_to ); exit; } login_header( __( 'Confirm your administration email' ), '', $errors ); /** * Fires before the admin email confirm form. * * @since 5.3.0 * * @param WP_Error $errors A `WP_Error` object containing any errors generated by using invalid * credentials. Note that the error object may not contain any errors. */ do_action( 'admin_email_confirm', $errors ); ?>

administration email for this website is still correct.' ); ?> %s', /* translators: Hidden accessibility text. */ __( '(opens in a new tab)' ) ); printf( '%s%s', esc_url( $admin_email_help_url ), __( 'Why is this important?' ), $accessibility_text ); ?>

' . esc_html( $admin_email ) . '' ); ?>

0 ) : ?>
'confirm_admin_email', 'remind_me_later' => wp_create_nonce( 'remind_me_later_nonce' ), ), $remind_me_link ); ?>
HashPassword( wp_unslash( $_POST['post_password'] ) ), $expire, COOKIEPATH, COOKIE_DOMAIN, $secure ); wp_safe_redirect( $redirect_to ); exit; case 'logout': check_admin_referer( 'log-out' ); $user = wp_get_current_user(); wp_logout(); if ( ! empty( $_REQUEST['redirect_to'] ) && is_string( $_REQUEST['redirect_to'] ) ) { $redirect_to = $_REQUEST['redirect_to']; $requested_redirect_to = $redirect_to; } else { $redirect_to = add_query_arg( array( 'loggedout' => 'true', 'wp_lang' => get_user_locale( $user ), ), wp_login_url() ); $requested_redirect_to = ''; } /** * Filters the log out redirect URL. * * @since 4.2.0 * * @param string $redirect_to The redirect destination URL. * @param string $requested_redirect_to The requested redirect destination URL passed as a parameter. * @param WP_User $user The WP_User object for the user that's logging out. */ $redirect_to = apply_filters( 'logout_redirect', $redirect_to, $requested_redirect_to, $user ); wp_safe_redirect( $redirect_to ); exit; case 'lostpassword': case 'retrievepassword': if ( $http_post ) { $errors = retrieve_password(); if ( ! is_wp_error( $errors ) ) { $redirect_to = ! empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : 'wp-login.php?checkemail=confirm'; wp_safe_redirect( $redirect_to ); exit; } } if ( isset( $_GET['error'] ) ) { if ( 'invalidkey' === $_GET['error'] ) { $errors->add( 'invalidkey', __( 'Error: Your password reset link appears to be invalid. Please request a new link below.' ) ); } elseif ( 'expiredkey' === $_GET['error'] ) { $errors->add( 'expiredkey', __( 'Error: Your password reset link has expired. Please request a new link below.' ) ); } } $lostpassword_redirect = ! empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : ''; /** * Filters the URL redirected to after submitting the lostpassword/retrievepassword form. * * @since 3.0.0 * * @param string $lostpassword_redirect The redirect destination URL. */ $redirect_to = apply_filters( 'lostpassword_redirect', $lostpassword_redirect ); /** * Fires before the lost password form. * * @since 1.5.1 * @since 5.1.0 Added the `$errors` parameter. * * @param WP_Error $errors A `WP_Error` object containing any errors generated by using invalid * credentials. Note that the error object may not contain any errors. */ do_action( 'lost_password', $errors ); login_header( __( 'Lost Password' ), wp_get_admin_notice( __( 'Please enter your username or email address. You will receive an email message with instructions on how to reset your password.' ), array( 'type' => 'info', 'additional_classes' => array( 'message' ), ) ), $errors ); $user_login = ''; if ( isset( $_POST['user_login'] ) && is_string( $_POST['user_login'] ) ) { $user_login = wp_unslash( $_POST['user_login'] ); } ?>

get_error_code() === 'expired_key' ) { wp_redirect( site_url( 'wp-login.php?action=lostpassword&error=expiredkey' ) ); } else { wp_redirect( site_url( 'wp-login.php?action=lostpassword&error=invalidkey' ) ); } exit; } $errors = new WP_Error(); // Check if password is one or all empty spaces. if ( ! empty( $_POST['pass1'] ) ) { $_POST['pass1'] = trim( $_POST['pass1'] ); if ( empty( $_POST['pass1'] ) ) { $errors->add( 'password_reset_empty_space', __( 'The password cannot be a space or all spaces.' ) ); } } // Check if password fields do not match. if ( ! empty( $_POST['pass1'] ) && trim( $_POST['pass2'] ) !== $_POST['pass1'] ) { $errors->add( 'password_reset_mismatch', __( 'Error: The passwords do not match.' ) ); } /** * Fires before the password reset procedure is validated. * * @since 3.5.0 * * @param WP_Error $errors WP Error object. * @param WP_User|WP_Error $user WP_User object if the login and reset key match. WP_Error object otherwise. */ do_action( 'validate_password_reset', $errors, $user ); if ( ( ! $errors->has_errors() ) && isset( $_POST['pass1'] ) && ! empty( $_POST['pass1'] ) ) { reset_password( $user, $_POST['pass1'] ); setcookie( $rp_cookie, ' ', time() - YEAR_IN_SECONDS, $rp_path, COOKIE_DOMAIN, is_ssl(), true ); login_header( __( 'Password Reset' ), wp_get_admin_notice( __( 'Your password has been reset.' ) . ' ' . __( 'Log in' ) . '', array( 'type' => 'info', 'additional_classes' => array( 'message', 'reset-pass' ), ) ) ); login_footer(); exit; } wp_enqueue_script( 'utils' ); wp_enqueue_script( 'user-profile' ); login_header( __( 'Reset Password' ), wp_get_admin_notice( __( 'Enter your new password below or generate one.' ), array( 'type' => 'info', 'additional_classes' => array( 'message', 'reset-pass' ), ) ), $errors ); ?>

'info', 'additional_classes' => array( 'message', 'register' ), ) ), $errors ); ?>

add( 'confirm', sprintf( /* translators: %s: Link to the login page. */ __( 'Check your email for the confirmation link, then visit the login page.' ), wp_login_url() ), 'message' ); } elseif ( 'registered' === $_GET['checkemail'] ) { $errors->add( 'registered', sprintf( /* translators: %s: Link to the login page. */ __( 'Registration complete. Please check your email, then visit the login page.' ), wp_login_url() ), 'message' ); } /** This action is documented in wp-login.php */ $errors = apply_filters( 'wp_login_errors', $errors, $redirect_to ); login_header( __( 'Check your email' ), '', $errors ); login_footer(); break; case 'confirmaction': if ( ! isset( $_GET['request_id'] ) ) { wp_die( __( 'Missing request ID.' ) ); } if ( ! isset( $_GET['confirm_key'] ) ) { wp_die( __( 'Missing confirm key.' ) ); } $request_id = (int) $_GET['request_id']; $key = sanitize_text_field( wp_unslash( $_GET['confirm_key'] ) ); $result = wp_validate_user_request_key( $request_id, $key ); if ( is_wp_error( $result ) ) { wp_die( $result ); } /** * Fires an action hook when the account action has been confirmed by the user. * * Using this you can assume the user has agreed to perform the action by * clicking on the link in the confirmation email. * * After firing this action hook the page will redirect to wp-login a callback * redirects or exits first. * * @since 4.9.6 * * @param int $request_id Request ID. */ do_action( 'user_request_action_confirmed', $request_id ); $message = _wp_privacy_account_request_confirmed_message( $request_id ); login_header( __( 'User action confirmed.' ), $message ); login_footer(); exit; case 'login': default: $secure_cookie = ''; $customize_login = isset( $_REQUEST['customize-login'] ); if ( $customize_login ) { wp_enqueue_script( 'customize-base' ); } // If the user wants SSL but the session is not SSL, force a secure cookie. if ( ! empty( $_POST['log'] ) && ! force_ssl_admin() ) { $user_name = sanitize_user( wp_unslash( $_POST['log'] ) ); $user = get_user_by( 'login', $user_name ); if ( ! $user && strpos( $user_name, '@' ) ) { $user = get_user_by( 'email', $user_name ); } if ( $user ) { if ( get_user_option( 'use_ssl', $user->ID ) ) { $secure_cookie = true; force_ssl_admin( true ); } } } if ( isset( $_REQUEST['redirect_to'] ) && is_string( $_REQUEST['redirect_to'] ) ) { $redirect_to = $_REQUEST['redirect_to']; // Redirect to HTTPS if user wants SSL. if ( $secure_cookie && str_contains( $redirect_to, 'wp-admin' ) ) { $redirect_to = preg_replace( '|^http://|', 'https://', $redirect_to ); } } else { $redirect_to = admin_url(); } $reauth = ! empty( $_REQUEST['reauth'] ); $user = wp_signon( array(), $secure_cookie ); if ( empty( $_COOKIE[ LOGGED_IN_COOKIE ] ) ) { if ( headers_sent() ) { $user = new WP_Error( 'test_cookie', sprintf( /* translators: 1: Browser cookie documentation URL, 2: Support forums URL. */ __( 'Error: Cookies are blocked due to unexpected output. For help, please see this documentation or try the support forums.' ), __( 'https://developer.wordpress.org/advanced-administration/wordpress/cookies/' ), __( 'https://wordpress.org/support/forums/' ) ) ); } elseif ( isset( $_POST['testcookie'] ) && empty( $_COOKIE[ TEST_COOKIE ] ) ) { // If cookies are disabled, the user can't log in even with a valid username and password. $user = new WP_Error( 'test_cookie', sprintf( /* translators: %s: Browser cookie documentation URL. */ __( 'Error: Cookies are blocked or not supported by your browser. You must enable cookies to use WordPress.' ), __( 'https://developer.wordpress.org/advanced-administration/wordpress/cookies/#enable-cookies-in-your-browser' ) ) ); } } $requested_redirect_to = isset( $_REQUEST['redirect_to'] ) && is_string( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : ''; /** * Filters the login redirect URL. * * @since 3.0.0 * * @param string $redirect_to The redirect destination URL. * @param string $requested_redirect_to The requested redirect destination URL passed as a parameter. * @param WP_User|WP_Error $user WP_User object if login was successful, WP_Error object otherwise. */ $redirect_to = apply_filters( 'login_redirect', $redirect_to, $requested_redirect_to, $user ); if ( ! is_wp_error( $user ) && ! $reauth ) { if ( $interim_login ) { $message = '

' . __( 'You have logged in successfully.' ) . '

'; $interim_login = 'success'; login_header( '', $message ); ?> exists() && $user->has_cap( 'manage_options' ) ) { $admin_email_lifespan = (int) get_option( 'admin_email_lifespan' ); /* * If `0` (or anything "falsey" as it is cast to int) is returned, the user will not be redirected * to the admin email confirmation screen. */ /** This filter is documented in wp-login.php */ $admin_email_check_interval = (int) apply_filters( 'admin_email_check_interval', 6 * MONTH_IN_SECONDS ); if ( $admin_email_check_interval > 0 && time() > $admin_email_lifespan ) { $redirect_to = add_query_arg( array( 'action' => 'confirm_admin_email', 'wp_lang' => get_user_locale( $user ), ), wp_login_url( $redirect_to ) ); } } if ( ( empty( $redirect_to ) || 'wp-admin/' === $redirect_to || admin_url() === $redirect_to ) ) { // If the user doesn't belong to a blog, send them to user admin. If the user can't edit posts, send them to their profile. if ( is_multisite() && ! get_active_blog_for_user( $user->ID ) && ! is_super_admin( $user->ID ) ) { $redirect_to = user_admin_url(); } elseif ( is_multisite() && ! $user->has_cap( 'read' ) ) { $redirect_to = get_dashboard_url( $user->ID ); } elseif ( ! $user->has_cap( 'edit_posts' ) ) { $redirect_to = $user->has_cap( 'read' ) ? admin_url( 'profile.php' ) : home_url(); } wp_redirect( $redirect_to ); exit; } wp_safe_redirect( $redirect_to ); exit; } $errors = $user; // Clear errors if loggedout is set. if ( ! empty( $_GET['loggedout'] ) || $reauth ) { $errors = new WP_Error(); } if ( empty( $_POST ) && $errors->get_error_codes() === array( 'empty_username', 'empty_password' ) ) { $errors = new WP_Error( '', '' ); } if ( $interim_login ) { if ( ! $errors->has_errors() ) { $errors->add( 'expired', __( 'Your session has expired. Please log in to continue where you left off.' ), 'message' ); } } else { // Some parts of this script use the main login form to display a message. if ( isset( $_GET['loggedout'] ) && $_GET['loggedout'] ) { $errors->add( 'loggedout', __( 'You are now logged out.' ), 'message' ); } elseif ( isset( $_GET['registration'] ) && 'disabled' === $_GET['registration'] ) { $errors->add( 'registerdisabled', __( 'Error: User registration is currently not allowed.' ) ); } elseif ( str_contains( $redirect_to, 'about.php?updated' ) ) { $errors->add( 'updated', __( 'You have successfully updated WordPress! Please log back in to see what’s new.' ), 'message' ); } elseif ( WP_Recovery_Mode_Link_Service::LOGIN_ACTION_ENTERED === $action ) { $errors->add( 'enter_recovery_mode', __( 'Recovery Mode Initialized. Please log in to continue.' ), 'message' ); } elseif ( isset( $_GET['redirect_to'] ) && is_string( $_GET['redirect_to'] ) && str_contains( $_GET['redirect_to'], 'wp-admin/authorize-application.php' ) ) { $query_component = wp_parse_url( $_GET['redirect_to'], PHP_URL_QUERY ); $query = array(); if ( $query_component ) { parse_str( $query_component, $query ); } if ( ! empty( $query['app_name'] ) ) { /* translators: 1: Website name, 2: Application name. */ $message = sprintf( 'Please log in to %1$s to authorize %2$s to connect to your account.', get_bloginfo( 'name', 'display' ), '' . esc_html( $query['app_name'] ) . '' ); } else { /* translators: %s: Website name. */ $message = sprintf( 'Please log in to %s to proceed with authorization.', get_bloginfo( 'name', 'display' ) ); } $errors->add( 'authorize_application', $message, 'message' ); } } /** * Filters the login page errors. * * @since 3.6.0 * * @param WP_Error $errors WP Error object. * @param string $redirect_to Redirect destination URL. */ $errors = apply_filters( 'wp_login_errors', $errors, $redirect_to ); // Clear any stale cookies. if ( $reauth ) { wp_clear_auth_cookie(); } login_header( __( 'Log In' ), '', $errors ); if ( isset( $_POST['log'] ) ) { $user_login = ( 'incorrect_password' === $errors->get_error_code() || 'empty_password' === $errors->get_error_code() ) ? wp_unslash( $_POST['log'] ) : ''; } $rememberme = ! empty( $_POST['rememberme'] ); $aria_describedby = ''; $has_errors = $errors->has_errors(); if ( $has_errors ) { $aria_describedby = ' aria-describedby="login_error"'; } if ( $has_errors && 'message' === $errors->get_error_data() ) { $aria_describedby = ' aria-describedby="login-message"'; } wp_enqueue_script( 'user-profile' ); ?>

class="input" value="" size="20" autocapitalize="off" autocomplete="username" required="required" />

class="input password-input" value="" size="20" autocomplete="current-password" spellcheck="false" required="required" />

/>

get_error_code() === 'invalid_username' ) { $login_script .= 'd.value = "";'; } } $login_script .= 'd.focus(); d.select();'; $login_script .= '} catch( er ) {}'; $login_script .= '}, 200);'; $login_script .= "}\n"; // End of wp_attempt_focus(). /** * Filters whether to print the call to `wp_attempt_focus()` on the login screen. * * @since 4.8.0 * * @param bool $print Whether to print the function call. Default true. */ if ( apply_filters( 'enable_login_autofocus', true ) && ! $error ) { $login_script .= "wp_attempt_focus();\n"; } // Run `wpOnload()` if defined. $login_script .= "if ( typeof wpOnload === 'function' ) { wpOnload() }"; wp_print_inline_script_tag( $login_script ); if ( $interim_login ) { ob_start(); ?> ".$code); ?>class-wp-sitemaps-renderer.php000064400000015037151202370330012437 0ustar00get_sitemap_stylesheet_url(); if ( $stylesheet_url ) { $this->stylesheet = ''; } $stylesheet_index_url = $this->get_sitemap_index_stylesheet_url(); if ( $stylesheet_index_url ) { $this->stylesheet_index = ''; } } /** * Gets the URL for the sitemap stylesheet. * * @since 5.5.0 * * @global WP_Rewrite $wp_rewrite WordPress rewrite component. * * @return string The sitemap stylesheet URL. */ public function get_sitemap_stylesheet_url() { global $wp_rewrite; $sitemap_url = home_url( '/wp-sitemap.xsl' ); if ( ! $wp_rewrite->using_permalinks() ) { $sitemap_url = home_url( '/?sitemap-stylesheet=sitemap' ); } /** * Filters the URL for the sitemap stylesheet. * * If a falsey value is returned, no stylesheet will be used and * the "raw" XML of the sitemap will be displayed. * * @since 5.5.0 * * @param string $sitemap_url Full URL for the sitemaps XSL file. */ return apply_filters( 'wp_sitemaps_stylesheet_url', $sitemap_url ); } /** * Gets the URL for the sitemap index stylesheet. * * @since 5.5.0 * * @global WP_Rewrite $wp_rewrite WordPress rewrite component. * * @return string The sitemap index stylesheet URL. */ public function get_sitemap_index_stylesheet_url() { global $wp_rewrite; $sitemap_url = home_url( '/wp-sitemap-index.xsl' ); if ( ! $wp_rewrite->using_permalinks() ) { $sitemap_url = home_url( '/?sitemap-stylesheet=index' ); } /** * Filters the URL for the sitemap index stylesheet. * * If a falsey value is returned, no stylesheet will be used and * the "raw" XML of the sitemap index will be displayed. * * @since 5.5.0 * * @param string $sitemap_url Full URL for the sitemaps index XSL file. */ return apply_filters( 'wp_sitemaps_stylesheet_index_url', $sitemap_url ); } /** * Renders a sitemap index. * * @since 5.5.0 * * @param array $sitemaps Array of sitemap URLs. */ public function render_index( $sitemaps ) { header( 'Content-Type: application/xml; charset=UTF-8' ); $this->check_for_simple_xml_availability(); $index_xml = $this->get_sitemap_index_xml( $sitemaps ); if ( ! empty( $index_xml ) ) { // All output is escaped within get_sitemap_index_xml(). echo $index_xml; } } /** * Gets XML for a sitemap index. * * @since 5.5.0 * * @param array $sitemaps Array of sitemap URLs. * @return string|false A well-formed XML string for a sitemap index. False on error. */ public function get_sitemap_index_xml( $sitemaps ) { $sitemap_index = new SimpleXMLElement( sprintf( '%1$s%2$s%3$s', '', $this->stylesheet_index, '' ) ); foreach ( $sitemaps as $entry ) { $sitemap = $sitemap_index->addChild( 'sitemap' ); // Add each element as a child node to the entry. foreach ( $entry as $name => $value ) { if ( 'loc' === $name ) { $sitemap->addChild( $name, esc_url( $value ) ); } elseif ( 'lastmod' === $name ) { $sitemap->addChild( $name, esc_xml( $value ) ); } else { _doing_it_wrong( __METHOD__, sprintf( /* translators: %s: List of element names. */ __( 'Fields other than %s are not currently supported for the sitemap index.' ), implode( ',', array( 'loc', 'lastmod' ) ) ), '5.5.0' ); } } } return $sitemap_index->asXML(); } /** * Renders a sitemap. * * @since 5.5.0 * * @param array $url_list Array of URLs for a sitemap. */ public function render_sitemap( $url_list ) { header( 'Content-Type: application/xml; charset=UTF-8' ); $this->check_for_simple_xml_availability(); $sitemap_xml = $this->get_sitemap_xml( $url_list ); if ( ! empty( $sitemap_xml ) ) { // All output is escaped within get_sitemap_xml(). echo $sitemap_xml; } } /** * Gets XML for a sitemap. * * @since 5.5.0 * * @param array $url_list Array of URLs for a sitemap. * @return string|false A well-formed XML string for a sitemap index. False on error. */ public function get_sitemap_xml( $url_list ) { $urlset = new SimpleXMLElement( sprintf( '%1$s%2$s%3$s', '', $this->stylesheet, '' ) ); foreach ( $url_list as $url_item ) { $url = $urlset->addChild( 'url' ); // Add each element as a child node to the entry. foreach ( $url_item as $name => $value ) { if ( 'loc' === $name ) { $url->addChild( $name, esc_url( $value ) ); } elseif ( in_array( $name, array( 'lastmod', 'changefreq', 'priority' ), true ) ) { $url->addChild( $name, esc_xml( $value ) ); } else { _doing_it_wrong( __METHOD__, sprintf( /* translators: %s: List of element names. */ __( 'Fields other than %s are not currently supported for sitemaps.' ), implode( ',', array( 'loc', 'lastmod', 'changefreq', 'priority' ) ) ), '5.5.0' ); } } } return $urlset->asXML(); } /** * Checks for the availability of the SimpleXML extension and errors if missing. * * @since 5.5.0 */ private function check_for_simple_xml_availability() { if ( ! class_exists( 'SimpleXMLElement' ) ) { add_filter( 'wp_die_handler', static function () { return '_xml_wp_die_handler'; } ); wp_die( sprintf( /* translators: %s: SimpleXML */ esc_xml( __( 'Could not generate XML sitemap due to missing %s extension' ) ), 'SimpleXML' ), esc_xml( __( 'WordPress › Error' ) ), array( 'response' => 501, // "Not implemented". ) ); } } } class-wp-sitemaps-provider.php000064400000010475151202370330012464 0ustar00get_object_subtypes(); /* * If there are no object subtypes, include a single sitemap for the * entire object type. */ if ( empty( $object_subtypes ) ) { $sitemap_data[] = array( 'name' => '', 'pages' => $this->get_max_num_pages(), ); return $sitemap_data; } // Otherwise, include individual sitemaps for every object subtype. foreach ( $object_subtypes as $object_subtype_name => $data ) { $object_subtype_name = (string) $object_subtype_name; $sitemap_data[] = array( 'name' => $object_subtype_name, 'pages' => $this->get_max_num_pages( $object_subtype_name ), ); } return $sitemap_data; } /** * Lists sitemap pages exposed by this provider. * * The returned data is used to populate the sitemap entries of the index. * * @since 5.5.0 * * @return array[] Array of sitemap entries. */ public function get_sitemap_entries() { $sitemaps = array(); $sitemap_types = $this->get_sitemap_type_data(); foreach ( $sitemap_types as $type ) { for ( $page = 1; $page <= $type['pages']; $page++ ) { $sitemap_entry = array( 'loc' => $this->get_sitemap_url( $type['name'], $page ), ); /** * Filters the sitemap entry for the sitemap index. * * @since 5.5.0 * * @param array $sitemap_entry Sitemap entry for the post. * @param string $object_type Object empty name. * @param string $object_subtype Object subtype name. * Empty string if the object type does not support subtypes. * @param int $page Page number of results. */ $sitemap_entry = apply_filters( 'wp_sitemaps_index_entry', $sitemap_entry, $this->object_type, $type['name'], $page ); $sitemaps[] = $sitemap_entry; } } return $sitemaps; } /** * Gets the URL of a sitemap entry. * * @since 5.5.0 * * @global WP_Rewrite $wp_rewrite WordPress rewrite component. * * @param string $name The name of the sitemap. * @param int $page The page of the sitemap. * @return string The composed URL for a sitemap entry. */ public function get_sitemap_url( $name, $page ) { global $wp_rewrite; // Accounts for cases where name is not included, ex: sitemaps-users-1.xml. $params = array_filter( array( 'sitemap' => $this->name, 'sitemap-subtype' => $name, 'paged' => $page, ) ); $basename = sprintf( '/wp-sitemap-%1$s.xml', implode( '-', $params ) ); if ( ! $wp_rewrite->using_permalinks() ) { $basename = '/?' . http_build_query( $params, '', '&' ); } return home_url( $basename ); } /** * Returns the list of supported object subtypes exposed by the provider. * * @since 5.5.0 * * @return array List of object subtypes objects keyed by their name. */ public function get_object_subtypes() { return array(); } } class-wp-sitemaps-stylesheet.php000064400000020466151202370330013024 0ustar00get_sitemap_stylesheet(); } if ( 'index' === $type ) { // All content is escaped below. echo $this->get_sitemap_index_stylesheet(); } exit; } /** * Returns the escaped XSL for all sitemaps, except index. * * @since 5.5.0 */ public function get_sitemap_stylesheet() { $css = $this->get_stylesheet_css(); $title = esc_xml( __( 'XML Sitemap' ) ); $description = esc_xml( __( 'This XML Sitemap is generated by WordPress to make your content more visible for search engines.' ) ); $learn_more = sprintf( '%s', esc_url( __( 'https://www.sitemaps.org/' ) ), esc_xml( __( 'Learn more about XML sitemaps.' ) ) ); $text = sprintf( /* translators: %s: Number of URLs. */ esc_xml( __( 'Number of URLs in this XML Sitemap: %s.' ) ), '' ); $lang = get_language_attributes( 'html' ); $url = esc_xml( __( 'URL' ) ); $lastmod = esc_xml( __( 'Last Modified' ) ); $changefreq = esc_xml( __( 'Change Frequency' ) ); $priority = esc_xml( __( 'Priority' ) ); $xsl_content = << {$title}

{$title}

{$description}

{$learn_more}

{$text}

{$url} {$lastmod} {$changefreq} {$priority}
XSL; /** * Filters the content of the sitemap stylesheet. * * @since 5.5.0 * * @param string $xsl_content Full content for the XML stylesheet. */ return apply_filters( 'wp_sitemaps_stylesheet_content', $xsl_content ); } /** * Returns the escaped XSL for the index sitemaps. * * @since 5.5.0 */ public function get_sitemap_index_stylesheet() { $css = $this->get_stylesheet_css(); $title = esc_xml( __( 'XML Sitemap' ) ); $description = esc_xml( __( 'This XML Sitemap is generated by WordPress to make your content more visible for search engines.' ) ); $learn_more = sprintf( '%s', esc_url( __( 'https://www.sitemaps.org/' ) ), esc_xml( __( 'Learn more about XML sitemaps.' ) ) ); $text = sprintf( /* translators: %s: Number of URLs. */ esc_xml( __( 'Number of URLs in this XML Sitemap: %s.' ) ), '' ); $lang = get_language_attributes( 'html' ); $url = esc_xml( __( 'URL' ) ); $lastmod = esc_xml( __( 'Last Modified' ) ); $xsl_content = << {$title}

{$title}

{$description}

{$learn_more}

{$text}

{$url} {$lastmod}
XSL; /** * Filters the content of the sitemap index stylesheet. * * @since 5.5.0 * * @param string $xsl_content Full content for the XML stylesheet. */ return apply_filters( 'wp_sitemaps_stylesheet_index_content', $xsl_content ); } /** * Gets the CSS to be included in sitemap XSL stylesheets. * * @since 5.5.0 * * @return string The CSS. */ public function get_stylesheet_css() { $text_align = is_rtl() ? 'right' : 'left'; $css = <<registry = new WP_Sitemaps_Registry(); $this->renderer = new WP_Sitemaps_Renderer(); $this->index = new WP_Sitemaps_Index( $this->registry ); } /** * Initiates all sitemap functionality. * * If sitemaps are disabled, only the rewrite rules will be registered * by this method, in order to properly send 404s. * * @since 5.5.0 */ public function init() { // These will all fire on the init hook. $this->register_rewrites(); add_action( 'template_redirect', array( $this, 'render_sitemaps' ) ); if ( ! $this->sitemaps_enabled() ) { return; } $this->register_sitemaps(); // Add additional action callbacks. add_filter( 'robots_txt', array( $this, 'add_robots' ), 0, 2 ); } /** * Determines whether sitemaps are enabled or not. * * @since 5.5.0 * * @return bool Whether sitemaps are enabled. */ public function sitemaps_enabled() { $is_enabled = (bool) get_option( 'blog_public' ); /** * Filters whether XML Sitemaps are enabled or not. * * When XML Sitemaps are disabled via this filter, rewrite rules are still * in place to ensure a 404 is returned. * * @see WP_Sitemaps::register_rewrites() * * @since 5.5.0 * * @param bool $is_enabled Whether XML Sitemaps are enabled or not. * Defaults to true for public sites. */ return (bool) apply_filters( 'wp_sitemaps_enabled', $is_enabled ); } /** * Registers and sets up the functionality for all supported sitemaps. * * @since 5.5.0 */ public function register_sitemaps() { $providers = array( 'posts' => new WP_Sitemaps_Posts(), 'taxonomies' => new WP_Sitemaps_Taxonomies(), 'users' => new WP_Sitemaps_Users(), ); /* @var WP_Sitemaps_Provider $provider */ foreach ( $providers as $name => $provider ) { $this->registry->add_provider( $name, $provider ); } } /** * Registers sitemap rewrite tags and routing rules. * * @since 5.5.0 */ public function register_rewrites() { // Add rewrite tags. add_rewrite_tag( '%sitemap%', '([^?]+)' ); add_rewrite_tag( '%sitemap-subtype%', '([^?]+)' ); // Register index route. add_rewrite_rule( '^wp-sitemap\.xml$', 'index.php?sitemap=index', 'top' ); // Register rewrites for the XSL stylesheet. add_rewrite_tag( '%sitemap-stylesheet%', '([^?]+)' ); add_rewrite_rule( '^wp-sitemap\.xsl$', 'index.php?sitemap-stylesheet=sitemap', 'top' ); add_rewrite_rule( '^wp-sitemap-index\.xsl$', 'index.php?sitemap-stylesheet=index', 'top' ); // Register routes for providers. add_rewrite_rule( '^wp-sitemap-([a-z]+?)-([a-z\d_-]+?)-(\d+?)\.xml$', 'index.php?sitemap=$matches[1]&sitemap-subtype=$matches[2]&paged=$matches[3]', 'top' ); add_rewrite_rule( '^wp-sitemap-([a-z]+?)-(\d+?)\.xml$', 'index.php?sitemap=$matches[1]&paged=$matches[2]', 'top' ); } /** * Renders sitemap templates based on rewrite rules. * * @since 5.5.0 * * @global WP_Query $wp_query WordPress Query object. */ public function render_sitemaps() { global $wp_query; $sitemap = sanitize_text_field( get_query_var( 'sitemap' ) ); $object_subtype = sanitize_text_field( get_query_var( 'sitemap-subtype' ) ); $stylesheet_type = sanitize_text_field( get_query_var( 'sitemap-stylesheet' ) ); $paged = absint( get_query_var( 'paged' ) ); // Bail early if this isn't a sitemap or stylesheet route. if ( ! ( $sitemap || $stylesheet_type ) ) { return; } if ( ! $this->sitemaps_enabled() ) { $wp_query->set_404(); status_header( 404 ); return; } // Render stylesheet if this is stylesheet route. if ( $stylesheet_type ) { $stylesheet = new WP_Sitemaps_Stylesheet(); $stylesheet->render_stylesheet( $stylesheet_type ); exit; } // Render the index. if ( 'index' === $sitemap ) { $sitemap_list = $this->index->get_sitemap_list(); $this->renderer->render_index( $sitemap_list ); exit; } $provider = $this->registry->get_provider( $sitemap ); if ( ! $provider ) { return; } if ( empty( $paged ) ) { $paged = 1; } $url_list = $provider->get_url_list( $paged, $object_subtype ); // Force a 404 and bail early if no URLs are present. if ( empty( $url_list ) ) { $wp_query->set_404(); status_header( 404 ); return; } $this->renderer->render_sitemap( $url_list ); exit; } /** * Redirects a URL to the wp-sitemap.xml * * @since 5.5.0 * @deprecated 6.7.0 Deprecated in favor of {@see WP_Rewrite::rewrite_rules()} * * @param bool $bypass Pass-through of the pre_handle_404 filter value. * @param WP_Query $query The WP_Query object. * @return bool Bypass value. */ public function redirect_sitemapxml( $bypass, $query ) { _deprecated_function( __FUNCTION__, '6.7.0' ); // If a plugin has already utilized the pre_handle_404 function, return without action to avoid conflicts. if ( $bypass ) { return $bypass; } // 'pagename' is for most permalink types, name is for when the %postname% is used as a top-level field. if ( 'sitemap-xml' === $query->get( 'pagename' ) || 'sitemap-xml' === $query->get( 'name' ) ) { wp_safe_redirect( $this->index->get_index_url() ); exit(); } return $bypass; } /** * Adds the sitemap index to robots.txt. * * @since 5.5.0 * * @param string $output robots.txt output. * @param bool $is_public Whether the site is public. * @return string The robots.txt output. */ public function add_robots( $output, $is_public ) { if ( $is_public ) { $output .= "\nSitemap: " . esc_url( $this->index->get_index_url() ) . "\n"; } return $output; } } class-wp-sitemaps-index.php000064400000003732151202370330011737 0ustar00registry = $registry; } /** * Gets a sitemap list for the index. * * @since 5.5.0 * * @return array[] Array of all sitemaps. */ public function get_sitemap_list() { $sitemaps = array(); $providers = $this->registry->get_providers(); /* @var WP_Sitemaps_Provider $provider */ foreach ( $providers as $name => $provider ) { $sitemap_entries = $provider->get_sitemap_entries(); // Prevent issues with array_push and empty arrays on PHP < 7.3. if ( ! $sitemap_entries ) { continue; } // Using array_push is more efficient than array_merge in a loop. array_push( $sitemaps, ...$sitemap_entries ); if ( count( $sitemaps ) >= $this->max_sitemaps ) { break; } } return array_slice( $sitemaps, 0, $this->max_sitemaps, true ); } /** * Builds the URL for the sitemap index. * * @since 5.5.0 * * @global WP_Rewrite $wp_rewrite WordPress rewrite component. * * @return string The sitemap index URL. */ public function get_index_url() { global $wp_rewrite; if ( ! $wp_rewrite->using_permalinks() ) { return home_url( '/?sitemap=index' ); } return home_url( '/wp-sitemap.xml' ); } } class-wp-sitemaps-registry.php000064400000003616151202370330012501 0ustar00providers[ $name ] ) ) { return false; } /** * Filters the sitemap provider before it is added. * * @since 5.5.0 * * @param WP_Sitemaps_Provider $provider Instance of a WP_Sitemaps_Provider. * @param string $name Name of the sitemap provider. */ $provider = apply_filters( 'wp_sitemaps_add_provider', $provider, $name ); if ( ! $provider instanceof WP_Sitemaps_Provider ) { return false; } $this->providers[ $name ] = $provider; return true; } /** * Returns a single registered sitemap provider. * * @since 5.5.0 * * @param string $name Sitemap provider name. * @return WP_Sitemaps_Provider|null Sitemap provider if it exists, null otherwise. */ public function get_provider( $name ) { if ( ! is_string( $name ) || ! isset( $this->providers[ $name ] ) ) { return null; } return $this->providers[ $name ]; } /** * Returns all registered sitemap providers. * * @since 5.5.0 * * @return WP_Sitemaps_Provider[] Array of sitemap providers. */ public function get_providers() { return $this->providers; } }