Sitemaps: Add XML sitemaps functionality to WordPress.
While web crawlers are able to discover pages from links within the site and from other sites, XML sitemaps supplement this approach by allowing crawlers to quickly and comprehensively identify all URLs included in the sitemap and learn other signals about those URLs using the associated metadata.
See https://make.wordpress.org/core/2020/06/10/merge-announcement-extensible-core-sitemaps/ for more details.
This feature exposes the sitemap index via `/wp-sitemap.xml` and exposes a variety of new filters and hooks for developers to modify the behavior. Users can disable sitemaps completely by turning off search engine visibility in WordPress admin.
This change also introduces a new `esc_xml()` function to escape strings for output in XML, as well as XML support to `wp_kses_normalize_entities()`.
Props Adrian McShane, afragen, adamsilverstein, casiepa, flixos90, garrett-eclipse, joemcgill, kburgoine, kraftbj, milana_cap, pacifika, pbiron, pfefferle, Ruxandra Gradina, swissspidy, szepeviktor, tangrufus, tweetythierry.
Fixes #50117.
See #3670. See #19998.
Built from https://develop.svn.wordpress.org/trunk@48072
git-svn-id: http://core.svn.wordpress.org/trunk@47839 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-06-17 17:24:07 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Sitemaps: WP_Sitemaps_Users class
|
|
|
|
*
|
|
|
|
* Builds the sitemaps for the 'user' object type.
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Sitemaps
|
|
|
|
* @since 5.5.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Users XML sitemap provider.
|
|
|
|
*
|
|
|
|
* @since 5.5.0
|
|
|
|
*/
|
|
|
|
class WP_Sitemaps_Users extends WP_Sitemaps_Provider {
|
|
|
|
/**
|
|
|
|
* WP_Sitemaps_Users constructor.
|
|
|
|
*
|
|
|
|
* @since 5.5.0
|
|
|
|
*/
|
|
|
|
public function __construct() {
|
|
|
|
$this->name = '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.
|
2021-11-18 14:50:05 +01:00
|
|
|
* @return array[] Array of URL information for a sitemap.
|
Sitemaps: Add XML sitemaps functionality to WordPress.
While web crawlers are able to discover pages from links within the site and from other sites, XML sitemaps supplement this approach by allowing crawlers to quickly and comprehensively identify all URLs included in the sitemap and learn other signals about those URLs using the associated metadata.
See https://make.wordpress.org/core/2020/06/10/merge-announcement-extensible-core-sitemaps/ for more details.
This feature exposes the sitemap index via `/wp-sitemap.xml` and exposes a variety of new filters and hooks for developers to modify the behavior. Users can disable sitemaps completely by turning off search engine visibility in WordPress admin.
This change also introduces a new `esc_xml()` function to escape strings for output in XML, as well as XML support to `wp_kses_normalize_entities()`.
Props Adrian McShane, afragen, adamsilverstein, casiepa, flixos90, garrett-eclipse, joemcgill, kburgoine, kraftbj, milana_cap, pacifika, pbiron, pfefferle, Ruxandra Gradina, swissspidy, szepeviktor, tangrufus, tweetythierry.
Fixes #50117.
See #3670. See #19998.
Built from https://develop.svn.wordpress.org/trunk@48072
git-svn-id: http://core.svn.wordpress.org/trunk@47839 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-06-17 17:24:07 +02:00
|
|
|
*/
|
|
|
|
public function get_url_list( $page_num, $object_subtype = '' ) {
|
|
|
|
/**
|
|
|
|
* Filters the users URL list before it is generated.
|
|
|
|
*
|
|
|
|
* Passing a non-null value will effectively short-circuit the generation,
|
|
|
|
* returning that value instead.
|
|
|
|
*
|
|
|
|
* @since 5.5.0
|
|
|
|
*
|
2021-11-18 14:50:05 +01:00
|
|
|
* @param array[]|null $url_list The URL list. Default null.
|
|
|
|
* @param int $page_num Page of results.
|
Sitemaps: Add XML sitemaps functionality to WordPress.
While web crawlers are able to discover pages from links within the site and from other sites, XML sitemaps supplement this approach by allowing crawlers to quickly and comprehensively identify all URLs included in the sitemap and learn other signals about those URLs using the associated metadata.
See https://make.wordpress.org/core/2020/06/10/merge-announcement-extensible-core-sitemaps/ for more details.
This feature exposes the sitemap index via `/wp-sitemap.xml` and exposes a variety of new filters and hooks for developers to modify the behavior. Users can disable sitemaps completely by turning off search engine visibility in WordPress admin.
This change also introduces a new `esc_xml()` function to escape strings for output in XML, as well as XML support to `wp_kses_normalize_entities()`.
Props Adrian McShane, afragen, adamsilverstein, casiepa, flixos90, garrett-eclipse, joemcgill, kburgoine, kraftbj, milana_cap, pacifika, pbiron, pfefferle, Ruxandra Gradina, swissspidy, szepeviktor, tangrufus, tweetythierry.
Fixes #50117.
See #3670. See #19998.
Built from https://develop.svn.wordpress.org/trunk@48072
git-svn-id: http://core.svn.wordpress.org/trunk@47839 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-06-17 17:24:07 +02:00
|
|
|
*/
|
|
|
|
$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 = '' ) {
|
|
|
|
/**
|
2021-11-18 14:50:05 +01:00
|
|
|
* Filters the max number of pages for a user sitemap before it is generated.
|
Sitemaps: Add XML sitemaps functionality to WordPress.
While web crawlers are able to discover pages from links within the site and from other sites, XML sitemaps supplement this approach by allowing crawlers to quickly and comprehensively identify all URLs included in the sitemap and learn other signals about those URLs using the associated metadata.
See https://make.wordpress.org/core/2020/06/10/merge-announcement-extensible-core-sitemaps/ for more details.
This feature exposes the sitemap index via `/wp-sitemap.xml` and exposes a variety of new filters and hooks for developers to modify the behavior. Users can disable sitemaps completely by turning off search engine visibility in WordPress admin.
This change also introduces a new `esc_xml()` function to escape strings for output in XML, as well as XML support to `wp_kses_normalize_entities()`.
Props Adrian McShane, afragen, adamsilverstein, casiepa, flixos90, garrett-eclipse, joemcgill, kburgoine, kraftbj, milana_cap, pacifika, pbiron, pfefferle, Ruxandra Gradina, swissspidy, szepeviktor, tangrufus, tweetythierry.
Fixes #50117.
See #3670. See #19998.
Built from https://develop.svn.wordpress.org/trunk@48072
git-svn-id: http://core.svn.wordpress.org/trunk@47839 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-06-17 17:24:07 +02:00
|
|
|
*
|
|
|
|
* Passing a non-null value will effectively short-circuit the generation,
|
|
|
|
* returning that value instead.
|
|
|
|
*
|
|
|
|
* @since 5.5.0
|
|
|
|
*
|
2021-11-18 14:50:05 +01:00
|
|
|
* @param int|null $max_num_pages The maximum number of pages. Default null.
|
Sitemaps: Add XML sitemaps functionality to WordPress.
While web crawlers are able to discover pages from links within the site and from other sites, XML sitemaps supplement this approach by allowing crawlers to quickly and comprehensively identify all URLs included in the sitemap and learn other signals about those URLs using the associated metadata.
See https://make.wordpress.org/core/2020/06/10/merge-announcement-extensible-core-sitemaps/ for more details.
This feature exposes the sitemap index via `/wp-sitemap.xml` and exposes a variety of new filters and hooks for developers to modify the behavior. Users can disable sitemaps completely by turning off search engine visibility in WordPress admin.
This change also introduces a new `esc_xml()` function to escape strings for output in XML, as well as XML support to `wp_kses_normalize_entities()`.
Props Adrian McShane, afragen, adamsilverstein, casiepa, flixos90, garrett-eclipse, joemcgill, kburgoine, kraftbj, milana_cap, pacifika, pbiron, pfefferle, Ruxandra Gradina, swissspidy, szepeviktor, tangrufus, tweetythierry.
Fixes #50117.
See #3670. See #19998.
Built from https://develop.svn.wordpress.org/trunk@48072
git-svn-id: http://core.svn.wordpress.org/trunk@47839 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-06-17 17:24:07 +02:00
|
|
|
*/
|
|
|
|
$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
|
|
|
|
*
|
2020-06-20 00:55:12 +02:00
|
|
|
* @return array Array of WP_User_Query arguments.
|
Sitemaps: Add XML sitemaps functionality to WordPress.
While web crawlers are able to discover pages from links within the site and from other sites, XML sitemaps supplement this approach by allowing crawlers to quickly and comprehensively identify all URLs included in the sitemap and learn other signals about those URLs using the associated metadata.
See https://make.wordpress.org/core/2020/06/10/merge-announcement-extensible-core-sitemaps/ for more details.
This feature exposes the sitemap index via `/wp-sitemap.xml` and exposes a variety of new filters and hooks for developers to modify the behavior. Users can disable sitemaps completely by turning off search engine visibility in WordPress admin.
This change also introduces a new `esc_xml()` function to escape strings for output in XML, as well as XML support to `wp_kses_normalize_entities()`.
Props Adrian McShane, afragen, adamsilverstein, casiepa, flixos90, garrett-eclipse, joemcgill, kburgoine, kraftbj, milana_cap, pacifika, pbiron, pfefferle, Ruxandra Gradina, swissspidy, szepeviktor, tangrufus, tweetythierry.
Fixes #50117.
See #3670. See #19998.
Built from https://develop.svn.wordpress.org/trunk@48072
git-svn-id: http://core.svn.wordpress.org/trunk@47839 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-06-17 17:24:07 +02:00
|
|
|
*/
|
|
|
|
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.
|
|
|
|
unset( $public_post_types['attachment'] );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
}
|