PluginProbe ʕ •ᴥ•ʔ
Jetpack – WP Security, Backup, Speed, & Growth / 14.9.2
Jetpack – WP Security, Backup, Speed, & Growth v14.9.2
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-factory.php 1 year ago sitemap-buffer-fallback.php 2 years ago sitemap-buffer-image-fallback.php 2 years ago sitemap-buffer-image-xmlwriter.php 1 year ago sitemap-buffer-image.php 4 years ago sitemap-buffer-master-fallback.php 2 years ago sitemap-buffer-master-xmlwriter.php 1 year ago sitemap-buffer-master.php 4 years ago sitemap-buffer-news-fallback.php 2 years ago sitemap-buffer-news-xmlwriter.php 1 year ago sitemap-buffer-news.php 4 years ago sitemap-buffer-page-fallback.php 2 years ago sitemap-buffer-page-xmlwriter.php 1 year ago sitemap-buffer-page.php 4 years ago sitemap-buffer-video-fallback.php 1 year ago sitemap-buffer-video-xmlwriter.php 1 year ago sitemap-buffer-video.php 4 years ago sitemap-buffer-xmlwriter.php 1 year ago sitemap-buffer.php 1 year ago sitemap-builder.php 1 year ago sitemap-constants.php 1 year ago sitemap-finder.php 2 years ago sitemap-librarian.php 1 year ago sitemap-logger.php 1 year ago sitemap-state.php 2 years ago sitemap-stylist.php 2 years ago sitemaps.php 1 year ago
sitemaps.php
606 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-buffer-fallback.php';
38 require_once __DIR__ . '/sitemap-buffer-xmlwriter.php';
39 require_once __DIR__ . '/sitemap-buffer-page-xmlwriter.php';
40 require_once __DIR__ . '/sitemap-buffer-image-xmlwriter.php';
41 require_once __DIR__ . '/sitemap-buffer-video-xmlwriter.php';
42 require_once __DIR__ . '/sitemap-buffer-news-xmlwriter.php';
43 require_once __DIR__ . '/sitemap-buffer-master-xmlwriter.php';
44 require_once __DIR__ . '/sitemap-buffer-factory.php';
45 require_once __DIR__ . '/sitemap-stylist.php';
46 require_once __DIR__ . '/sitemap-librarian.php';
47 require_once __DIR__ . '/sitemap-finder.php';
48 require_once __DIR__ . '/sitemap-builder.php';
49
50 if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
51 require_once __DIR__ . '/sitemap-logger.php';
52 }
53
54 // phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files.
55
56 /**
57 * Governs the generation, storage, and serving of sitemaps.
58 *
59 * @since 4.8.0
60 *
61 * @phan-constructor-used-for-side-effects
62 */
63 class Jetpack_Sitemap_Manager {
64
65 /**
66 * Librarian object for storing and retrieving sitemap data.
67 *
68 * @see Jetpack_Sitemap_Librarian
69 * @since 4.8.0
70 * @var Jetpack_Sitemap_Librarian $librarian Librarian object for storing and retrieving sitemap data.
71 */
72 private $librarian;
73
74 /**
75 * Logger object for reporting debug messages.
76 *
77 * @see Jetpack_Sitemap_Logger
78 * @since 4.8.0
79 * @var Jetpack_Sitemap_Logger $logger Logger object for reporting debug messages.
80 */
81 private $logger;
82
83 /**
84 * Finder object for handling sitemap URIs.
85 *
86 * @see Jetpack_Sitemap_Finder
87 * @since 4.8.0
88 * @var Jetpack_Sitemap_Finder $finder Finder object for handling with sitemap URIs.
89 */
90 private $finder;
91
92 /**
93 * Construct a new Jetpack_Sitemap_Manager.
94 *
95 * @access public
96 * @since 4.8.0
97 */
98 public function __construct() {
99 $this->librarian = new Jetpack_Sitemap_Librarian();
100 $this->finder = new Jetpack_Sitemap_Finder();
101
102 if ( defined( 'WP_DEBUG' ) && ( true === WP_DEBUG ) ) {
103 $this->logger = new Jetpack_Sitemap_Logger();
104 }
105
106 // Add callback for sitemap URL handler.
107 add_action(
108 'wp_loaded',
109 array( $this, 'callback_action_catch_sitemap_urls' ),
110 defined( 'IS_WPCOM' ) && IS_WPCOM ? 100 : 10
111 );
112
113 // Add generator to wp_cron task list.
114 $this->schedule_sitemap_generation();
115
116 // Add sitemap to robots.txt.
117 add_action(
118 'do_robotstxt',
119 array( $this, 'callback_action_do_robotstxt' ),
120 20
121 );
122
123 // The news sitemap is cached; here we add a callback to
124 // flush the cached news sitemap when a post is published.
125 add_action(
126 'publish_post',
127 array( $this, 'callback_action_flush_news_sitemap_cache' ),
128 10
129 );
130
131 // In case we need to purge all sitemaps, we do this.
132 add_action(
133 'jetpack_sitemaps_purge_data',
134 array( $this, 'callback_action_purge_data' )
135 );
136
137 /*
138 * Module parameters are stored as options in the database.
139 * This allows us to avoid having to process all of init
140 * before serving the sitemap data. The following actions
141 * process and store these filters.
142 */
143
144 // Process filters and store location string for sitemap.
145 add_action(
146 'init',
147 array( $this, 'callback_action_filter_sitemap_location' ),
148 999
149 );
150 }
151
152 /**
153 * Echo a raw string of given content-type.
154 *
155 * @access private
156 * @since 4.8.0
157 *
158 * @param string $the_content_type The content type to be served.
159 * @param string $the_content The string to be echoed.
160 * @return never
161 */
162 private function serve_raw_and_die( $the_content_type, $the_content ) {
163 header( 'Content-Type: ' . $the_content_type . '; charset=UTF-8' );
164
165 global $wp_query;
166 $wp_query->is_feed = true;
167 set_query_var( 'feed', 'sitemap' );
168
169 if ( '' === $the_content ) {
170 $error = __( 'No sitemap found. Please try again later.', 'jetpack' );
171 if ( current_user_can( 'manage_options' ) ) {
172 $next = human_time_diff( wp_next_scheduled( 'jp_sitemap_cron_hook' ) );
173 /* translators: %s is a human_time_diff until next sitemap generation. */
174 $error = sprintf( __( 'No sitemap found. The system will try to build it again in %s.', 'jetpack' ), $next );
175 }
176
177 wp_die(
178 esc_html( $error ),
179 esc_html__( 'Sitemaps', 'jetpack' ),
180 array(
181 'response' => 404,
182 )
183 );
184 }
185
186 echo $the_content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- All content created by Jetpack.
187
188 die( 0 );
189 }
190
191 /**
192 * Callback to intercept sitemap url requests and serve sitemap files.
193 *
194 * @access public
195 * @since 4.8.0
196 */
197 public function callback_action_catch_sitemap_urls() {
198 // Regular expressions for sitemap URL routing.
199 $regex = array(
200 'sitemap' => '/^sitemap-[1-9][0-9]*\.xml$/',
201 'index' => '/^sitemap-index-[1-9][0-9]*\.xml$/',
202 'image' => '/^image-sitemap-[1-9][0-9]*\.xml$/',
203 'image-index' => '/^image-sitemap-index-[1-9][0-9]*\.xml$/',
204 'video' => '/^video-sitemap-[1-9][0-9]*\.xml$/',
205 'video-index' => '/^video-sitemap-index-[1-9][0-9]*\.xml$/',
206 );
207
208 // The raw path(+query) of the requested URI.
209 if ( isset( $_SERVER['REQUEST_URI'] ) ) { // WPCS: Input var okay.
210 $raw_uri = sanitize_text_field(
211 wp_unslash( $_SERVER['REQUEST_URI'] ) // WPCS: Input var okay.
212 );
213 } else {
214 $raw_uri = '';
215 }
216
217 $request = $this->finder->recognize_sitemap_uri( $raw_uri );
218
219 if ( isset( $request['sitemap_name'] ) ) {
220
221 /**
222 * Filter the content type used to serve the sitemap XML files.
223 *
224 * @module sitemaps
225 *
226 * @since 3.9.0
227 *
228 * @param string $xml_content_type By default, it's 'text/xml'.
229 */
230 $xml_content_type = apply_filters( 'jetpack_sitemap_content_type', 'text/xml' );
231
232 // Catch master sitemap xml.
233 if ( 'sitemap.xml' === $request['sitemap_name'] ) {
234 $sitemap_content = $this->librarian->get_sitemap_text(
235 jp_sitemap_filename( JP_MASTER_SITEMAP_TYPE, 0 ),
236 JP_MASTER_SITEMAP_TYPE
237 );
238
239 // if there is no master sitemap yet, let's just return an empty sitemap with a short TTL instead of a 404.
240 if ( empty( $sitemap_content ) ) {
241 $builder = new Jetpack_Sitemap_Builder();
242 $sitemap_content = $builder->empty_sitemap_xml();
243 }
244
245 $this->serve_raw_and_die(
246 $xml_content_type,
247 $sitemap_content
248 );
249 }
250
251 // Catch sitemap xsl.
252 if ( 'sitemap.xsl' === $request['sitemap_name'] ) {
253 $this->serve_raw_and_die(
254 'application/xml',
255 Jetpack_Sitemap_Stylist::sitemap_xsl()
256 );
257 }
258
259 // Catch sitemap index xsl.
260 if ( 'sitemap-index.xsl' === $request['sitemap_name'] ) {
261 $this->serve_raw_and_die(
262 'application/xml',
263 Jetpack_Sitemap_Stylist::sitemap_index_xsl()
264 );
265 }
266
267 // Catch image sitemap xsl.
268 if ( 'image-sitemap.xsl' === $request['sitemap_name'] ) {
269 $this->serve_raw_and_die(
270 'application/xml',
271 Jetpack_Sitemap_Stylist::image_sitemap_xsl()
272 );
273 }
274
275 // Catch video sitemap xsl.
276 if ( 'video-sitemap.xsl' === $request['sitemap_name'] ) {
277 $this->serve_raw_and_die(
278 'application/xml',
279 Jetpack_Sitemap_Stylist::video_sitemap_xsl()
280 );
281 }
282
283 // Catch news sitemap xml.
284 if ( 'news-sitemap.xml' === $request['sitemap_name'] ) {
285 $sitemap_builder = new Jetpack_Sitemap_Builder();
286 $this->serve_raw_and_die(
287 $xml_content_type,
288 $sitemap_builder->news_sitemap_xml()
289 );
290 }
291
292 // Catch news sitemap xsl.
293 if ( 'news-sitemap.xsl' === $request['sitemap_name'] ) {
294 $this->serve_raw_and_die(
295 'application/xml',
296 Jetpack_Sitemap_Stylist::news_sitemap_xsl()
297 );
298 }
299
300 // Catch sitemap xml.
301 if ( preg_match( $regex['sitemap'], $request['sitemap_name'] ) ) {
302 $this->serve_raw_and_die(
303 $xml_content_type,
304 $this->librarian->get_sitemap_text(
305 $request['sitemap_name'],
306 JP_PAGE_SITEMAP_TYPE
307 )
308 );
309 }
310
311 // Catch sitemap index xml.
312 if ( preg_match( $regex['index'], $request['sitemap_name'] ) ) {
313 $this->serve_raw_and_die(
314 $xml_content_type,
315 $this->librarian->get_sitemap_text(
316 $request['sitemap_name'],
317 JP_PAGE_SITEMAP_INDEX_TYPE
318 )
319 );
320 }
321
322 // Catch image sitemap xml.
323 if ( preg_match( $regex['image'], $request['sitemap_name'] ) ) {
324 $this->serve_raw_and_die(
325 $xml_content_type,
326 $this->librarian->get_sitemap_text(
327 $request['sitemap_name'],
328 JP_IMAGE_SITEMAP_TYPE
329 )
330 );
331 }
332
333 // Catch image sitemap index xml.
334 if ( preg_match( $regex['image-index'], $request['sitemap_name'] ) ) {
335 $this->serve_raw_and_die(
336 $xml_content_type,
337 $this->librarian->get_sitemap_text(
338 $request['sitemap_name'],
339 JP_IMAGE_SITEMAP_INDEX_TYPE
340 )
341 );
342 }
343
344 // Catch video sitemap xml.
345 if ( preg_match( $regex['video'], $request['sitemap_name'] ) ) {
346 $this->serve_raw_and_die(
347 $xml_content_type,
348 $this->librarian->get_sitemap_text(
349 $request['sitemap_name'],
350 JP_VIDEO_SITEMAP_TYPE
351 )
352 );
353 }
354
355 // Catch video sitemap index xml.
356 if ( preg_match( $regex['video-index'], $request['sitemap_name'] ) ) {
357 $this->serve_raw_and_die(
358 $xml_content_type,
359 $this->librarian->get_sitemap_text(
360 $request['sitemap_name'],
361 JP_VIDEO_SITEMAP_INDEX_TYPE
362 )
363 );
364 }
365 }
366 }
367
368 /**
369 * Callback for adding sitemap-interval to the list of schedules.
370 *
371 * @access public
372 * @since 4.8.0
373 *
374 * @param array $schedules The array of WP_Cron schedules.
375 *
376 * @return array The updated array of WP_Cron schedules.
377 */
378 public function callback_add_sitemap_schedule( $schedules ) {
379 $schedules['sitemap-interval'] = array(
380 'interval' => JP_SITEMAP_INTERVAL,
381 'display' => __( 'Sitemap Interval', 'jetpack' ),
382 );
383 return $schedules;
384 }
385
386 /**
387 * Callback handler for sitemap cron hook
388 *
389 * @access public
390 */
391 public function callback_sitemap_cron_hook() {
392 $sitemap_builder = new Jetpack_Sitemap_Builder();
393 $sitemap_builder->update_sitemap();
394 }
395
396 /**
397 * Add actions to schedule sitemap generation.
398 * Should only be called once, in the constructor.
399 *
400 * @access private
401 * @since 4.8.0
402 */
403 private function schedule_sitemap_generation() {
404 // Add cron schedule.
405 add_filter( 'cron_schedules', array( $this, 'callback_add_sitemap_schedule' ) ); // phpcs:ignore WordPress.WP.CronInterval.ChangeDetected
406
407 add_action(
408 'jp_sitemap_cron_hook',
409 array( $this, 'callback_sitemap_cron_hook' )
410 );
411
412 if ( ! wp_next_scheduled( 'jp_sitemap_cron_hook' ) ) {
413 /**
414 * Filter the delay in seconds until sitemap generation cron job is started.
415 *
416 * This filter allows a site operator or hosting provider to potentialy spread out sitemap generation for a
417 * lot of sites over time. By default, it will be randomly done over 15 minutes.
418 *
419 * @module sitemaps
420 * @since 6.6.1
421 *
422 * @param int $delay Time to delay in seconds.
423 */
424 $delay = apply_filters( 'jetpack_sitemap_generation_delay', MINUTE_IN_SECONDS * wp_rand( 1, 15 ) ); // Randomly space it out to start within next fifteen minutes.
425 wp_schedule_event(
426 time() + $delay,
427 'sitemap-interval',
428 'jp_sitemap_cron_hook'
429 );
430 }
431 }
432
433 /**
434 * Callback to add sitemap to robots.txt.
435 *
436 * @access public
437 * @since 4.8.0
438 */
439 public function callback_action_do_robotstxt() {
440
441 /**
442 * Filter whether to make the default sitemap discoverable to robots or not. Default true.
443 *
444 * @module sitemaps
445 * @since 3.9.0
446 * @deprecated 7.4.0
447 *
448 * @param bool $discover_sitemap Make default sitemap discoverable to robots.
449 */
450 $discover_sitemap = apply_filters_deprecated( 'jetpack_sitemap_generate', array( true ), 'jetpack-7.4.0', 'jetpack_sitemap_include_in_robotstxt' );
451
452 /**
453 * Filter whether to make the default sitemap discoverable to robots or not. Default true.
454 *
455 * @module sitemaps
456 * @since 7.4.0
457 *
458 * @param bool $discover_sitemap Make default sitemap discoverable to robots.
459 */
460 $discover_sitemap = apply_filters( 'jetpack_sitemap_include_in_robotstxt', $discover_sitemap );
461
462 if ( true === $discover_sitemap ) {
463 $sitemap_url = $this->finder->construct_sitemap_url( 'sitemap.xml' );
464 echo 'Sitemap: ' . esc_url( $sitemap_url ) . "\n";
465 }
466
467 /**
468 * Filter whether to make the news sitemap discoverable to robots or not. Default true.
469 *
470 * @module sitemaps
471 * @since 3.9.0
472 * @deprecated 7.4.0
473 *
474 * @param bool $discover_news_sitemap Make default news sitemap discoverable to robots.
475 */
476 $discover_news_sitemap = apply_filters_deprecated( 'jetpack_news_sitemap_generate', array( true ), 'jetpack-7.4.0', 'jetpack_news_sitemap_include_in_robotstxt' );
477
478 /**
479 * Filter whether to make the news sitemap discoverable to robots or not. Default true.
480 *
481 * @module sitemaps
482 * @since 7.4.0
483 *
484 * @param bool $discover_news_sitemap Make default news sitemap discoverable to robots.
485 */
486 $discover_news_sitemap = apply_filters( 'jetpack_news_sitemap_include_in_robotstxt', $discover_news_sitemap );
487
488 if ( true === $discover_news_sitemap ) {
489 $news_sitemap_url = $this->finder->construct_sitemap_url( 'news-sitemap.xml' );
490 echo 'Sitemap: ' . esc_url( $news_sitemap_url ) . "\n";
491 }
492 }
493
494 /**
495 * Callback to delete the news sitemap cache.
496 *
497 * @access public
498 * @since 4.8.0
499 */
500 public function callback_action_flush_news_sitemap_cache() {
501 delete_transient( 'jetpack_news_sitemap_xml' );
502 }
503
504 /**
505 * Callback for resetting stored sitemap data.
506 *
507 * @access public
508 * @since 5.3.0
509 * @since 6.7.0 Schedules a regeneration.
510 */
511 public function callback_action_purge_data() {
512 $this->callback_action_flush_news_sitemap_cache();
513 $this->librarian->delete_all_stored_sitemap_data();
514 /** This filter is documented in modules/sitemaps/sitemaps.php */
515 $delay = apply_filters( 'jetpack_sitemap_generation_delay', MINUTE_IN_SECONDS * wp_rand( 1, 15 ) ); // Randomly space it out to start within next fifteen minutes.
516 wp_schedule_single_event( time() + $delay, 'jp_sitemap_cron_hook' );
517 }
518
519 /**
520 * Callback to set the sitemap location.
521 *
522 * @access public
523 * @since 4.8.0
524 */
525 public function callback_action_filter_sitemap_location() {
526 update_option(
527 'jetpack_sitemap_location',
528 /**
529 * Additional path for sitemap URIs. Default value is empty.
530 *
531 * This string is any additional path fragment you want included between
532 * the home URL and the sitemap filenames. Exactly how this fragment is
533 * interpreted depends on your permalink settings. For example:
534 *
535 * Pretty permalinks:
536 * home_url() . jetpack_sitemap_location . '/sitemap.xml'
537 *
538 * Plain ("ugly") permalinks:
539 * home_url() . jetpack_sitemap_location . '/?jetpack-sitemap=sitemap.xml'
540 *
541 * PATHINFO permalinks:
542 * home_url() . '/index.php' . jetpack_sitemap_location . '/sitemap.xml'
543 *
544 * where 'sitemap.xml' is the name of a specific sitemap file.
545 * The value of this filter must be a valid path fragment per RFC 3986;
546 * in particular it must either be empty or begin with a '/'.
547 * Also take care that any restrictions on sitemap location imposed by
548 * the sitemap protocol are satisfied.
549 *
550 * The result of this filter is stored in an option, 'jetpack_sitemap_location';
551 * that option is what gets read when the sitemap location is needed.
552 * This way we don't have to wait for init to finish before building sitemaps.
553 *
554 * @link https://tools.ietf.org/html/rfc3986#section-3.3 RFC 3986
555 * @link https://www.sitemaps.org/ The sitemap protocol
556 *
557 * @since 4.8.0
558 */
559 apply_filters(
560 'jetpack_sitemap_location',
561 ''
562 )
563 );
564 }
565 } // End Jetpack_Sitemap_Manager class.
566
567 new Jetpack_Sitemap_Manager();
568
569 /**
570 * Absolute URL of the current blog's sitemap.
571 *
572 * @module sitemaps
573 *
574 * @since 3.9.0
575 * @since 4.8.1 Code uses method found in Jetpack_Sitemap_Finder::construct_sitemap_url in 4.8.0.
576 * It has been moved here to avoid fatal errors with other plugins that were expecting to find this function.
577 *
578 * @param string $filename Sitemap file name. Defaults to 'sitemap.xml', the initial sitemaps page.
579 *
580 * @return string Sitemap URL.
581 */
582 function jetpack_sitemap_uri( $filename = 'sitemap.xml' ) {
583 global $wp_rewrite;
584
585 $location = Jetpack_Options::get_option_and_ensure_autoload( 'jetpack_sitemap_location', '' );
586
587 if ( $wp_rewrite->using_index_permalinks() ) {
588 $sitemap_url = home_url( '/index.php' . $location . '/' . $filename );
589 } elseif ( $wp_rewrite->using_permalinks() ) {
590 $sitemap_url = home_url( $location . '/' . $filename );
591 } else {
592 $sitemap_url = home_url( $location . '/?jetpack-sitemap=' . $filename );
593 }
594
595 /**
596 * Filter sitemap URL relative to home URL.
597 *
598 * @module sitemaps
599 *
600 * @since 3.9.0
601 *
602 * @param string $sitemap_url Sitemap URL.
603 */
604 return apply_filters( 'jetpack_sitemap_location', $sitemap_url );
605 }
606