run:R W Run
7.33 KB
2026-03-11 16:18:51
R W Run
5.77 KB
2026-03-11 16:18:51
R W Run
4.09 KB
2026-03-11 16:18:51
R W Run
error_log
📄class-wp-sitemaps-users.php
1<?php
2/**
3 * Sitemaps: WP_Sitemaps_Users class
4 *
5 * Builds the sitemaps for the 'user' object type.
6 *
7 * @package WordPress
8 * @subpackage Sitemaps
9 * @since 5.5.0
10 */
11
12/**
13 * Users XML sitemap provider.
14 *
15 * @since 5.5.0
16 */
17class WP_Sitemaps_Users extends WP_Sitemaps_Provider {
18 /**
19 * WP_Sitemaps_Users constructor.
20 *
21 * @since 5.5.0
22 */
23 public function __construct() {
24 $this->name = 'users';
25 $this->object_type = 'user';
26 }
27
28 /**
29 * Gets a URL list for a user sitemap.
30 *
31 * @since 5.5.0
32 *
33 * @param int $page_num Page of results.
34 * @param string $object_subtype Optional. Not applicable for Users but
35 * required for compatibility with the parent
36 * provider class. Default empty.
37 * @return array[] Array of URL information for a sitemap.
38 */
39 public function get_url_list( $page_num, $object_subtype = '' ) {
40 /**
41 * Filters the users URL list before it is generated.
42 *
43 * Returning a non-null value will effectively short-circuit the generation,
44 * returning that value instead.
45 *
46 * @since 5.5.0
47 *
48 * @param array[]|null $url_list The URL list. Default null.
49 * @param int $page_num Page of results.
50 */
51 $url_list = apply_filters(
52 'wp_sitemaps_users_pre_url_list',
53 null,
54 $page_num
55 );
56
57 if ( null !== $url_list ) {
58 return $url_list;
59 }
60
61 $args = $this->get_users_query_args();
62 $args['paged'] = $page_num;
63
64 $query = new WP_User_Query( $args );
65 $users = $query->get_results();
66 $url_list = array();
67
68 foreach ( $users as $user ) {
69 $sitemap_entry = array(
70 'loc' => get_author_posts_url( $user->ID ),
71 );
72
73 /**
74 * Filters the sitemap entry for an individual user.
75 *
76 * @since 5.5.0
77 *
78 * @param array $sitemap_entry Sitemap entry for the user.
79 * @param WP_User $user User object.
80 */
81 $sitemap_entry = apply_filters( 'wp_sitemaps_users_entry', $sitemap_entry, $user );
82 $url_list[] = $sitemap_entry;
83 }
84
85 return $url_list;
86 }
87
88 /**
89 * Gets the max number of pages available for the object type.
90 *
91 * @since 5.5.0
92 *
93 * @see WP_Sitemaps_Provider::max_num_pages
94 *
95 * @param string $object_subtype Optional. Not applicable for Users but
96 * required for compatibility with the parent
97 * provider class. Default empty.
98 * @return int Total page count.
99 */
100 public function get_max_num_pages( $object_subtype = '' ) {
101 /**
102 * Filters the max number of pages for a user sitemap before it is generated.
103 *
104 * Returning a non-null value will effectively short-circuit the generation,
105 * returning that value instead.
106 *
107 * @since 5.5.0
108 *
109 * @param int|null $max_num_pages The maximum number of pages. Default null.
110 */
111 $max_num_pages = apply_filters( 'wp_sitemaps_users_pre_max_num_pages', null );
112
113 if ( null !== $max_num_pages ) {
114 return $max_num_pages;
115 }
116
117 $args = $this->get_users_query_args();
118 $query = new WP_User_Query( $args );
119
120 $total_users = $query->get_total();
121
122 return (int) ceil( $total_users / wp_sitemaps_get_max_urls( $this->object_type ) );
123 }
124
125 /**
126 * Returns the query args for retrieving users to list in the sitemap.
127 *
128 * @since 5.5.0
129 *
130 * @return array Array of WP_User_Query arguments.
131 */
132 protected function get_users_query_args() {
133 $public_post_types = get_post_types(
134 array(
135 'public' => true,
136 )
137 );
138
139 // We're not supporting sitemaps for author pages for attachments and pages.
140 unset( $public_post_types['attachment'] );
141 unset( $public_post_types['page'] );
142
143 /**
144 * Filters the query arguments for authors with public posts.
145 *
146 * Allows modification of the authors query arguments before querying.
147 *
148 * @see WP_User_Query for a full list of arguments
149 *
150 * @since 5.5.0
151 *
152 * @param array $args Array of WP_User_Query arguments.
153 */
154 $args = apply_filters(
155 'wp_sitemaps_users_query_args',
156 array(
157 'has_published_posts' => array_keys( $public_post_types ),
158 'number' => wp_sitemaps_get_max_urls( $this->object_type ),
159 )
160 );
161
162 return $args;
163 }
164}
165