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/src/wp-cron.php
+++ b/src/wp-cron.php
@@ -55,8 +55,20 @@ function _get_cron_lock() {
 	return $value;
 }
 
-if ( false === $crons = _get_cron_array() )
+if ( false === $crons = _get_cron_array() ) {
 	die();
+}
+
+$should_skip = false;
+// Don't process cron for suspended blogs.
+if ( is_multisite() && ( $current_blog->archived || $current_blog->spam || $current_blog->deleted ) ) {
+	$should_skip = true;
+}
+/** This filter is documented in wp-includes/cron.php */
+if ( true === apply_filters( 'skip_cron_for_blog', $should_skip, $current_blog ) ) {
+	return;
+}
+unset( $should_skip );
 
 $keys = array_keys( $crons );
 $gmt_time = microtime( true );
diff --git a/src/wp-includes/cron.php b/src/wp-includes/cron.php
index 60492c5..1b7edd3 100644
--- a/src/wp-includes/cron.php
+++ b/src/wp-includes/cron.php
@@ -331,12 +331,36 @@ function spawn_cron( $gmt_time = 0 ) {
  * @since 2.1.0
  */
 function wp_cron() {
+	global $current_blog;
+
 	// Prevent infinite loops caused by lack of wp-cron.php
-	if ( strpos($_SERVER['REQUEST_URI'], '/wp-cron.php') !== false || ( defined('DISABLE_WP_CRON') && DISABLE_WP_CRON ) )
+	if ( strpos($_SERVER['REQUEST_URI'], '/wp-cron.php') !== false || ( defined('DISABLE_WP_CRON') && DISABLE_WP_CRON ) ) {
 		return;
+	}
+
+	if ( false === $crons = _get_cron_array() ) {
+		return;
+	}
 
-	if ( false === $crons = _get_cron_array() )
+	$should_skip = false;
+	// Don't process cron for suspended blogs.
+	if ( is_multisite() && ( $current_blog->archived || $current_blog->spam || $current_blog->deleted ) ) {
+		$should_skip = true;
+	}
+	/**
+	 * Allow to either force skip a cron run or to force cron to run even for suspended blogs.
+	 *
+	 * @param bool        $should_skip  Whether the cron run is going to be skipped.
+	 *                                  Will be `false` for single-site or non-suspended multi-site blogs
+	 *                                  or `true` for suspended blogs.
+	 *                                  Set to `false` to force cron to run or `true` to force cron to quit.
+	 * @param null|object $current_blog The blog object for which cron will run or null if not in
+	 *                                  multi-site.
+	 */
+	if ( true === apply_filters( 'skip_cron_for_blog', $should_skip, $current_blog ) ) {
 		return;
+	}
+	unset( $should_skip );
 
 	$gmt_time = microtime( true );
 	$keys = array_keys( $crons );
-- 
1.9.4.msysgit.2

