Make WordPress Core

Changeset 56394


Ignore:
Timestamp:
08/12/2023 12:00:27 PM (15 months ago)
Author:
SergeyBiryukov
Message:

Coding Standards: Use strict comparison in wp-includes/cron.php.

Includes minor code layout fixes for better readability.

Follow-up to [3634], [4189].

Props aristath, poena, afercia, SergeyBiryukov.
See #58831.

File:
1 edited

Legend:

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

    r56180 r56394  
    140140            continue;
    141141        }
     142
    142143        if ( $event_timestamp > $max_timestamp ) {
    143144            break;
    144145        }
     146
    145147        if ( isset( $cron[ $event->hook ][ $key ] ) ) {
    146148            $duplicate = true;
     
    360362    if ( 0 === $interval ) {
    361363        $scheduled_event = wp_get_scheduled_event( $hook, $args, $timestamp );
     364
    362365        if ( $scheduled_event && isset( $scheduled_event->interval ) ) {
    363366            $interval = $scheduled_event->interval;
     
    415418
    416419    // Now we assume something is wrong and fail to schedule.
    417     if ( 0 == $interval ) {
     420    if ( 0 === $interval ) {
    418421        if ( $wp_error ) {
    419422            return new WP_Error(
     
    507510    $crons = _get_cron_array();
    508511    $key   = md5( serialize( $args ) );
     512
    509513    unset( $crons[ $timestamp ][ $hook ][ $key ] );
     514
    510515    if ( empty( $crons[ $timestamp ][ $hook ] ) ) {
    511516        unset( $crons[ $timestamp ][ $hook ] );
    512517    }
     518
    513519    if ( empty( $crons[ $timestamp ] ) ) {
    514520        unset( $crons[ $timestamp ] );
     
    547553     */
    548554    if ( ! is_array( $args ) ) {
    549         _deprecated_argument( __FUNCTION__, '3.0.0', __( 'This argument has changed to an array to match the behavior of the other cron functions.' ) );
     555        _deprecated_argument(
     556            __FUNCTION__,
     557            '3.0.0',
     558            __( 'This argument has changed to an array to match the behavior of the other cron functions.' )
     559        );
     560
    550561        $args     = array_slice( func_get_args(), 1 ); // phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection
    551562        $wp_error = false;
     
    682693
    683694    $results = array();
     695
    684696    foreach ( $crons as $timestamp => $args ) {
    685697        if ( ! empty( $crons[ $timestamp ][ $hook ] ) ) {
    686698            $results[] = count( $crons[ $timestamp ][ $hook ] );
    687699        }
     700
    688701        unset( $crons[ $timestamp ][ $hook ] );
    689702
     
    755768     */
    756769    $pre = apply_filters( 'pre_get_scheduled_event', null, $hook, $args, $timestamp );
     770
    757771    if ( null !== $pre ) {
    758772        return $pre;
     
    779793            }
    780794        }
     795
    781796        if ( ! $next ) {
    782797            return false;
     
    816831function wp_next_scheduled( $hook, $args = array() ) {
    817832    $next_event = wp_get_scheduled_event( $hook, $args );
     833
    818834    if ( ! $next_event ) {
    819835        return false;
     
    931947
    932948    $result = wp_remote_post( $cron_request['url'], $cron_request['args'] );
     949
    933950    return ! is_wp_error( $result );
    934951}
     
    977994function _wp_cron() {
    978995    // Prevent infinite loops caused by lack of wp-cron.php.
    979     if ( str_contains( $_SERVER['REQUEST_URI'], '/wp-cron.php' ) || ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ) ) {
     996    if ( str_contains( $_SERVER['REQUEST_URI'], '/wp-cron.php' )
     997        || ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON )
     998    ) {
    980999        return 0;
    9811000    }
     
    9941013    $schedules = wp_get_schedules();
    9951014    $results   = array();
     1015
    9961016    foreach ( $crons as $timestamp => $cronhooks ) {
    9971017        if ( $timestamp > $gmt_time ) {
    9981018            break;
    9991019        }
     1020
    10001021        foreach ( (array) $cronhooks as $hook => $args ) {
    1001             if ( isset( $schedules[ $hook ]['callback'] ) && ! call_user_func( $schedules[ $hook ]['callback'] ) ) {
     1022            if ( isset( $schedules[ $hook ]['callback'] )
     1023                && ! call_user_func( $schedules[ $hook ]['callback'] )
     1024            ) {
    10021025                continue;
    10031026            }
     1027
    10041028            $results[] = spawn_cron( $gmt_time );
    10051029            break 2;
     
    10101034        return false;
    10111035    }
     1036
    10121037    return count( $results );
    10131038}
     
    12141239
    12151240    $cron['version'] = 2;
    1216     $result          = update_option( 'cron', $cron );
     1241
     1242    $result = update_option( 'cron', $cron );
    12171243
    12181244    if ( $wp_error && ! $result ) {
     
    12381264 */
    12391265function _upgrade_cron_array( $cron ) {
    1240     if ( isset( $cron['version'] ) && 2 == $cron['version'] ) {
     1266    if ( isset( $cron['version'] ) && 2 === $cron['version'] ) {
    12411267        return $cron;
    12421268    }
     
    12461272    foreach ( (array) $cron as $timestamp => $hooks ) {
    12471273        foreach ( (array) $hooks as $hook => $args ) {
    1248             $key                                     = md5( serialize( $args['args'] ) );
     1274            $key = md5( serialize( $args['args'] ) );
     1275
    12491276            $new_cron[ $timestamp ][ $hook ][ $key ] = $args;
    12501277        }
     
    12521279
    12531280    $new_cron['version'] = 2;
     1281
    12541282    update_option( 'cron', $new_cron );
     1283
    12551284    return $new_cron;
    12561285}
Note: See TracChangeset for help on using the changeset viewer.