Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (8 years ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-cron.php

    r41276 r42343  
    1717 */
    1818
    19 ignore_user_abort(true);
     19ignore_user_abort( true );
    2020
    21 if ( !empty($_POST) || defined('DOING_AJAX') || defined('DOING_CRON') )
     21if ( ! empty( $_POST ) || defined( 'DOING_AJAX' ) || defined( 'DOING_CRON' ) ) {
    2222    die();
     23}
    2324
    2425/**
     
    2728 * @var bool
    2829 */
    29 define('DOING_CRON', true);
     30define( 'DOING_CRON', true );
    3031
    31 if ( !defined('ABSPATH') ) {
     32if ( ! defined( 'ABSPATH' ) ) {
    3233    /** Set up WordPress environment */
    3334    require_once( dirname( __FILE__ ) . '/wp-load.php' );
     
    5859    } else {
    5960        $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", '_transient_doing_cron' ) );
    60         if ( is_object( $row ) )
     61        if ( is_object( $row ) ) {
    6162            $value = $row->option_value;
     63        }
    6264    }
    6365
     
    6567}
    6668
    67 if ( false === $crons = _get_cron_array() )
     69if ( false === $crons = _get_cron_array() ) {
    6870    die();
     71}
    6972
    70 $keys = array_keys( $crons );
     73$keys     = array_keys( $crons );
    7174$gmt_time = microtime( true );
    7275
    73 if ( isset($keys[0]) && $keys[0] > $gmt_time )
     76if ( isset( $keys[0] ) && $keys[0] > $gmt_time ) {
    7477    die();
     78}
    7579
    7680
     
    8084// Use global $doing_wp_cron lock otherwise use the GET lock. If no lock, trying grabbing a new lock.
    8185if ( empty( $doing_wp_cron ) ) {
    82     if ( empty( $_GET[ 'doing_wp_cron' ] ) ) {
     86    if ( empty( $_GET['doing_wp_cron'] ) ) {
    8387        // Called from external script/job. Try setting a lock.
    84         if ( $doing_cron_transient && ( $doing_cron_transient + WP_CRON_LOCK_TIMEOUT > $gmt_time ) )
     88        if ( $doing_cron_transient && ( $doing_cron_transient + WP_CRON_LOCK_TIMEOUT > $gmt_time ) ) {
    8589            return;
     90        }
    8691        $doing_cron_transient = $doing_wp_cron = sprintf( '%.22F', microtime( true ) );
    8792        set_transient( 'doing_cron', $doing_wp_cron );
    8893    } else {
    89         $doing_wp_cron = $_GET[ 'doing_wp_cron' ];
     94        $doing_wp_cron = $_GET['doing_wp_cron'];
    9095    }
    9196}
     
    95100 * must match $doing_wp_cron (the "key").
    96101 */
    97 if ( $doing_cron_transient != $doing_wp_cron )
     102if ( $doing_cron_transient != $doing_wp_cron ) {
    98103    return;
     104}
    99105
    100106foreach ( $crons as $timestamp => $cronhooks ) {
    101     if ( $timestamp > $gmt_time )
     107    if ( $timestamp > $gmt_time ) {
    102108        break;
     109    }
    103110
    104111    foreach ( $cronhooks as $hook => $keys ) {
     
    109116
    110117            if ( $schedule != false ) {
    111                 $new_args = array($timestamp, $schedule, $hook, $v['args']);
    112                 call_user_func_array('wp_reschedule_event', $new_args);
     118                $new_args = array( $timestamp, $schedule, $hook, $v['args'] );
     119                call_user_func_array( 'wp_reschedule_event', $new_args );
    113120            }
    114121
     
    124131             * @param array  $args The arguments to be passed to the hook.
    125132             */
    126             do_action_ref_array( $hook, $v['args'] );
     133            do_action_ref_array( $hook, $v['args'] );
    127134
    128135            // If the hook ran too long and another cron process stole the lock, quit.
    129             if ( _get_cron_lock() != $doing_wp_cron )
     136            if ( _get_cron_lock() != $doing_wp_cron ) {
    130137                return;
     138            }
    131139        }
    132140    }
    133141}
    134142
    135 if ( _get_cron_lock() == $doing_wp_cron )
     143if ( _get_cron_lock() == $doing_wp_cron ) {
    136144    delete_transient( 'doing_cron' );
     145}
    137146
    138147die();
Note: See TracChangeset for help on using the changeset viewer.