49 |
49 |
50 /** |
50 /** |
51 * Gets a URL list for a taxonomy sitemap. |
51 * Gets a URL list for a taxonomy sitemap. |
52 * |
52 * |
53 * @since 5.5.0 |
53 * @since 5.5.0 |
54 * |
54 * @since 5.9.0 Renamed `$taxonomy` to `$object_subtype` to match parent class |
55 * @param int $page_num Page of results. |
55 * for PHP 8 named parameter support. |
56 * @param string $taxonomy Optional. Taxonomy name. Default empty. |
56 * |
57 * @return array Array of URLs for a sitemap. |
57 * @param int $page_num Page of results. |
58 */ |
58 * @param string $object_subtype Optional. Taxonomy name. Default empty. |
59 public function get_url_list( $page_num, $taxonomy = '' ) { |
59 * @return array[] Array of URL information for a sitemap. |
|
60 */ |
|
61 public function get_url_list( $page_num, $object_subtype = '' ) { |
|
62 // Restores the more descriptive, specific name for use within this method. |
|
63 $taxonomy = $object_subtype; |
60 $supported_types = $this->get_object_subtypes(); |
64 $supported_types = $this->get_object_subtypes(); |
61 |
65 |
62 // Bail early if the queried taxonomy is not supported. |
66 // Bail early if the queried taxonomy is not supported. |
63 if ( ! isset( $supported_types[ $taxonomy ] ) ) { |
67 if ( ! isset( $supported_types[ $taxonomy ] ) ) { |
64 return array(); |
68 return array(); |
65 } |
69 } |
66 |
70 |
67 /** |
71 /** |
68 * Filters the taxonomies URL list before it is generated. |
72 * Filters the taxonomies URL list before it is generated. |
69 * |
73 * |
70 * Passing a non-null value will effectively short-circuit the generation, |
74 * Returning a non-null value will effectively short-circuit the generation, |
71 * returning that value instead. |
75 * returning that value instead. |
72 * |
76 * |
73 * @since 5.5.0 |
77 * @since 5.5.0 |
74 * |
78 * |
75 * @param array $url_list The URL list. Default null. |
79 * @param array[]|null $url_list The URL list. Default null. |
76 * @param string $taxonomy Taxonomy name. |
80 * @param string $taxonomy Taxonomy name. |
77 * @param int $page_num Page of results. |
81 * @param int $page_num Page of results. |
78 */ |
82 */ |
79 $url_list = apply_filters( |
83 $url_list = apply_filters( |
80 'wp_sitemaps_taxonomies_pre_url_list', |
84 'wp_sitemaps_taxonomies_pre_url_list', |
81 null, |
85 null, |
82 $taxonomy, |
86 $taxonomy, |
91 |
95 |
92 // Offset by how many terms should be included in previous pages. |
96 // Offset by how many terms should be included in previous pages. |
93 $offset = ( $page_num - 1 ) * wp_sitemaps_get_max_urls( $this->object_type ); |
97 $offset = ( $page_num - 1 ) * wp_sitemaps_get_max_urls( $this->object_type ); |
94 |
98 |
95 $args = $this->get_taxonomies_query_args( $taxonomy ); |
99 $args = $this->get_taxonomies_query_args( $taxonomy ); |
|
100 $args['fields'] = 'all'; |
96 $args['offset'] = $offset; |
101 $args['offset'] = $offset; |
97 |
102 |
98 $taxonomy_terms = new WP_Term_Query( $args ); |
103 $taxonomy_terms = new WP_Term_Query( $args ); |
99 |
104 |
100 if ( ! empty( $taxonomy_terms->terms ) ) { |
105 if ( ! empty( $taxonomy_terms->terms ) ) { |
111 |
116 |
112 /** |
117 /** |
113 * Filters the sitemap entry for an individual term. |
118 * Filters the sitemap entry for an individual term. |
114 * |
119 * |
115 * @since 5.5.0 |
120 * @since 5.5.0 |
|
121 * @since 6.0.0 Added `$term` argument containing the term object. |
116 * |
122 * |
117 * @param array $sitemap_entry Sitemap entry for the term. |
123 * @param array $sitemap_entry Sitemap entry for the term. |
|
124 * @param int $term_id Term ID. |
|
125 * @param string $taxonomy Taxonomy name. |
118 * @param WP_Term $term Term object. |
126 * @param WP_Term $term Term object. |
119 * @param string $taxonomy Taxonomy name. |
|
120 */ |
127 */ |
121 $sitemap_entry = apply_filters( 'wp_sitemaps_taxonomies_entry', $sitemap_entry, $term, $taxonomy ); |
128 $sitemap_entry = apply_filters( 'wp_sitemaps_taxonomies_entry', $sitemap_entry, $term->term_id, $taxonomy, $term ); |
122 $url_list[] = $sitemap_entry; |
129 $url_list[] = $sitemap_entry; |
123 } |
130 } |
124 } |
131 } |
125 |
132 |
126 return $url_list; |
133 return $url_list; |
128 |
135 |
129 /** |
136 /** |
130 * Gets the max number of pages available for the object type. |
137 * Gets the max number of pages available for the object type. |
131 * |
138 * |
132 * @since 5.5.0 |
139 * @since 5.5.0 |
133 * |
140 * @since 5.9.0 Renamed `$taxonomy` to `$object_subtype` to match parent class |
134 * @param string $taxonomy Taxonomy name. |
141 * for PHP 8 named parameter support. |
|
142 * |
|
143 * @param string $object_subtype Optional. Taxonomy name. Default empty. |
135 * @return int Total number of pages. |
144 * @return int Total number of pages. |
136 */ |
145 */ |
137 public function get_max_num_pages( $taxonomy = '' ) { |
146 public function get_max_num_pages( $object_subtype = '' ) { |
138 if ( empty( $taxonomy ) ) { |
147 if ( empty( $object_subtype ) ) { |
139 return 0; |
148 return 0; |
140 } |
149 } |
141 |
150 |
142 /** |
151 // Restores the more descriptive, specific name for use within this method. |
143 * Filters the max number of pages before it is generated. |
152 $taxonomy = $object_subtype; |
|
153 |
|
154 /** |
|
155 * Filters the max number of pages for a taxonomy sitemap before it is generated. |
144 * |
156 * |
145 * Passing a non-null value will short-circuit the generation, |
157 * Passing a non-null value will short-circuit the generation, |
146 * returning that value instead. |
158 * returning that value instead. |
147 * |
159 * |
148 * @since 5.5.0 |
160 * @since 5.5.0 |
149 * |
161 * |
150 * @param int $max_num_pages The maximum number of pages. Default null. |
162 * @param int|null $max_num_pages The maximum number of pages. Default null. |
151 * @param string $taxonomy Taxonomy name. |
163 * @param string $taxonomy Taxonomy name. |
152 */ |
164 */ |
153 $max_num_pages = apply_filters( 'wp_sitemaps_taxonomies_pre_max_num_pages', null, $taxonomy ); |
165 $max_num_pages = apply_filters( 'wp_sitemaps_taxonomies_pre_max_num_pages', null, $taxonomy ); |
154 |
166 |
155 if ( null !== $max_num_pages ) { |
167 if ( null !== $max_num_pages ) { |
156 return $max_num_pages; |
168 return $max_num_pages; |
183 * @param string $taxonomy Taxonomy name. |
195 * @param string $taxonomy Taxonomy name. |
184 */ |
196 */ |
185 $args = apply_filters( |
197 $args = apply_filters( |
186 'wp_sitemaps_taxonomies_query_args', |
198 'wp_sitemaps_taxonomies_query_args', |
187 array( |
199 array( |
188 'fields' => 'ids', |
|
189 'taxonomy' => $taxonomy, |
200 'taxonomy' => $taxonomy, |
190 'orderby' => 'term_order', |
201 'orderby' => 'term_order', |
191 'number' => wp_sitemaps_get_max_urls( $this->object_type ), |
202 'number' => wp_sitemaps_get_max_urls( $this->object_type ), |
192 'hide_empty' => true, |
203 'hide_empty' => true, |
193 'hierarchical' => false, |
204 'hierarchical' => false, |