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/src/wp-cron.php
+++ b/src/wp-cron.php
@@ -55,8 +55,24 @@ function _get_cron_lock() {
 	return $value;
 }
 
-if ( false === $crons = _get_cron_array() )
+if ( false === $crons = _get_cron_array() ) {
 	die();
+}
+
+$should_skip  = false;
+$current_site = null;
+if ( is_multisite() ) {
+	$current_site = get_blog_details();
+	// Don't process cron for suspended blogs.
+	if ( $current_site->archived || $current_site->spam || $current_site->deleted ) {
+		$should_skip = true;
+	}
+}
+/** This filter is documented in wp-includes/cron.php */
+if ( true === apply_filters( 'skip_cron_for_site', $should_skip, $current_site ) ) {
+	die();
+}
+unset( $should_skip, $current_site );
 
 $keys = array_keys( $crons );
 $gmt_time = microtime( true );
diff --git a/src/wp-includes/cron.php b/src/wp-includes/cron.php
index 493e0ec..b4dcf97 100644
--- a/src/wp-includes/cron.php
+++ b/src/wp-includes/cron.php
@@ -336,11 +336,41 @@ function spawn_cron( $gmt_time = 0 ) {
  */
 function wp_cron() {
 	// 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() )
+	if ( false === $crons = _get_cron_array() ) {
 		return;
+	}
+
+	$should_skip  = false;
+	$current_site = null;
+	if ( is_multisite() ) {
+		$current_site = get_blog_details();
+		// Don't process cron for suspended sites.
+		if ( $current_site->archived || $current_site->spam || $current_site->deleted ) {
+			$should_skip = true;
+		}
+	}
+	/**
+	 * Allow to either force skip a cron run or to force cron to run even for suspended sites.
+	 *
+	 * @since 4.6.0
+	 *
+	 * @param bool        $should_skip  Whether the cron run is going to be skipped.
+	 *                                  Will be `false` for single-site or non-suspended site within multi-site
+	 *                                  or `true` for suspended sites.
+	 *                                  Sites are regarded as suspended if they are either archived, marked
+	 *                                  as spam or marked as deleted.
+	 *                                  Set to `false` to force cron to run or `true` to force cron to quit.
+	 * @param null|object $current_site The WP_Site object for which cron will run or null if not in
+	 *                                  multi-site.
+	 */
+	if ( true === apply_filters( 'skip_cron_for_site', $should_skip, $current_site ) ) {
+		return;
+	}
+	unset( $should_skip, $current_site );
 
 	$gmt_time = microtime( true );
 	$keys = array_keys( $crons );
-- 
1.9.4.msysgit.2

