mirror of
https://github.com/WordPress/WordPress.git
synced 2025-01-03 06:57:35 +01:00
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. Built from https://develop.svn.wordpress.org/trunk@56394 git-svn-id: http://core.svn.wordpress.org/trunk@55906 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
0c05aa75e8
commit
22f80e9382
@ -139,9 +139,11 @@ function wp_schedule_single_event( $timestamp, $hook, $args = array(), $wp_error
|
||||
if ( $event_timestamp < $min_timestamp ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( $event_timestamp > $max_timestamp ) {
|
||||
break;
|
||||
}
|
||||
|
||||
if ( isset( $cron[ $event->hook ][ $key ] ) ) {
|
||||
$duplicate = true;
|
||||
break;
|
||||
@ -359,6 +361,7 @@ function wp_reschedule_event( $timestamp, $recurrence, $hook, $args = array(), $
|
||||
// Now we try to get it from the saved interval in case the schedule disappears.
|
||||
if ( 0 === $interval ) {
|
||||
$scheduled_event = wp_get_scheduled_event( $hook, $args, $timestamp );
|
||||
|
||||
if ( $scheduled_event && isset( $scheduled_event->interval ) ) {
|
||||
$interval = $scheduled_event->interval;
|
||||
}
|
||||
@ -414,7 +417,7 @@ function wp_reschedule_event( $timestamp, $recurrence, $hook, $args = array(), $
|
||||
}
|
||||
|
||||
// Now we assume something is wrong and fail to schedule.
|
||||
if ( 0 == $interval ) {
|
||||
if ( 0 === $interval ) {
|
||||
if ( $wp_error ) {
|
||||
return new WP_Error(
|
||||
'invalid_schedule',
|
||||
@ -506,10 +509,13 @@ function wp_unschedule_event( $timestamp, $hook, $args = array(), $wp_error = fa
|
||||
|
||||
$crons = _get_cron_array();
|
||||
$key = md5( serialize( $args ) );
|
||||
|
||||
unset( $crons[ $timestamp ][ $hook ][ $key ] );
|
||||
|
||||
if ( empty( $crons[ $timestamp ][ $hook ] ) ) {
|
||||
unset( $crons[ $timestamp ][ $hook ] );
|
||||
}
|
||||
|
||||
if ( empty( $crons[ $timestamp ] ) ) {
|
||||
unset( $crons[ $timestamp ] );
|
||||
}
|
||||
@ -546,7 +552,12 @@ function wp_clear_scheduled_hook( $hook, $args = array(), $wp_error = false ) {
|
||||
* Previously, this function took the arguments as discrete vars rather than an array like the rest of the API.
|
||||
*/
|
||||
if ( ! is_array( $args ) ) {
|
||||
_deprecated_argument( __FUNCTION__, '3.0.0', __( 'This argument has changed to an array to match the behavior of the other cron functions.' ) );
|
||||
_deprecated_argument(
|
||||
__FUNCTION__,
|
||||
'3.0.0',
|
||||
__( 'This argument has changed to an array to match the behavior of the other cron functions.' )
|
||||
);
|
||||
|
||||
$args = array_slice( func_get_args(), 1 ); // phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection
|
||||
$wp_error = false;
|
||||
}
|
||||
@ -681,10 +692,12 @@ function wp_unschedule_hook( $hook, $wp_error = false ) {
|
||||
}
|
||||
|
||||
$results = array();
|
||||
|
||||
foreach ( $crons as $timestamp => $args ) {
|
||||
if ( ! empty( $crons[ $timestamp ][ $hook ] ) ) {
|
||||
$results[] = count( $crons[ $timestamp ][ $hook ] );
|
||||
}
|
||||
|
||||
unset( $crons[ $timestamp ][ $hook ] );
|
||||
|
||||
if ( empty( $crons[ $timestamp ] ) ) {
|
||||
@ -754,6 +767,7 @@ function wp_get_scheduled_event( $hook, $args = array(), $timestamp = null ) {
|
||||
* @param int|null $timestamp Unix timestamp (UTC) of the event. Null to retrieve next scheduled event.
|
||||
*/
|
||||
$pre = apply_filters( 'pre_get_scheduled_event', null, $hook, $args, $timestamp );
|
||||
|
||||
if ( null !== $pre ) {
|
||||
return $pre;
|
||||
}
|
||||
@ -778,6 +792,7 @@ function wp_get_scheduled_event( $hook, $args = array(), $timestamp = null ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! $next ) {
|
||||
return false;
|
||||
}
|
||||
@ -815,6 +830,7 @@ function wp_get_scheduled_event( $hook, $args = array(), $timestamp = null ) {
|
||||
*/
|
||||
function wp_next_scheduled( $hook, $args = array() ) {
|
||||
$next_event = wp_get_scheduled_event( $hook, $args );
|
||||
|
||||
if ( ! $next_event ) {
|
||||
return false;
|
||||
}
|
||||
@ -930,6 +946,7 @@ function spawn_cron( $gmt_time = 0 ) {
|
||||
);
|
||||
|
||||
$result = wp_remote_post( $cron_request['url'], $cron_request['args'] );
|
||||
|
||||
return ! is_wp_error( $result );
|
||||
}
|
||||
|
||||
@ -976,7 +993,9 @@ function wp_cron() {
|
||||
*/
|
||||
function _wp_cron() {
|
||||
// Prevent infinite loops caused by lack of wp-cron.php.
|
||||
if ( str_contains( $_SERVER['REQUEST_URI'], '/wp-cron.php' ) || ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ) ) {
|
||||
if ( str_contains( $_SERVER['REQUEST_URI'], '/wp-cron.php' )
|
||||
|| ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON )
|
||||
) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -993,14 +1012,19 @@ function _wp_cron() {
|
||||
|
||||
$schedules = wp_get_schedules();
|
||||
$results = array();
|
||||
|
||||
foreach ( $crons as $timestamp => $cronhooks ) {
|
||||
if ( $timestamp > $gmt_time ) {
|
||||
break;
|
||||
}
|
||||
|
||||
foreach ( (array) $cronhooks as $hook => $args ) {
|
||||
if ( isset( $schedules[ $hook ]['callback'] ) && ! call_user_func( $schedules[ $hook ]['callback'] ) ) {
|
||||
if ( isset( $schedules[ $hook ]['callback'] )
|
||||
&& ! call_user_func( $schedules[ $hook ]['callback'] )
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$results[] = spawn_cron( $gmt_time );
|
||||
break 2;
|
||||
}
|
||||
@ -1009,6 +1033,7 @@ function _wp_cron() {
|
||||
if ( in_array( false, $results, true ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return count( $results );
|
||||
}
|
||||
|
||||
@ -1213,6 +1238,7 @@ function _set_cron_array( $cron, $wp_error = false ) {
|
||||
}
|
||||
|
||||
$cron['version'] = 2;
|
||||
|
||||
$result = update_option( 'cron', $cron );
|
||||
|
||||
if ( $wp_error && ! $result ) {
|
||||
@ -1237,7 +1263,7 @@ function _set_cron_array( $cron, $wp_error = false ) {
|
||||
* @return array An upgraded cron info array.
|
||||
*/
|
||||
function _upgrade_cron_array( $cron ) {
|
||||
if ( isset( $cron['version'] ) && 2 == $cron['version'] ) {
|
||||
if ( isset( $cron['version'] ) && 2 === $cron['version'] ) {
|
||||
return $cron;
|
||||
}
|
||||
|
||||
@ -1246,11 +1272,14 @@ function _upgrade_cron_array( $cron ) {
|
||||
foreach ( (array) $cron as $timestamp => $hooks ) {
|
||||
foreach ( (array) $hooks as $hook => $args ) {
|
||||
$key = md5( serialize( $args['args'] ) );
|
||||
|
||||
$new_cron[ $timestamp ][ $hook ][ $key ] = $args;
|
||||
}
|
||||
}
|
||||
|
||||
$new_cron['version'] = 2;
|
||||
|
||||
update_option( 'cron', $new_cron );
|
||||
|
||||
return $new_cron;
|
||||
}
|
||||
|
@ -16,7 +16,7 @@
|
||||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '6.4-alpha-56393';
|
||||
$wp_version = '6.4-alpha-56394';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
Loading…
Reference in New Issue
Block a user