PluginProbe ʕ •ᴥ•ʔ
Jetpack – WP Security, Backup, Speed, & Growth / 13.3.3
Jetpack – WP Security, Backup, Speed, & Growth v13.3.3
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 14.1.1 14.2.2 14.3.1 14.4.2 14.5.1 14.6.1 14.7.1 14.8.1 14.9.2 15.0.3 15.1.2 15.2.1 15.3.2 15.4.1 15.5.1 15.6.1 15.7.2 15.8.1 15.9.2 16.0.2 16.1.3 16.2-a.5 16.2-a.3 16.1.2 16.2-a.1 16.1.1 16.1 16.1-beta 16.1-beta.2 16.1-beta.3 16.1-a.5 16.1-a.3 16.0.1 16.1-a.1 16.0 16.0-beta 16.0-a.7 16.0-a.5 15.9.1 16.0-a.3 16.0-a.1 15.9 15.9-beta 15.9-a.7 15.9-a.5 15.9-a.3 15.9-a.1 15.8 15.8-beta 15.8-a.7 15.8-a.5 5.2.5 5.3.4 5.4.4 5.5.5 5.6.5 5.7.5 5.8.4 5.9.4 6.0.4 6.1 6.1.1 6.1.2 6.1.3 6.1.4 6.1.5 6.2 6.2.1 6.2.2 6.2.3 6.2.4 6.2.5 6.3 6.3.1 6.3.2 6.3.3 6.3.4 6.3.5 6.3.6 6.3.7 6.4 6.4.1 6.4.2 6.4.3 6.4.4 6.4.5 6.4.6 6.5 6.5.1 6.5.2 6.5.3 6.5.4 6.6 6.6.1 6.6.2 6.6.3 6.6.4 6.6.5 6.7 6.7.1 6.7.2 6.7.3 6.7.4 6.8 6.8.1 6.8.2 6.8.3 6.8.4 6.8.5 6.9 6.9.1 6.9.2 6.9.3 6.9.4 7.0 7.0.1 7.0.2 7.0.3 7.0.4 7.0.5 7.1 7.1.1 7.1.2 7.1.3 7.1.4 7.1.5 7.2 7.2.1 7.2.1.1 7.2.2 7.2.3 7.2.4 7.2.5 7.3 7.3.0.1 7.3.1 7.3.1.1 7.3.2 7.3.3 7.3.4 7.3.5 7.4 7.4.1 7.4.2 7.4.3 7.4.4 7.4.5 7.5 7.5.0.1 7.5.1 7.5.2 7.5.3 7.5.4 7.5.5 7.5.6 7.5.7 7.6 7.6.1 7.6.2 7.6.3 7.6.4 7.7 7.7.1 7.7.2 7.7.3 7.7.4 7.7.5 7.7.6 7.8 7.8.1 7.8.2 7.8.3 7.8.4 7.9 7.9.1 7.9.2 7.9.3 7.9.4 8.0 8.0.1 8.0.2 8.0.3 8.1 8.1.1 8.1.2 8.1.3 8.1.4 8.2 8.2.0.1 8.2.1 8.2.2 8.2.3 8.2.4 8.2.5 8.2.6 8.3 8.3.1 8.3.2 8.3.3 8.4 8.4.1 8.4.2 8.4.3 8.4.4 8.4.5 8.5 8.5.1 8.5.2 8.5.3 8.6 8.6.1 8.6.2 8.6.3 8.6.4 8.7 8.7.0.1 8.7.1 8.7.2 8.7.3 8.7.4 8.8 8.8.1 8.8.2 8.8.3 8.8.4 8.8.5 8.9 8.9.1 8.9.2 8.9.3 8.9.4 9.0 9.0.1 9.0.2 9.0.3 9.0.4 9.0.5 9.1 9.1.1 9.1.2 9.1.3 9.2 9.2.1 9.2.2 9.2.3 9.2.4 9.3 9.3.1 9.3.2 9.3.3 9.3.4 9.3.5 9.4 9.4.1 9.4.2 9.4.3 9.4.4 9.5 9.5.1 9.5.2 9.5.3 9.5.4 9.5.5 9.6 9.6.1 9.6.2 9.6.3 9.6.4 9.7 9.7.1 9.7.2 15.7-beta.2 9.7.3 15.7.1 9.8 15.8-a.1 9.8.1 15.8-a.3 9.8.2 2.0.9 9.8.3 2.1.7 9.9 2.2.10 9.9.1 2.3.10 9.9.2 2.4.7 9.9.3 2.5.5 2.6.6 2.7.5 2.8.5 2.9.6 3.0.6 3.1.5 3.2.5 3.3.6 3.4.6 3.5.6 3.6.4 3.7.5 3.8.5 3.9.10 4.0.7 4.1.4 4.2.5 4.3.5 4.4.5 4.5.3 4.6.3 4.7.4 4.8.5 4.9.3 5.0.3 5.1.4 trunk 10.0 10.0.1 10.0.2 10.1 10.1.1 10.1.2 10.2 10.2.1 10.2.2 10.2.3 10.3 10.3.1 10.3.2 10.4 10.4.1 10.4.2 10.5 10.5.1 10.5.2 10.5.3 10.6 10.6.1 10.6.2 10.7 10.7.1 10.7.2 10.8 10.8.1 10.8.2 10.9 10.9.1 10.9.2 10.9.3 11.0 11.0.1 11.0.2 11.1 11.1.1 11.1.2 11.1.3 11.1.4 11.2 11.2.1 11.2.2 11.3 11.3.1 11.3.2 11.3.3 11.3.4 11.4 11.4.1 11.4.2 11.5 11.5.1 11.5.2 11.5.3 11.6 11.6.1 11.6.2 11.7 11.7.1 11.7.2 11.7.3 11.8 11.8.3 11.8.4 11.8.5 11.8.6 11.9 11.9.1 11.9.2 11.9.3 12.0 12.0.1 12.0.2 12.1 12.1.1 12.1.2 12.2 12.2.1 12.2.2 12.3 12.3.1 12.4 12.4.1 12.5 12.5.1 12.6 12.6.1 12.6.2 12.6.3 12.7 12.7.1 12.7.2 12.8 12.8.1 12.8.2 12.9 12.9.1 12.9.2 12.9.3 12.9.4 13.0 13.0.1 13.1 13.1.1 13.1.2 13.1.3 13.1.4 13.2 13.2.1 13.2.2 13.2.3 13.3 13.3.1 13.3.2 13.4 13.4.1 13.4.2 13.4.3 13.4.4 13.5 13.5.1 13.6 13.6.1 13.7 13.7.1 13.8 13.8.1 13.8.2 13.9 13.9.1 14.0 14.1 14.2 14.2.1 14.3 14.4 14.4.1 14.5 14.6 14.7 14.8 14.9 14.9.1 15.0 15.0.1 15.0.2 15.1 15.1.1 15.2 15.3 15.3.1 15.4 15.5 15.6 15.7 15.7-a.1 15.7-a.3 15.7-a.5 15.7-a.7 15.7-beta
jetpack / modules / sitemaps / sitemaps.php
jetpack / modules / sitemaps Last commit date
sitemap-buffer-fallback.php 2 years ago sitemap-buffer-image-fallback.php 2 years ago sitemap-buffer-image.php 4 years ago sitemap-buffer-master-fallback.php 2 years ago sitemap-buffer-master.php 4 years ago sitemap-buffer-news-fallback.php 2 years ago sitemap-buffer-news.php 4 years ago sitemap-buffer-page-fallback.php 2 years ago sitemap-buffer-page.php 4 years ago sitemap-buffer-video-fallback.php 2 years ago sitemap-buffer-video.php 4 years ago sitemap-buffer.php 3 years ago sitemap-builder.php 2 years ago sitemap-constants.php 4 years ago sitemap-finder.php 2 years ago sitemap-librarian.php 2 years ago sitemap-logger.php 4 years ago sitemap-state.php 2 years ago sitemap-stylist.php 2 years ago sitemaps.php 2 years ago
sitemaps.php
603 lines
1 <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2 /**
3 * Generate sitemap files in base XML as well as some namespace extensions.
4 *
5 * This module generates two different base sitemaps.
6 *
7 * 1. sitemap.xml
8 * The basic sitemap is updated regularly by wp-cron. It is stored in the
9 * database and retrieved when requested. This sitemap aims to include canonical
10 * URLs for all published content and abide by the sitemap spec. This is the root
11 * of a tree of sitemap and sitemap index xml files, depending on the number of URLs.
12 *
13 * By default the sitemap contains published posts of type 'post' and 'page', as
14 * well as the home url. To include other post types use the 'jetpack_sitemap_post_types'
15 * filter.
16 *
17 * @link https://www.sitemaps.org/protocol.html Base sitemaps protocol.
18 * @link https://support.google.com/webmasters/answer/178636 Image sitemap extension.
19 * @link https://developers.google.com/webmasters/videosearch/sitemaps Video sitemap extension.
20 *
21 * 2. news-sitemap.xml
22 * The news sitemap is generated on the fly when requested. It does not aim for
23 * completeness, instead including at most 1000 of the most recent published posts
24 * from the previous 2 days, per the news-sitemap spec.
25 *
26 * @link https://support.google.com/webmasters/answer/74288 News sitemap extension.
27 *
28 * @package automattic/jetpack
29 * @since 3.9.0
30 * @since 4.8.0 Remove 1000 post limit.
31 * @author Automattic
32 */
33
34 /* Include all of the sitemap subclasses. */
35 require_once __DIR__ . '/sitemap-constants.php';
36 require_once __DIR__ . '/sitemap-buffer.php';
37 require_once __DIR__ . '/sitemap-stylist.php';
38 require_once __DIR__ . '/sitemap-librarian.php';
39 require_once __DIR__ . '/sitemap-finder.php';
40 require_once __DIR__ . '/sitemap-builder.php';
41
42 if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
43 require_once __DIR__ . '/sitemap-logger.php';
44 }
45
46 // phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files.
47
48 /**
49 * Governs the generation, storage, and serving of sitemaps.
50 *
51 * @since 4.8.0
52 */
53 class Jetpack_Sitemap_Manager {
54
55 /**
56 * Librarian object for storing and retrieving sitemap data.
57 *
58 * @see Jetpack_Sitemap_Librarian
59 * @since 4.8.0
60 * @var Jetpack_Sitemap_Librarian $librarian Librarian object for storing and retrieving sitemap data.
61 */
62 private $librarian;
63
64 /**
65 * Logger object for reporting debug messages.
66 *
67 * @see Jetpack_Sitemap_Logger
68 * @since 4.8.0
69 * @var Jetpack_Sitemap_Logger $logger Logger object for reporting debug messages.
70 */
71 private $logger;
72
73 /**
74 * Finder object for handling sitemap URIs.
75 *
76 * @see Jetpack_Sitemap_Finder
77 * @since 4.8.0
78 * @var Jetpack_Sitemap_Finder $finder Finder object for handling with sitemap URIs.
79 */
80 private $finder;
81
82 /**
83 * Construct a new Jetpack_Sitemap_Manager.
84 *
85 * @access public
86 * @since 4.8.0
87 */
88 public function __construct() {
89 $this->librarian = new Jetpack_Sitemap_Librarian();
90 $this->finder = new Jetpack_Sitemap_Finder();
91
92 if ( defined( 'WP_DEBUG' ) && ( true === WP_DEBUG ) ) {
93 $this->logger = new Jetpack_Sitemap_Logger();
94 }
95
96 // Add callback for sitemap URL handler.
97 add_action(
98 'wp_loaded',
99 array( $this, 'callback_action_catch_sitemap_urls' ),
100 defined( 'IS_WPCOM' ) && IS_WPCOM ? 100 : 10
101 );
102
103 // Add generator to wp_cron task list.
104 $this->schedule_sitemap_generation();
105
106 // Add sitemap to robots.txt.
107 add_action(
108 'do_robotstxt',
109 array( $this, 'callback_action_do_robotstxt' ),
110 20
111 );
112
113 // The news sitemap is cached; here we add a callback to
114 // flush the cached news sitemap when a post is published.
115 add_action(
116 'publish_post',
117 array( $this, 'callback_action_flush_news_sitemap_cache' ),
118 10
119 );
120
121 // In case we need to purge all sitemaps, we do this.
122 add_action(
123 'jetpack_sitemaps_purge_data',
124 array( $this, 'callback_action_purge_data' )
125 );
126
127 /*
128 * Module parameters are stored as options in the database.
129 * This allows us to avoid having to process all of init
130 * before serving the sitemap data. The following actions
131 * process and store these filters.
132 */
133
134 // Process filters and store location string for sitemap.
135 add_action(
136 'init',
137 array( $this, 'callback_action_filter_sitemap_location' ),
138 999
139 );
140 }
141
142 /**
143 * Echo a raw string of given content-type.
144 *
145 * @access private
146 * @since 4.8.0
147 *
148 * @param string $the_content_type The content type to be served.
149 * @param string $the_content The string to be echoed.
150 * @return never
151 */
152 private function serve_raw_and_die( $the_content_type, $the_content ) {
153 header( 'Content-Type: ' . $the_content_type . '; charset=UTF-8' );
154
155 global $wp_query;
156 $wp_query->is_feed = true;
157 set_query_var( 'feed', 'sitemap' );
158
159 if ( '' === $the_content ) {
160 $error = __( 'No sitemap found. Please try again later.', 'jetpack' );
161 if ( current_user_can( 'manage_options' ) ) {
162 $next = human_time_diff( wp_next_scheduled( 'jp_sitemap_cron_hook' ) );
163 /* translators: %s is a human_time_diff until next sitemap generation. */
164 $error = sprintf( __( 'No sitemap found. The system will try to build it again in %s.', 'jetpack' ), $next );
165 }
166
167 wp_die(
168 esc_html( $error ),
169 esc_html__( 'Sitemaps', 'jetpack' ),
170 array(
171 'response' => 404,
172 )
173 );
174 }
175
176 echo $the_content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- All content created by Jetpack.
177
178 die();
179 }
180
181 /**
182 * Callback to intercept sitemap url requests and serve sitemap files.
183 *
184 * @access public
185 * @since 4.8.0
186 */
187 public function callback_action_catch_sitemap_urls() {
188 // Regular expressions for sitemap URL routing.
189 $regex = array(
190 'master' => '/^sitemap\.xml$/',
191 'sitemap' => '/^sitemap-[1-9][0-9]*\.xml$/',
192 'index' => '/^sitemap-index-[1-9][0-9]*\.xml$/',
193 'sitemap-style' => '/^sitemap\.xsl$/',
194 'index-style' => '/^sitemap-index\.xsl$/',
195 'image' => '/^image-sitemap-[1-9][0-9]*\.xml$/',
196 'image-index' => '/^image-sitemap-index-[1-9][0-9]*\.xml$/',
197 'image-style' => '/^image-sitemap\.xsl$/',
198 'video' => '/^video-sitemap-[1-9][0-9]*\.xml$/',
199 'video-index' => '/^video-sitemap-index-[1-9][0-9]*\.xml$/',
200 'video-style' => '/^video-sitemap\.xsl$/',
201 'news' => '/^news-sitemap\.xml$/',
202 'news-style' => '/^news-sitemap\.xsl$/',
203 );
204
205 // The raw path(+query) of the requested URI.
206 if ( isset( $_SERVER['REQUEST_URI'] ) ) { // WPCS: Input var okay.
207 $raw_uri = sanitize_text_field(
208 wp_unslash( $_SERVER['REQUEST_URI'] ) // WPCS: Input var okay.
209 );
210 } else {
211 $raw_uri = '';
212 }
213
214 $request = $this->finder->recognize_sitemap_uri( $raw_uri );
215
216 if ( isset( $request['sitemap_name'] ) ) {
217
218 /**
219 * Filter the content type used to serve the sitemap XML files.
220 *
221 * @module sitemaps
222 *
223 * @since 3.9.0
224 *
225 * @param string $xml_content_type By default, it's 'text/xml'.
226 */
227 $xml_content_type = apply_filters( 'jetpack_sitemap_content_type', 'text/xml' );
228
229 // Catch master sitemap xml.
230 if ( preg_match( $regex['master'], $request['sitemap_name'] ) ) {
231 $sitemap_content = $this->librarian->get_sitemap_text(
232 jp_sitemap_filename( JP_MASTER_SITEMAP_TYPE, 0 ),
233 JP_MASTER_SITEMAP_TYPE
234 );
235
236 // if there is no master sitemap yet, let's just return an empty sitemap with a short TTL instead of a 404.
237 if ( empty( $sitemap_content ) ) {
238 $builder = new Jetpack_Sitemap_Builder();
239 $sitemap_content = $builder->empty_sitemap_xml();
240 }
241
242 $this->serve_raw_and_die(
243 $xml_content_type,
244 $sitemap_content
245 );
246 }
247
248 // Catch sitemap xml.
249 if ( preg_match( $regex['sitemap'], $request['sitemap_name'] ) ) {
250 $this->serve_raw_and_die(
251 $xml_content_type,
252 $this->librarian->get_sitemap_text(
253 $request['sitemap_name'],
254 JP_PAGE_SITEMAP_TYPE
255 )
256 );
257 }
258
259 // Catch sitemap index xml.
260 if ( preg_match( $regex['index'], $request['sitemap_name'] ) ) {
261 $this->serve_raw_and_die(
262 $xml_content_type,
263 $this->librarian->get_sitemap_text(
264 $request['sitemap_name'],
265 JP_PAGE_SITEMAP_INDEX_TYPE
266 )
267 );
268 }
269
270 // Catch sitemap xsl.
271 if ( preg_match( $regex['sitemap-style'], $request['sitemap_name'] ) ) {
272 $this->serve_raw_and_die(
273 'application/xml',
274 Jetpack_Sitemap_Stylist::sitemap_xsl()
275 );
276 }
277
278 // Catch sitemap index xsl.
279 if ( preg_match( $regex['index-style'], $request['sitemap_name'] ) ) {
280 $this->serve_raw_and_die(
281 'application/xml',
282 Jetpack_Sitemap_Stylist::sitemap_index_xsl()
283 );
284 }
285
286 // Catch image sitemap xml.
287 if ( preg_match( $regex['image'], $request['sitemap_name'] ) ) {
288 $this->serve_raw_and_die(
289 $xml_content_type,
290 $this->librarian->get_sitemap_text(
291 $request['sitemap_name'],
292 JP_IMAGE_SITEMAP_TYPE
293 )
294 );
295 }
296
297 // Catch image sitemap index xml.
298 if ( preg_match( $regex['image-index'], $request['sitemap_name'] ) ) {
299 $this->serve_raw_and_die(
300 $xml_content_type,
301 $this->librarian->get_sitemap_text(
302 $request['sitemap_name'],
303 JP_IMAGE_SITEMAP_INDEX_TYPE
304 )
305 );
306 }
307
308 // Catch image sitemap xsl.
309 if ( preg_match( $regex['image-style'], $request['sitemap_name'] ) ) {
310 $this->serve_raw_and_die(
311 'application/xml',
312 Jetpack_Sitemap_Stylist::image_sitemap_xsl()
313 );
314 }
315
316 // Catch video sitemap xml.
317 if ( preg_match( $regex['video'], $request['sitemap_name'] ) ) {
318 $this->serve_raw_and_die(
319 $xml_content_type,
320 $this->librarian->get_sitemap_text(
321 $request['sitemap_name'],
322 JP_VIDEO_SITEMAP_TYPE
323 )
324 );
325 }
326
327 // Catch video sitemap index xml.
328 if ( preg_match( $regex['video-index'], $request['sitemap_name'] ) ) {
329 $this->serve_raw_and_die(
330 $xml_content_type,
331 $this->librarian->get_sitemap_text(
332 $request['sitemap_name'],
333 JP_VIDEO_SITEMAP_INDEX_TYPE
334 )
335 );
336 }
337
338 // Catch video sitemap xsl.
339 if ( preg_match( $regex['video-style'], $request['sitemap_name'] ) ) {
340 $this->serve_raw_and_die(
341 'application/xml',
342 Jetpack_Sitemap_Stylist::video_sitemap_xsl()
343 );
344 }
345
346 // Catch news sitemap xml.
347 if ( preg_match( $regex['news'], $request['sitemap_name'] ) ) {
348 $sitemap_builder = new Jetpack_Sitemap_Builder();
349 $this->serve_raw_and_die(
350 $xml_content_type,
351 $sitemap_builder->news_sitemap_xml()
352 );
353 }
354
355 // Catch news sitemap xsl.
356 if ( preg_match( $regex['news-style'], $request['sitemap_name'] ) ) {
357 $this->serve_raw_and_die(
358 'application/xml',
359 Jetpack_Sitemap_Stylist::news_sitemap_xsl()
360 );
361 }
362 }
363 }
364
365 /**
366 * Callback for adding sitemap-interval to the list of schedules.
367 *
368 * @access public
369 * @since 4.8.0
370 *
371 * @param array $schedules The array of WP_Cron schedules.
372 *
373 * @return array The updated array of WP_Cron schedules.
374 */
375 public function callback_add_sitemap_schedule( $schedules ) {
376 $schedules['sitemap-interval'] = array(
377 'interval' => JP_SITEMAP_INTERVAL,
378 'display' => __( 'Sitemap Interval', 'jetpack' ),
379 );
380 return $schedules;
381 }
382
383 /**
384 * Callback handler for sitemap cron hook
385 *
386 * @access public
387 */
388 public function callback_sitemap_cron_hook() {
389 $sitemap_builder = new Jetpack_Sitemap_Builder();
390 $sitemap_builder->update_sitemap();
391 }
392
393 /**
394 * Add actions to schedule sitemap generation.
395 * Should only be called once, in the constructor.
396 *
397 * @access private
398 * @since 4.8.0
399 */
400 private function schedule_sitemap_generation() {
401 // Add cron schedule.
402 add_filter( 'cron_schedules', array( $this, 'callback_add_sitemap_schedule' ) ); // phpcs:ignore WordPress.WP.CronInterval.ChangeDetected
403
404 add_action(
405 'jp_sitemap_cron_hook',
406 array( $this, 'callback_sitemap_cron_hook' )
407 );
408
409 if ( ! wp_next_scheduled( 'jp_sitemap_cron_hook' ) ) {
410 /**
411 * Filter the delay in seconds until sitemap generation cron job is started.
412 *
413 * This filter allows a site operator or hosting provider to potentialy spread out sitemap generation for a
414 * lot of sites over time. By default, it will be randomly done over 15 minutes.
415 *
416 * @module sitemaps
417 * @since 6.6.1
418 *
419 * @param int $delay Time to delay in seconds.
420 */
421 $delay = apply_filters( 'jetpack_sitemap_generation_delay', MINUTE_IN_SECONDS * wp_rand( 1, 15 ) ); // Randomly space it out to start within next fifteen minutes.
422 wp_schedule_event(
423 time() + $delay,
424 'sitemap-interval',
425 'jp_sitemap_cron_hook'
426 );
427 }
428 }
429
430 /**
431 * Callback to add sitemap to robots.txt.
432 *
433 * @access public
434 * @since 4.8.0
435 */
436 public function callback_action_do_robotstxt() {
437
438 /**
439 * Filter whether to make the default sitemap discoverable to robots or not. Default true.
440 *
441 * @module sitemaps
442 * @since 3.9.0
443 * @deprecated 7.4.0
444 *
445 * @param bool $discover_sitemap Make default sitemap discoverable to robots.
446 */
447 $discover_sitemap = apply_filters_deprecated( 'jetpack_sitemap_generate', array( true ), 'jetpack-7.4.0', 'jetpack_sitemap_include_in_robotstxt' );
448
449 /**
450 * Filter whether to make the default sitemap discoverable to robots or not. Default true.
451 *
452 * @module sitemaps
453 * @since 7.4.0
454 *
455 * @param bool $discover_sitemap Make default sitemap discoverable to robots.
456 */
457 $discover_sitemap = apply_filters( 'jetpack_sitemap_include_in_robotstxt', $discover_sitemap );
458
459 if ( true === $discover_sitemap ) {
460 $sitemap_url = $this->finder->construct_sitemap_url( 'sitemap.xml' );
461 echo 'Sitemap: ' . esc_url( $sitemap_url ) . "\n";
462 }
463
464 /**
465 * Filter whether to make the news sitemap discoverable to robots or not. Default true.
466 *
467 * @module sitemaps
468 * @since 3.9.0
469 * @deprecated 7.4.0
470 *
471 * @param bool $discover_news_sitemap Make default news sitemap discoverable to robots.
472 */
473 $discover_news_sitemap = apply_filters_deprecated( 'jetpack_news_sitemap_generate', array( true ), 'jetpack-7.4.0', 'jetpack_news_sitemap_include_in_robotstxt' );
474
475 /**
476 * Filter whether to make the news sitemap discoverable to robots or not. Default true.
477 *
478 * @module sitemaps
479 * @since 7.4.0
480 *
481 * @param bool $discover_news_sitemap Make default news sitemap discoverable to robots.
482 */
483 $discover_news_sitemap = apply_filters( 'jetpack_news_sitemap_include_in_robotstxt', $discover_news_sitemap );
484
485 if ( true === $discover_news_sitemap ) {
486 $news_sitemap_url = $this->finder->construct_sitemap_url( 'news-sitemap.xml' );
487 echo 'Sitemap: ' . esc_url( $news_sitemap_url ) . "\n";
488 }
489 }
490
491 /**
492 * Callback to delete the news sitemap cache.
493 *
494 * @access public
495 * @since 4.8.0
496 */
497 public function callback_action_flush_news_sitemap_cache() {
498 delete_transient( 'jetpack_news_sitemap_xml' );
499 }
500
501 /**
502 * Callback for resetting stored sitemap data.
503 *
504 * @access public
505 * @since 5.3.0
506 * @since 6.7.0 Schedules a regeneration.
507 */
508 public function callback_action_purge_data() {
509 $this->callback_action_flush_news_sitemap_cache();
510 $this->librarian->delete_all_stored_sitemap_data();
511 /** This filter is documented in modules/sitemaps/sitemaps.php */
512 $delay = apply_filters( 'jetpack_sitemap_generation_delay', MINUTE_IN_SECONDS * wp_rand( 1, 15 ) ); // Randomly space it out to start within next fifteen minutes.
513 wp_schedule_single_event( time() + $delay, 'jp_sitemap_cron_hook' );
514 }
515
516 /**
517 * Callback to set the sitemap location.
518 *
519 * @access public
520 * @since 4.8.0
521 */
522 public function callback_action_filter_sitemap_location() {
523 update_option(
524 'jetpack_sitemap_location',
525 /**
526 * Additional path for sitemap URIs. Default value is empty.
527 *
528 * This string is any additional path fragment you want included between
529 * the home URL and the sitemap filenames. Exactly how this fragment is
530 * interpreted depends on your permalink settings. For example:
531 *
532 * Pretty permalinks:
533 * home_url() . jetpack_sitemap_location . '/sitemap.xml'
534 *
535 * Plain ("ugly") permalinks:
536 * home_url() . jetpack_sitemap_location . '/?jetpack-sitemap=sitemap.xml'
537 *
538 * PATHINFO permalinks:
539 * home_url() . '/index.php' . jetpack_sitemap_location . '/sitemap.xml'
540 *
541 * where 'sitemap.xml' is the name of a specific sitemap file.
542 * The value of this filter must be a valid path fragment per RFC 3986;
543 * in particular it must either be empty or begin with a '/'.
544 * Also take care that any restrictions on sitemap location imposed by
545 * the sitemap protocol are satisfied.
546 *
547 * The result of this filter is stored in an option, 'jetpack_sitemap_location';
548 * that option is what gets read when the sitemap location is needed.
549 * This way we don't have to wait for init to finish before building sitemaps.
550 *
551 * @link https://tools.ietf.org/html/rfc3986#section-3.3 RFC 3986
552 * @link https://www.sitemaps.org/ The sitemap protocol
553 *
554 * @since 4.8.0
555 */
556 apply_filters(
557 'jetpack_sitemap_location',
558 ''
559 )
560 );
561 }
562 } // End Jetpack_Sitemap_Manager class.
563
564 new Jetpack_Sitemap_Manager();
565
566 /**
567 * Absolute URL of the current blog's sitemap.
568 *
569 * @module sitemaps
570 *
571 * @since 3.9.0
572 * @since 4.8.1 Code uses method found in Jetpack_Sitemap_Finder::construct_sitemap_url in 4.8.0.
573 * It has been moved here to avoid fatal errors with other plugins that were expecting to find this function.
574 *
575 * @param string $filename Sitemap file name. Defaults to 'sitemap.xml', the initial sitemaps page.
576 *
577 * @return string Sitemap URL.
578 */
579 function jetpack_sitemap_uri( $filename = 'sitemap.xml' ) {
580 global $wp_rewrite;
581
582 $location = Jetpack_Options::get_option_and_ensure_autoload( 'jetpack_sitemap_location', '' );
583
584 if ( $wp_rewrite->using_index_permalinks() ) {
585 $sitemap_url = home_url( '/index.php' . $location . '/' . $filename );
586 } elseif ( $wp_rewrite->using_permalinks() ) {
587 $sitemap_url = home_url( $location . '/' . $filename );
588 } else {
589 $sitemap_url = home_url( $location . '/?jetpack-sitemap=' . $filename );
590 }
591
592 /**
593 * Filter sitemap URL relative to home URL.
594 *
595 * @module sitemaps
596 *
597 * @since 3.9.0
598 *
599 * @param string $sitemap_url Sitemap URL.
600 */
601 return apply_filters( 'jetpack_sitemap_location', $sitemap_url );
602 }
603