From d8b2589064c69afd9c3b88746e50d98bd8424472 Mon Sep 17 00:00:00 2001
From: jrfnl <github_nospam@adviesenzo.nl>
Date: Thu, 10 Dec 2015 12:52:06 +0100
Subject: [PATCH] Don't spawn cron for suspended blogs with possibility to
overrule.
---
src/wp-cron.php | 14 +++++++++++++-
src/wp-includes/cron.php | 28 ++++++++++++++++++++++++++--
2 files changed, 39 insertions(+), 3 deletions(-)
diff --git a/src/wp-cron.php b/src/wp-cron.php
index 15c6676..f3625f2 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 | // Don't process cron for suspended blogs. |
| 64 | if ( is_multisite() && ( $current_blog->archived || $current_blog->spam || $current_blog->deleted ) ) { |
| 65 | $should_skip = true; |
| 66 | } |
| 67 | /** This filter is documented in wp-includes/cron.php */ |
| 68 | if ( true === apply_filters( 'skip_cron_for_blog', $should_skip, $current_blog ) ) { |
| 69 | return; |
| 70 | } |
| 71 | unset( $should_skip ); |
60 | 72 | |
61 | 73 | $keys = array_keys( $crons ); |
62 | 74 | $gmt_time = microtime( true ); |
diff --git a/src/wp-includes/cron.php b/src/wp-includes/cron.php
index 60492c5..1b7edd3 100644
a
|
b
|
function spawn_cron( $gmt_time = 0 ) { |
331 | 331 | * @since 2.1.0 |
332 | 332 | */ |
333 | 333 | function wp_cron() { |
| 334 | global $current_blog; |
| 335 | |
334 | 336 | // Prevent infinite loops caused by lack of wp-cron.php |
335 | | if ( strpos($_SERVER['REQUEST_URI'], '/wp-cron.php') !== false || ( defined('DISABLE_WP_CRON') && DISABLE_WP_CRON ) ) |
| 337 | if ( strpos($_SERVER['REQUEST_URI'], '/wp-cron.php') !== false || ( defined('DISABLE_WP_CRON') && DISABLE_WP_CRON ) ) { |
336 | 338 | return; |
| 339 | } |
| 340 | |
| 341 | if ( false === $crons = _get_cron_array() ) { |
| 342 | return; |
| 343 | } |
337 | 344 | |
338 | | if ( false === $crons = _get_cron_array() ) |
| 345 | $should_skip = false; |
| 346 | // Don't process cron for suspended blogs. |
| 347 | if ( is_multisite() && ( $current_blog->archived || $current_blog->spam || $current_blog->deleted ) ) { |
| 348 | $should_skip = true; |
| 349 | } |
| 350 | /** |
| 351 | * Allow to either force skip a cron run or to force cron to run even for suspended blogs. |
| 352 | * |
| 353 | * @param bool $should_skip Whether the cron run is going to be skipped. |
| 354 | * Will be `false` for single-site or non-suspended multi-site blogs |
| 355 | * or `true` for suspended blogs. |
| 356 | * Set to `false` to force cron to run or `true` to force cron to quit. |
| 357 | * @param null|object $current_blog The blog object for which cron will run or null if not in |
| 358 | * multi-site. |
| 359 | */ |
| 360 | if ( true === apply_filters( 'skip_cron_for_blog', $should_skip, $current_blog ) ) { |
339 | 361 | return; |
| 362 | } |
| 363 | unset( $should_skip ); |
340 | 364 | |
341 | 365 | $gmt_time = microtime( true ); |
342 | 366 | $keys = array_keys( $crons ); |