Make WordPress Core

Changeset 50394


Ignore:
Timestamp:
02/20/2021 12:09:45 PM (6 years ago)
Author:
johnbillion
Message:

Cron API: Add a missing $wp_error parameter to the pre_reschedule_event filter.

Props tmatsuur, mukesh27

Fixes #52572
See #49961

Location:
trunk
Files:
2 edited

Legend:

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

    r50175 r50394  
    399399         * @param bool               $wp_error Whether to return a WP_Error on failure.
    400400         */
    401         $pre = apply_filters( 'pre_reschedule_event', null, $event );
     401        $pre = apply_filters( 'pre_reschedule_event', null, $event, $wp_error );
    402402
    403403        if ( null !== $pre ) {
  • trunk/tests/phpunit/tests/cron.php

    r50143 r50394  
    776776         */
    777777        public function test_schedule_short_circuit_with_error_returns_false_when_wp_error_is_set_to_false() {
    778                 $return_error = function() {
     778                $return_error = function( $pre, $event, $wp_error ) {
     779                        $this->assertFalse( $wp_error );
     780
    779781                        return new WP_Error(
    780782                                'my_error',
    … …  
    784786
    785787                // Add filters which return a WP_Error:
    786                 add_filter( 'pre_schedule_event', $return_error );
    787                 add_filter( 'pre_reschedule_event', $return_error );
     788                add_filter( 'pre_schedule_event', $return_error, 10, 3 );
     789                add_filter( 'pre_reschedule_event', $return_error, 10, 3 );
    788790
    789791                // Schedule events without the `$wp_error` parameter:
    … …  
    802804         */
    803805        public function test_schedule_short_circuit_with_error_returns_error_when_wp_error_is_set_to_true() {
    804                 $return_error = function() {
     806                $return_error = function( $pre, $event, $wp_error ) {
     807                        $this->assertTrue( $wp_error );
     808
    805809                        return new WP_Error(
    806810                                'my_error',
    … …  
    810814
    811815                // Add filters which return a WP_Error:
    812                 add_filter( 'pre_schedule_event', $return_error );
    813                 add_filter( 'pre_reschedule_event', $return_error );
     816                add_filter( 'pre_schedule_event', $return_error, 10, 3 );
     817                add_filter( 'pre_reschedule_event', $return_error, 10, 3 );
    814818
    815819                // Schedule events with the `$wp_error` parameter:
    … …  
    877881         */
    878882        public function test_deprecated_argument_usage_of_wp_clear_scheduled_hook() {
    879                 add_filter(
    880                         'pre_clear_scheduled_hook',
    881                         function( $pre, $hook, $args, $wp_error ) {
    882                                 $this->assertSame( array( 1, 2, 3 ), $args );
    883                                 $this->assertFalse( $wp_error );
    884 
    885                                 return $pre;
    886                         },
    887                         10,
    888                         4
    889                 );
     883                $return_pre = function( $pre, $hook, $args, $wp_error ) {
     884                        $this->assertSame( array( 1, 2, 3 ), $args );
     885                        $this->assertFalse( $wp_error );
     886
     887                        return $pre;
     888                };
     889
     890                add_filter( 'pre_clear_scheduled_hook', $return_pre, 10, 4 );
    890891
    891892                $cleared = wp_clear_scheduled_hook( 'hook', 1, 2, 3 );
    … …  
    919920         */
    920921        public function test_clear_scheduled_hook_returns_custom_pre_filter_error_when_wp_error_is_set_to_true() {
    921                 add_filter(
    922                         'pre_unschedule_event',
    923                         function( $pre ) {
    924                                 return new WP_Error( 'error_code', 'error message' );
    925                         }
    926                 );
     922                $return_error = function( $pre, $timestamp, $hook, $args, $wp_error ) {
     923                        $this->assertTrue( $wp_error );
     924
     925                        return new WP_Error( 'error_code', 'error message' );
     926                };
     927
     928                add_filter( 'pre_unschedule_event', $return_error, 10, 5 );
    927929
    928930                wp_schedule_single_event( strtotime( '+1 hour' ), 'test_hook' );
    … …  
    951953         */
    952954        public function test_unschedule_short_circuit_with_error_returns_false_when_wp_error_is_set_to_false() {
    953                 $return_error = function() {
     955                $return_error = function( $pre, $hook, $wp_error ) {
     956                        $this->assertFalse( $wp_error );
     957
    954958                        return new WP_Error(
    955959                                'my_error',
    … …  
    959963
    960964                // Add a filter which returns a WP_Error:
    961                 add_filter( 'pre_unschedule_hook', $return_error );
     965                add_filter( 'pre_unschedule_hook', $return_error, 10, 3 );
    962966
    963967                // Unschedule a hook without the `$wp_error` parameter:
    … …  
    972976         */
    973977        public function test_unschedule_short_circuit_with_error_returns_error_when_wp_error_is_set_to_true() {
    974                 $return_error = function() {
     978                $return_error = function( $pre, $hook, $wp_error ) {
     979                        $this->assertTrue( $wp_error );
     980
    975981                        return new WP_Error(
    976982                                'my_error',
    … …  
    980986
    981987                // Add a filter which returns a WP_Error:
    982                 add_filter( 'pre_unschedule_hook', $return_error );
     988                add_filter( 'pre_unschedule_hook', $return_error, 10, 3 );
    983989
    984990                // Unschedule a hook with the `$wp_error` parameter:
Note: See TracChangeset for help on using the changeset viewer.