| Conditions | 29 |
| Paths | 6337 |
| Total Lines | 207 |
| Code Lines | 100 |
| Lines | 3 |
| Ratio | 1.45 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 250 | $request['sitemap_name'], |
||
| 251 | JP_PAGE_SITEMAP_TYPE |
||
| 252 | ) |
||
| 253 | ); |
||
| 254 | } |
||
| 255 | |||
| 256 | // Catch sitemap index xml. |
||
| 257 | View Code Duplication | if ( preg_match( $regex['index'], $request['sitemap_name'] ) ) { |
|
| 258 | $this->serve_raw_and_die( |
||
| 259 | $xml_content_type, |
||
| 260 | $this->librarian->get_sitemap_text( |
||
| 261 | $request['sitemap_name'], |
||
| 262 | JP_PAGE_SITEMAP_INDEX_TYPE |
||
| 263 | ) |
||
| 264 | ); |
||
| 265 | } |
||
| 266 | |||
| 267 | // Catch sitemap xsl. |
||
| 268 | if ( preg_match( $regex['sitemap-style'], $request['sitemap_name'] ) ) { |
||
| 269 | $this->serve_raw_and_die( |
||
| 270 | 'application/xml', |
||
| 271 | Jetpack_Sitemap_Stylist::sitemap_xsl() |
||
| 272 | ); |
||
| 273 | } |
||
| 274 | |||
| 275 | // Catch sitemap index xsl. |
||
| 276 | if ( preg_match( $regex['index-style'], $request['sitemap_name'] ) ) { |
||
| 277 | $this->serve_raw_and_die( |
||
| 278 | 'application/xml', |
||
| 279 | Jetpack_Sitemap_Stylist::sitemap_index_xsl() |
||
| 280 | ); |
||
| 281 | } |
||
| 282 | |||
| 283 | // Catch image sitemap xml. |
||
| 284 | View Code Duplication | if ( preg_match( $regex['image'], $request['sitemap_name'] ) ) { |
|
| 285 | $this->serve_raw_and_die( |
||
| 286 | $xml_content_type, |
||
| 287 | $this->librarian->get_sitemap_text( |
||
| 288 | $request['sitemap_name'], |
||
| 289 | JP_IMAGE_SITEMAP_TYPE |
||
| 290 | ) |
||
| 291 | ); |
||
| 292 | } |
||
| 293 | |||
| 294 | // Catch image sitemap index xml. |
||
| 295 | View Code Duplication | if ( preg_match( $regex['image-index'], $request['sitemap_name'] ) ) { |
|
| 296 | $this->serve_raw_and_die( |
||
| 297 | $xml_content_type, |
||
| 298 | $this->librarian->get_sitemap_text( |
||
| 299 | $request['sitemap_name'], |
||
| 300 | JP_IMAGE_SITEMAP_INDEX_TYPE |
||
| 301 | ) |
||
| 302 | ); |
||
| 303 | } |
||
| 304 | |||
| 305 | // Catch image sitemap xsl. |
||
| 306 | if ( preg_match( $regex['image-style'], $request['sitemap_name'] ) ) { |
||
| 307 | $this->serve_raw_and_die( |
||
| 308 | 'application/xml', |
||
| 309 | Jetpack_Sitemap_Stylist::image_sitemap_xsl() |
||
| 310 | ); |
||
| 311 | } |
||
| 312 | |||
| 313 | // Catch video sitemap xml. |
||
| 314 | View Code Duplication | if ( preg_match( $regex['video'], $request['sitemap_name'] ) ) { |
|
| 315 | $this->serve_raw_and_die( |
||
| 316 | $xml_content_type, |
||
| 317 | $this->librarian->get_sitemap_text( |
||
| 318 | $request['sitemap_name'], |
||
| 319 | JP_VIDEO_SITEMAP_TYPE |
||
| 320 | ) |
||
| 321 | ); |
||
| 322 | } |
||
| 323 | |||
| 324 | // Catch video sitemap index xml. |
||
| 325 | View Code Duplication | if ( preg_match( $regex['video-index'], $request['sitemap_name'] ) ) { |
|
| 326 | $this->serve_raw_and_die( |
||
| 327 | $xml_content_type, |
||
| 328 | $this->librarian->get_sitemap_text( |
||
| 329 | $request['sitemap_name'], |
||
| 330 | JP_VIDEO_SITEMAP_INDEX_TYPE |
||
| 331 | ) |
||
| 332 | ); |
||
| 333 | } |
||
| 334 | |||
| 335 | // Catch video sitemap xsl. |
||
| 336 | if ( preg_match( $regex['video-style'], $request['sitemap_name'] ) ) { |
||
| 337 | $this->serve_raw_and_die( |
||
| 338 | 'application/xml', |
||
| 339 | Jetpack_Sitemap_Stylist::video_sitemap_xsl() |
||
| 340 | ); |
||
| 341 | } |
||
| 342 | |||
| 343 | // Catch news sitemap xml. |
||
| 344 | if ( preg_match( $regex['news'], $request['sitemap_name'] ) ) { |
||
| 345 | $sitemap_builder = new Jetpack_Sitemap_Builder(); |
||
| 346 | $this->serve_raw_and_die( |
||
| 347 | $xml_content_type, |
||
| 348 | $sitemap_builder->news_sitemap_xml() |
||
| 349 | ); |
||
| 350 | } |
||
| 351 | |||
| 352 | // Catch news sitemap xsl. |
||
| 353 | if ( preg_match( $regex['news-style'], $request['sitemap_name'] ) ) { |
||
| 354 | $this->serve_raw_and_die( |
||
| 355 | 'application/xml', |
||
| 356 | Jetpack_Sitemap_Stylist::news_sitemap_xsl() |
||
| 357 | ); |
||
| 358 | } |
||
| 359 | } |
||
| 360 | } |
||
| 361 | |||
| 362 | /** |
||
| 363 | * Callback for adding sitemap-interval to the list of schedules. |
||
| 364 | * |
||
| 365 | * @access public |
||
| 366 | * @since 4.8.0 |
||
| 367 | * |
||
| 368 | * @param array $schedules The array of WP_Cron schedules. |
||
| 369 | * |
||
| 370 | * @return array The updated array of WP_Cron schedules. |
||
| 371 | */ |
||
| 372 | public function callback_add_sitemap_schedule( $schedules ) { |
||
| 373 | $schedules['sitemap-interval'] = array( |
||
| 374 | 'interval' => JP_SITEMAP_INTERVAL, |
||
| 375 | 'display' => __( 'Sitemap Interval', 'jetpack' ), |
||
| 376 | ); |
||
| 377 | return $schedules; |
||
| 378 | } |
||
| 379 | |||
| 380 | /** |
||
| 381 | * Callback handler for sitemap cron hook |
||
| 382 | * |
||
| 383 | * @access public |
||
| 384 | */ |
||
| 385 | public function callback_sitemap_cron_hook() { |
||
| 386 | $sitemap_builder = new Jetpack_Sitemap_Builder(); |
||
| 387 | $sitemap_builder->update_sitemap(); |
||
| 388 | } |
||
| 389 | |||
| 390 | /** |
||
| 391 | * Add actions to schedule sitemap generation. |
||
| 392 | * Should only be called once, in the constructor. |
||
| 393 | * |
||
| 394 | * @access private |
||
| 395 | * @since 4.8.0 |
||
| 396 | */ |
||
| 397 | private function schedule_sitemap_generation() { |
||
| 398 | // Add cron schedule. |
||
| 399 | add_filter( 'cron_schedules', array( $this, 'callback_add_sitemap_schedule' ) ); // phpcs:ignore WordPress.WP.CronInterval.ChangeDetected |
||
| 400 | |||
| 401 | add_action( |
||
| 402 | 'jp_sitemap_cron_hook', |
||
| 403 | array( $this, 'callback_sitemap_cron_hook' ) |
||
| 404 | ); |
||
| 405 | |||
| 406 | if ( ! wp_next_scheduled( 'jp_sitemap_cron_hook' ) ) { |
||
| 407 | /** |
||
| 408 | * Filter the delay in seconds until sitemap generation cron job is started. |
||
| 409 | * |
||
| 410 | * This filter allows a site operator or hosting provider to potentialy spread out sitemap generation for a |
||
| 411 | * lot of sites over time. By default, it will be randomly done over 15 minutes. |
||
| 412 | * |
||
| 413 | * @module sitemaps |
||
| 414 | * @since 6.6.1 |
||
| 415 | * |
||
| 416 | * @param int $delay Time to delay in seconds. |
||
| 417 | */ |
||
| 418 | $delay = apply_filters( 'jetpack_sitemap_generation_delay', MINUTE_IN_SECONDS * wp_rand( 1, 15 ) ); // Randomly space it out to start within next fifteen minutes. |
||
| 419 | wp_schedule_event( |
||
| 420 | time() + $delay, |
||
| 421 | 'sitemap-interval', |
||
| 422 | 'jp_sitemap_cron_hook' |
||
| 423 | ); |
||
| 424 | } |
||
| 425 | } |
||
| 426 | |||
| 427 | /** |
||
| 428 | * Callback to add sitemap to robots.txt. |
||
| 429 | * |
||
| 430 | * @access public |
||
| 431 | * @since 4.8.0 |
||
| 432 | */ |
||
| 433 | public function callback_action_do_robotstxt() { |
||
| 434 | |||
| 435 | /** |
||
| 436 | * Filter whether to make the default sitemap discoverable to robots or not. Default true. |
||
| 437 | * |
||
| 438 | * @module sitemaps |
||
| 439 | * @since 3.9.0 |
||
| 440 | * |
||
| 441 | * @param bool $discover_sitemap Make default sitemap discoverable to robots. |
||
| 442 | */ |
||
| 443 | $discover_sitemap = apply_filters( 'jetpack_sitemap_generate', true ); |
||
| 444 | |||
| 445 | View Code Duplication | if ( true === $discover_sitemap ) { |
|
| 446 | $sitemap_url = $this->finder->construct_sitemap_url( 'sitemap.xml' ); |
||
| 447 | echo 'Sitemap: ' . esc_url( $sitemap_url ) . "\n"; |
||
| 448 | } |
||
| 449 | |||
| 450 | /** |
||
| 451 | * Filter whether to make the news sitemap discoverable to robots or not. Default true. |
||
| 452 | * |
||
| 453 | * @module sitemaps |
||
| 454 | * @since 3.9.0 |
||
| 455 | * |
||
| 456 | * @param bool $discover_news_sitemap Make default news sitemap discoverable to robots. |
||
| 457 | */ |
||
| 579 |