Make WordPress Core

Ticket #52572: 52572.3.diff

File 52572.3.diff, 4.6 KB (added by johnbillion, 2 years ago)
  • src/wp-includes/cron.php

     
    398398         * }
    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 ) {
    404404                if ( $wp_error && false === $pre ) {
  • tests/phpunit/tests/cron.php

     
    775775         * @ticket 49961
    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',
    781783                                'An error ocurred'
     
    783785                };
    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:
    790792                $single_event      = wp_schedule_single_event( time(), 'hook', array() );
     
    801803         * @ticket 49961
    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',
    807811                                'An error ocurred'
     
    809813                };
    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:
    816820                $single_event      = wp_schedule_single_event( time(), 'hook', array(), true );
     
    876880         * @expectedDeprecated wp_clear_scheduled_hook
    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 );
     883                $return_pre = function( $pre, $hook, $args, $wp_error ) {
     884                        $this->assertSame( array( 1, 2, 3 ), $args );
     885                        $this->assertFalse( $wp_error );
    884886
    885                                 return $pre;
    886                         },
    887                         10,
    888                         4
    889                 );
     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 );
    892893
     
    920921        public function test_clear_scheduled_hook_returns_custom_pre_filter_error_when_wp_error_is_set_to_true() {
    921922                add_filter(
    922923                        'pre_unschedule_event',
    923                         function( $pre ) {
     924                        function( $pre, $timestamp, $hook, $args, $wp_error ) {
     925                                $this->assertTrue( $wp_error );
     926
    924927                                return new WP_Error( 'error_code', 'error message' );
    925                         }
     928                        },
     929                        10,
     930                        5
    926931                );
    927932
    928933                wp_schedule_single_event( strtotime( '+1 hour' ), 'test_hook' );
     
    950955         * @ticket 49961
    951956         */
    952957        public function test_unschedule_short_circuit_with_error_returns_false_when_wp_error_is_set_to_false() {
    953                 $return_error = function() {
     958                $return_error = function( $pre, $hook, $wp_error ) {
     959                        $this->assertFalse( $wp_error );
     960
    954961                        return new WP_Error(
    955962                                'my_error',
    956963                                'An error ocurred'
     
    958965                };
    959966
    960967                // Add a filter which returns a WP_Error:
    961                 add_filter( 'pre_unschedule_hook', $return_error );
     968                add_filter( 'pre_unschedule_hook', $return_error, 10, 3 );
    962969
    963970                // Unschedule a hook without the `$wp_error` parameter:
    964971                $result = wp_unschedule_hook( 'hook' );
     
    971978         * @ticket 49961
    972979         */
    973980        public function test_unschedule_short_circuit_with_error_returns_error_when_wp_error_is_set_to_true() {
    974                 $return_error = function() {
     981                $return_error = function( $pre, $hook, $wp_error ) {
     982                        $this->assertTrue( $wp_error );
     983
    975984                        return new WP_Error(
    976985                                'my_error',
    977986                                'An error ocurred'
     
    979988                };
    980989
    981990                // Add a filter which returns a WP_Error:
    982                 add_filter( 'pre_unschedule_hook', $return_error );
     991                add_filter( 'pre_unschedule_hook', $return_error, 10, 3 );
    983992
    984993                // Unschedule a hook with the `$wp_error` parameter:
    985994                $result = wp_unschedule_hook( 'hook', true );