From 46e2b79a51d26d50df015d9124782b4806a2b4cb Mon Sep 17 00:00:00 2001
From: jrfnl <github_nospam@adviesenzo.nl>
Date: Mon, 18 Apr 2016 06:02:40 +0200
Subject: [PATCH] Don't spawn cron for suspended blogs with possibility to
overrule.
---
src/wp-cron.php | 18 +++++++++++++++++-
src/wp-includes/cron.php | 34 ++++++++++++++++++++++++++++++++--
2 files changed, 49 insertions(+), 3 deletions(-)
diff --git a/src/wp-cron.php b/src/wp-cron.php
index 15c6676..ab90442 100644
a
|
b
|
function _get_cron_lock() { |
55 | 55 | return $value; |
56 | 56 | } |
57 | 57 | |
58 | | if ( false === $crons = _get_cron_array() ) |
| 58 | if ( false === $crons = _get_cron_array() ) { |
59 | 59 | die(); |
| 60 | } |
| 61 | |
| 62 | $should_skip = false; |
| 63 | $current_site = null; |
| 64 | if ( is_multisite() ) { |
| 65 | $current_site = get_blog_details(); |
| 66 | // Don't process cron for suspended blogs. |
| 67 | if ( $current_site->archived || $current_site->spam || $current_site->deleted ) { |
| 68 | $should_skip = true; |
| 69 | } |
| 70 | } |
| 71 | /** This filter is documented in wp-includes/cron.php */ |
| 72 | if ( true === apply_filters( 'skip_cron_for_site', $should_skip, $current_site ) ) { |
| 73 | die(); |
| 74 | } |
| 75 | unset( $should_skip, $current_site ); |
60 | 76 | |
61 | 77 | $keys = array_keys( $crons ); |
62 | 78 | $gmt_time = microtime( true ); |
diff --git a/src/wp-includes/cron.php b/src/wp-includes/cron.php
index 493e0ec..b4dcf97 100644
a
|
b
|
function spawn_cron( $gmt_time = 0 ) { |
336 | 336 | */ |
337 | 337 | function wp_cron() { |
338 | 338 | // Prevent infinite loops caused by lack of wp-cron.php |
339 | | if ( strpos($_SERVER['REQUEST_URI'], '/wp-cron.php') !== false || ( defined('DISABLE_WP_CRON') && DISABLE_WP_CRON ) ) |
| 339 | if ( strpos( $_SERVER['REQUEST_URI'], '/wp-cron.php' ) !== false || ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ) ) { |
340 | 340 | return; |
| 341 | } |
341 | 342 | |
342 | | if ( false === $crons = _get_cron_array() ) |
| 343 | if ( false === $crons = _get_cron_array() ) { |
343 | 344 | return; |
| 345 | } |
| 346 | |
| 347 | $should_skip = false; |
| 348 | $current_site = null; |
| 349 | if ( is_multisite() ) { |
| 350 | $current_site = get_blog_details(); |
| 351 | // Don't process cron for suspended sites. |
| 352 | if ( $current_site->archived || $current_site->spam || $current_site->deleted ) { |
| 353 | $should_skip = true; |
| 354 | } |
| 355 | } |
| 356 | /** |
| 357 | * Allow to either force skip a cron run or to force cron to run even for suspended sites. |
| 358 | * |
| 359 | * @since 4.6.0 |
| 360 | * |
| 361 | * @param bool $should_skip Whether the cron run is going to be skipped. |
| 362 | * Will be `false` for single-site or non-suspended site within multi-site |
| 363 | * or `true` for suspended sites. |
| 364 | * Sites are regarded as suspended if they are either archived, marked |
| 365 | * as spam or marked as deleted. |
| 366 | * Set to `false` to force cron to run or `true` to force cron to quit. |
| 367 | * @param null|object $current_site The WP_Site object for which cron will run or null if not in |
| 368 | * multi-site. |
| 369 | */ |
| 370 | if ( true === apply_filters( 'skip_cron_for_site', $should_skip, $current_site ) ) { |
| 371 | return; |
| 372 | } |
| 373 | unset( $should_skip, $current_site ); |
344 | 374 | |
345 | 375 | $gmt_time = microtime( true ); |
346 | 376 | $keys = array_keys( $crons ); |