WordPress.org

Make WordPress Core

Ticket #45976: 45976.diff

File 45976.diff, 4.0 KB (added by peterwilsoncc, 7 months ago)
  • src/wp-includes/cron.php

    diff --git a/src/wp-includes/cron.php b/src/wp-includes/cron.php
    index c6bb637092..51294ec824 100644
    a b function wp_unschedule_hook( $hook ) { 
    481481/**
    482482 * Retrieve a scheduled event.
    483483 *
    484  * Retrieve the full event object for a given event.
     484 * Retrieve the full event object for a given event, if no timestamp is specified the next
     485 * scheduled event is returned.
    485486 *
    486487 * @since 5.1.0
    487488 *
    function wp_unschedule_hook( $hook ) { 
    493494 * @return bool|object The event object. False if the event does not exist.
    494495 */
    495496function wp_get_scheduled_event( $hook, $args = array(), $timestamp = null ) {
    496         if ( ! $timestamp ) {
    497                 // Get the next scheduled event.
    498                 $timestamp = wp_next_scheduled( $hook, $args );
    499         }
    500 
    501497        /**
    502498         * Filter to preflight or hijack retrieving a scheduled event.
    503499         *
    function wp_get_scheduled_event( $hook, $args = array(), $timestamp = null ) { 
    521517                return $pre;
    522518        }
    523519
    524         $crons = _get_cron_array();
    525         $key   = md5( serialize( $args ) );
     520        if ( null !== $timestamp & ! is_numeric( $timestamp ) ) {
     521                return false;
     522        }
    526523
    527         if ( ! $timestamp || ! isset( $crons[ $timestamp ] ) ) {
    528                 // No such event.
     524        $crons = _get_cron_array();
     525        if ( empty( $crons ) ) {
    529526                return false;
    530527        }
    531528
    532         if ( ! isset( $crons[ $timestamp ][ $hook ] ) || ! isset( $crons[ $timestamp ][ $hook ][ $key ] ) ) {
     529        $key = md5( serialize( $args ) );
     530
     531        if ( ! $timestamp ) {
     532                // Get next event.
     533                $next = false;
     534                foreach ( $crons as $timestamp => $cron ) {
     535                        if ( isset( $cron[ $hook ][ $key ] ) ) {
     536                                $next = $timestamp;
     537                                break;
     538                        }
     539                }
     540                if ( ! $next ) {
     541                        return false;
     542                }
     543
     544                $timestamp = $next;
     545        } elseif ( ! isset( $crons[ $timestamp ][ $hook ][ $key ] ) ) {
    533546                return false;
    534547        }
    535548
    function wp_get_scheduled_event( $hook, $args = array(), $timestamp = null ) { 
    551564 * Retrieve the next timestamp for an event.
    552565 *
    553566 * @since 2.1.0
    554  * @since 5.1.0 {@see 'pre_next_scheduled'} and {@see 'next_scheduled'} filters added.
    555567 *
    556568 * @param string $hook Action hook of the event.
    557569 * @param array  $args Optional. Array containing each separate argument to pass to the hook's callback function.
    function wp_get_scheduled_event( $hook, $args = array(), $timestamp = null ) { 
    560572 * @return false|int The Unix timestamp of the next time the event will occur. False if the event doesn't exist.
    561573 */
    562574function wp_next_scheduled( $hook, $args = array() ) {
    563         /**
    564          * Filter to preflight or hijack retrieving the next scheduled event timestamp.
    565          *
    566          * Returning a non-null value will short-circuit the normal retrieval
    567          * process, causing the function to return the filtered value instead.
    568          *
    569          * Pass the timestamp of the next event if it exists, false if not.
    570          *
    571          * @since 5.1.0
    572          *
    573          * @param null|bool $pre       Value to return instead. Default null to continue unscheduling the event.
    574          * @param string    $hook      Action hook of the event.
    575          * @param array     $args      Arguments to pass to the hook's callback function.
    576          */
    577         $pre = apply_filters( 'pre_next_scheduled', null, $hook, $args );
    578         if ( null !== $pre ) {
    579                 return $pre;
    580         }
    581 
    582         $crons = _get_cron_array();
    583         $key   = md5( serialize( $args ) );
    584         $next  = false;
    585 
    586         if ( ! empty( $crons ) ) {
    587                 foreach ( $crons as $timestamp => $cron ) {
    588                         if ( isset( $cron[ $hook ][ $key ] ) ) {
    589                                 $next = $timestamp;
    590                                 break;
    591                         }
    592                 }
     575        $next_event = wp_get_scheduled_event( $hook, $args );
     576        if ( ! $next_event ) {
     577                return false;
    593578        }
    594579
    595         /**
    596          * Filter the next scheduled event timestamp.
    597          *
    598          * @since 5.1.0
    599          *
    600          * @param int|bool $next The UNIX timestamp when the scheduled event will next occur, or false if not found.
    601          * @param string   $hook Action hook to execute when cron is run.
    602          * @param array    $args Arguments to be passed to the callback function. Used for deduplicating events.
    603          */
    604         return apply_filters( 'next_scheduled', $next, $hook, $args );
     580        return $next_event->timestamp;
    605581}
    606582
    607583/**