mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 20:30:23 +00:00
Sitemaps: Prevent incorrect redirection of paged sitemap requests.
Update `redirect_canonical()` to account for custom pagination and URL format used by sitemaps in order to follow standard practices. Introduce the function `get_sitemap_url()` to simplify getting the index and provider URLs as needed. Props jonathanstegall, pbiron, GamerZ, salvoaranzulla, peterwilsoncc. Fixes #50910. git-svn-id: https://develop.svn.wordpress.org/trunk@48872 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -87,3 +87,39 @@ function wp_sitemaps_get_max_urls( $object_type ) {
|
||||
*/
|
||||
return apply_filters( 'wp_sitemaps_max_urls', 2000, $object_type );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the full URL for a sitemap.
|
||||
*
|
||||
* @since 5.5.1
|
||||
*
|
||||
* @param string $name The sitemap name.
|
||||
* @param string $subtype_name The sitemap subtype name. Default empty string.
|
||||
* @param int $page The page of the sitemap. Default 1.
|
||||
* @return string|false The sitemap URL or false if the sitemap doesn't exist.
|
||||
*/
|
||||
function get_sitemap_url( $name, $subtype_name = '', $page = 1 ) {
|
||||
$sitemaps = wp_sitemaps_get_server();
|
||||
if ( ! $sitemaps ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( 'index' === $name ) {
|
||||
return $sitemaps->index->get_index_url();
|
||||
}
|
||||
|
||||
$provider = $sitemaps->registry->get_provider( $name );
|
||||
if ( ! $provider ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( $subtype_name && ! in_array( $subtype_name, array_keys( $provider->get_object_subtypes() ), true ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$page = absint( $page );
|
||||
if ( 0 >= $page ) {
|
||||
$page = 1;
|
||||
}
|
||||
return $provider->get_sitemap_url( $subtype_name, $page );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user