PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.1
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.1
16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 All 504 releases
← All changes | modules/sitemaps/sitemaps.php +77 -65 12.7.316.3-a.1 View file →
@@ -30,11 +30,23 @@
30 30 * @since 4.8.0 Remove 1000 post limit.
31 31 * @author Automattic
32 32 */
33 33
34 +if ( ! defined( 'ABSPATH' ) ) {
35 + exit( 0 );
36 +}
37 +
34 38 /* Include all of the sitemap subclasses. */
35 39 require_once __DIR__ . '/sitemap-constants.php';
36 40 require_once __DIR__ . '/sitemap-buffer.php';
41 +require_once __DIR__ . '/sitemap-buffer-fallback.php';
42 +require_once __DIR__ . '/sitemap-buffer-xmlwriter.php';
43 +require_once __DIR__ . '/sitemap-buffer-page-xmlwriter.php';
44 +require_once __DIR__ . '/sitemap-buffer-image-xmlwriter.php';
45 +require_once __DIR__ . '/sitemap-buffer-video-xmlwriter.php';
46 +require_once __DIR__ . '/sitemap-buffer-news-xmlwriter.php';
47 +require_once __DIR__ . '/sitemap-buffer-master-xmlwriter.php';
48 +require_once __DIR__ . '/sitemap-buffer-factory.php';
37 49 require_once __DIR__ . '/sitemap-stylist.php';
38 50 require_once __DIR__ . '/sitemap-librarian.php';
39 51 require_once __DIR__ . '/sitemap-finder.php';
40 52 require_once __DIR__ . '/sitemap-builder.php';
@@ -48,8 +60,10 @@
48 60 /**
49 61 * Governs the generation, storage, and serving of sitemaps.
50 62 *
51 63 * @since 4.8.0
64 + *
65 + * @phan-constructor-used-for-side-effects
52 66 */
53 67 class Jetpack_Sitemap_Manager {
54 68
55 69 /**
@@ -94,9 +108,9 @@
94 108 }
95 109
96 110 // Add callback for sitemap URL handler.
97 111 add_action(
98 - 'init',
112 + 'wp_loaded',
99 113 array( $this, 'callback_action_catch_sitemap_urls' ),
100 114 defined( 'IS_WPCOM' ) && IS_WPCOM ? 100 : 10
101 115 );
102 116
@@ -146,8 +160,9 @@
146 160 * @since 4.8.0
147 161 *
148 162 * @param string $the_content_type The content type to be served.
149 163 * @param string $the_content The string to be echoed.
164 + * @return never
150 165 */
151 166 private function serve_raw_and_die( $the_content_type, $the_content ) {
152 167 header( 'Content-Type: ' . $the_content_type . '; charset=UTF-8' );
153 168
@@ -173,9 +188,9 @@
173 188 }
174 189
175 190 echo $the_content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- All content created by Jetpack.
176 191
177 - die();
192 + die( 0 );
178 193 }
179 194
180 195 /**
181 196 * Callback to intercept sitemap url requests and serve sitemap files.
@@ -185,21 +200,14 @@
185 200 */
186 201 public function callback_action_catch_sitemap_urls() {
187 202 // Regular expressions for sitemap URL routing.
188 203 $regex = array(
189 - 'master' => '/^sitemap\.xml$/',
190 - 'sitemap' => '/^sitemap-[1-9][0-9]*\.xml$/',
191 - 'index' => '/^sitemap-index-[1-9][0-9]*\.xml$/',
192 - 'sitemap-style' => '/^sitemap\.xsl$/',
193 - 'index-style' => '/^sitemap-index\.xsl$/',
194 - 'image' => '/^image-sitemap-[1-9][0-9]*\.xml$/',
195 - 'image-index' => '/^image-sitemap-index-[1-9][0-9]*\.xml$/',
196 - 'image-style' => '/^image-sitemap\.xsl$/',
197 - 'video' => '/^video-sitemap-[1-9][0-9]*\.xml$/',
198 - 'video-index' => '/^video-sitemap-index-[1-9][0-9]*\.xml$/',
199 - 'video-style' => '/^video-sitemap\.xsl$/',
200 - 'news' => '/^news-sitemap\.xml$/',
201 - 'news-style' => '/^news-sitemap\.xsl$/',
204 + 'sitemap' => '/^sitemap-[1-9][0-9]*\.xml$/',
205 + 'index' => '/^sitemap-index-[1-9][0-9]*\.xml$/',
206 + 'image' => '/^image-sitemap-[1-9][0-9]*\.xml$/',
207 + 'image-index' => '/^image-sitemap-index-[1-9][0-9]*\.xml$/',
208 + 'video' => '/^video-sitemap-[1-9][0-9]*\.xml$/',
209 + 'video-index' => '/^video-sitemap-index-[1-9][0-9]*\.xml$/',
202 210 );
203 211
204 212 // The raw path(+query) of the requested URI.
205 213 if ( isset( $_SERVER['REQUEST_URI'] ) ) { // WPCS: Input var okay.
@@ -225,9 +233,9 @@
225 233 */
226 234 $xml_content_type = apply_filters( 'jetpack_sitemap_content_type', 'text/xml' );
227 235
228 236 // Catch master sitemap xml.
229 - if ( preg_match( $regex['master'], $request['sitemap_name'] ) ) {
237 + if ( 'sitemap.xml' === $request['sitemap_name'] ) {
230 238 $sitemap_content = $this->librarian->get_sitemap_text(
231 239 jp_sitemap_filename( JP_MASTER_SITEMAP_TYPE, 0 ),
232 240 JP_MASTER_SITEMAP_TYPE
233 241 );
@@ -243,8 +251,57 @@
243 251 $sitemap_content
244 252 );
245 253 }
246 254
255 + // Catch sitemap xsl.
256 + if ( 'sitemap.xsl' === $request['sitemap_name'] ) {
257 + $this->serve_raw_and_die(
258 + 'application/xml',
259 + Jetpack_Sitemap_Stylist::sitemap_xsl()
260 + );
261 + }
262 +
263 + // Catch sitemap index xsl.
264 + if ( 'sitemap-index.xsl' === $request['sitemap_name'] ) {
265 + $this->serve_raw_and_die(
266 + 'application/xml',
267 + Jetpack_Sitemap_Stylist::sitemap_index_xsl()
268 + );
269 + }
270 +
271 + // Catch image sitemap xsl.
272 + if ( 'image-sitemap.xsl' === $request['sitemap_name'] ) {
273 + $this->serve_raw_and_die(
274 + 'application/xml',
275 + Jetpack_Sitemap_Stylist::image_sitemap_xsl()
276 + );
277 + }
278 +
279 + // Catch video sitemap xsl.
280 + if ( 'video-sitemap.xsl' === $request['sitemap_name'] ) {
281 + $this->serve_raw_and_die(
282 + 'application/xml',
283 + Jetpack_Sitemap_Stylist::video_sitemap_xsl()
284 + );
285 + }
286 +
287 + // Catch news sitemap xml.
288 + if ( 'news-sitemap.xml' === $request['sitemap_name'] ) {
289 + $sitemap_builder = new Jetpack_Sitemap_Builder();
290 + $this->serve_raw_and_die(
291 + $xml_content_type,
292 + $sitemap_builder->news_sitemap_xml()
293 + );
294 + }
295 +
296 + // Catch news sitemap xsl.
297 + if ( 'news-sitemap.xsl' === $request['sitemap_name'] ) {
298 + $this->serve_raw_and_die(
299 + 'application/xml',
300 + Jetpack_Sitemap_Stylist::news_sitemap_xsl()
301 + );
302 + }
303 +
247 304 // Catch sitemap xml.
248 305 if ( preg_match( $regex['sitemap'], $request['sitemap_name'] ) ) {
249 306 $this->serve_raw_and_die(
250 307 $xml_content_type,
@@ -265,24 +322,8 @@
265 322 )
266 323 );
267 324 }
268 325
269 - // Catch sitemap xsl.
270 - if ( preg_match( $regex['sitemap-style'], $request['sitemap_name'] ) ) {
271 - $this->serve_raw_and_die(
272 - 'application/xml',
273 - Jetpack_Sitemap_Stylist::sitemap_xsl()
274 - );
275 - }
276 -
277 - // Catch sitemap index xsl.
278 - if ( preg_match( $regex['index-style'], $request['sitemap_name'] ) ) {
279 - $this->serve_raw_and_die(
280 - 'application/xml',
281 - Jetpack_Sitemap_Stylist::sitemap_index_xsl()
282 - );
283 - }
284 -
285 326 // Catch image sitemap xml.
286 327 if ( preg_match( $regex['image'], $request['sitemap_name'] ) ) {
287 328 $this->serve_raw_and_die(
288 329 $xml_content_type,
@@ -303,16 +344,8 @@
303 344 )
304 345 );
305 346 }
306 347
307 - // Catch image sitemap xsl.
308 - if ( preg_match( $regex['image-style'], $request['sitemap_name'] ) ) {
309 - $this->serve_raw_and_die(
310 - 'application/xml',
311 - Jetpack_Sitemap_Stylist::image_sitemap_xsl()
312 - );
313 - }
314 -
315 348 // Catch video sitemap xml.
316 349 if ( preg_match( $regex['video'], $request['sitemap_name'] ) ) {
317 350 $this->serve_raw_and_die(
318 351 $xml_content_type,
@@ -332,33 +365,8 @@
332 365 JP_VIDEO_SITEMAP_INDEX_TYPE
333 366 )
334 367 );
335 368 }
336 -
337 - // Catch video sitemap xsl.
338 - if ( preg_match( $regex['video-style'], $request['sitemap_name'] ) ) {
339 - $this->serve_raw_and_die(
340 - 'application/xml',
341 - Jetpack_Sitemap_Stylist::video_sitemap_xsl()
342 - );
343 - }
344 -
345 - // Catch news sitemap xml.
346 - if ( preg_match( $regex['news'], $request['sitemap_name'] ) ) {
347 - $sitemap_builder = new Jetpack_Sitemap_Builder();
348 - $this->serve_raw_and_die(
349 - $xml_content_type,
350 - $sitemap_builder->news_sitemap_xml()
351 - );
352 - }
353 -
354 - // Catch news sitemap xsl.
355 - if ( preg_match( $regex['news-style'], $request['sitemap_name'] ) ) {
356 - $this->serve_raw_and_die(
357 - 'application/xml',
358 - Jetpack_Sitemap_Stylist::news_sitemap_xsl()
359 - );
360 - }
361 369 }
362 370 }
363 371
364 372 /**
@@ -598,4 +606,8 @@
598 606 * @param string $sitemap_url Sitemap URL.
599 607 */
600 608 return apply_filters( 'jetpack_sitemap_location', $sitemap_url );
601 609 }
610 +
611 +// Register Jetpack Sitemaps abilities (WordPress Abilities API, WP 6.9+).
612 +require_once __DIR__ . '/abilities/class-sitemaps-abilities.php';
613 +\Automattic\Jetpack\Plugin\Abilities\Sitemaps_Abilities::init();