Make WordPress Core

Ticket #20537: 20537-6-with-filter.patch

File 20537-6-with-filter.patch, 3.2 KB (added by jrf, 9 years ago)
  • src/wp-cron.php

    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() { 
    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$current_site = null;
     64if ( 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 */
     72if ( true === apply_filters( 'skip_cron_for_site', $should_skip, $current_site ) ) {
     73        die();
     74}
     75unset( $should_skip, $current_site );
    6076
    6177$keys = array_keys( $crons );
    6278$gmt_time = microtime( true );
  • src/wp-includes/cron.php

    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 ) { 
    336336 */
    337337function wp_cron() {
    338338        // 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 ) ) {
    340340                return;
     341        }
    341342
    342         if ( false === $crons = _get_cron_array() )
     343        if ( false === $crons = _get_cron_array() ) {
    343344                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 );
    344374
    345375        $gmt_time = microtime( true );
    346376        $keys = array_keys( $crons );