Make WordPress Core

Ticket #20537: 20537-with-filter.patch

File 20537-with-filter.patch, 2.8 KB (added by jrf, 9 years ago)

Refreshed patch, including filter which allows to force skip/force run cron anyhow.

  • src/wp-cron.php

    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() { 
    5555        return $value;
    5656}
    5757
    58 if ( false === $crons = _get_cron_array() )
     58if ( false === $crons = _get_cron_array() ) {
    5959        die();
     60}
     61
     62$should_skip = false;
     63// Don't process cron for suspended blogs.
     64if ( 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 */
     68if ( true === apply_filters( 'skip_cron_for_blog', $should_skip, $current_blog ) ) {
     69        return;
     70}
     71unset( $should_skip );
    6072
    6173$keys = array_keys( $crons );
    6274$gmt_time = microtime( true );
  • src/wp-includes/cron.php

    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 ) { 
    331331 * @since 2.1.0
    332332 */
    333333function wp_cron() {
     334        global $current_blog;
     335
    334336        // 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 ) ) {
    336338                return;
     339        }
     340
     341        if ( false === $crons = _get_cron_array() ) {
     342                return;
     343        }
    337344
    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 ) ) {
    339361                return;
     362        }
     363        unset( $should_skip );
    340364
    341365        $gmt_time = microtime( true );
    342366        $keys = array_keys( $crons );