Make WordPress Core

Ticket #34913: 34913.diff

File 34913.diff, 8.4 KB (added by peterwilsoncc, 7 years ago)
  • src/wp-admin/includes/upgrade.php

    diff --git src/wp-admin/includes/upgrade.php src/wp-admin/includes/upgrade.php
    index f8b871db49..84ffd5d359 100644
    function upgrade_all() { 
    793793                upgrade_460();
    794794        }
    795795
     796        if ( $wp_current_db_version < 43680 ) {
     797                upgrade_510();
     798        }
     799
    796800        maybe_disable_link_manager();
    797801
    798802        maybe_disable_automattic_widgets();
    function upgrade_460() { 
    20692073        }
    20702074}
    20712075
     2076/**
     2077 * Executes changes made in WordPress 5.1.0.
     2078 *
     2079 * @ignore
     2080 * @since 5.1.0
     2081 *
     2082 * @global int $wp_current_db_version Current database version.
     2083 */
     2084function upgrade_510() {
     2085        global $wp_current_db_version;
     2086
     2087        // Getting the cron array will automatically update it to version 3.
     2088        if ( $wp_current_db_version < 43680 ) {
     2089                _get_cron_array();
     2090        }
     2091}
     2092
    20722093/**
    20732094 * Executes network-level upgrade routines.
    20742095 *
  • src/wp-includes/cron.php

    diff --git src/wp-includes/cron.php src/wp-includes/cron.php
    index db3fc51601..bf20179f86 100644
     
    3232 * @return bool True if event successfully scheduled. False for failure.
    3333 */
    3434function wp_schedule_single_event( $timestamp, $hook, $args = array() ) {
     35        if ( ! is_array( $args ) ) {
     36                _doing_it_wrong( __FUNCTION__, __( 'Cron arguments are expected to be an array. Please update your function call.' ), '2.1.0' );
     37                $args = _cron_cast_to_array_helper( $args );
     38        }
    3539        // Make sure timestamp is a positive integer
    3640        if ( ! is_numeric( $timestamp ) || $timestamp <= 0 ) {
    3741                return false;
    function wp_schedule_single_event( $timestamp, $hook, $args = array() ) { 
    149153 * @return bool True if event successfully scheduled. False for failure.
    150154 */
    151155function wp_schedule_event( $timestamp, $recurrence, $hook, $args = array() ) {
     156        if ( ! is_array( $args ) ) {
     157                _doing_it_wrong( __FUNCTION__, __( 'Cron arguments are expected to be an array. Please update your function call.' ), '2.1.0' );
     158                $args = _cron_cast_to_array_helper( $args );
     159        }
    152160        // Make sure timestamp is a positive integer
    153161        if ( ! is_numeric( $timestamp ) || $timestamp <= 0 ) {
    154162                return false;
    function wp_schedule_event( $timestamp, $recurrence, $hook, $args = array() ) { 
    214222 * @return bool True if event successfully rescheduled. False for failure.
    215223 */
    216224function wp_reschedule_event( $timestamp, $recurrence, $hook, $args = array() ) {
     225        if ( ! is_array( $args ) ) {
     226                _doing_it_wrong( __FUNCTION__, __( 'Cron arguments are expected to be an array. Please update your function call.' ), '2.1.0' );
     227                $args = _cron_cast_to_array_helper( $args );
     228        }
    217229        // Make sure timestamp is a positive integer
    218230        if ( ! is_numeric( $timestamp ) || $timestamp <= 0 ) {
    219231                return false;
    function wp_unschedule_event( $timestamp, $hook, $args = array() ) { 
    308320        if ( ! is_numeric( $timestamp ) || $timestamp <= 0 ) {
    309321                return false;
    310322        }
     323        if ( ! is_array( $args ) ) {
     324                _doing_it_wrong( __FUNCTION__, __( 'Cron arguments are expected to be an array. Please update your function call.' ), '2.1.0' );
     325                $args = _cron_cast_to_array_helper( $args );
     326        }
    311327
    312328        /**
    313329         * Filter to preflight or hijack unscheduling of events.
    function wp_unschedule_hook( $hook ) { 
    493509 * @return bool|object The event object. False if the event does not exist.
    494510 */
    495511function wp_get_scheduled_event( $hook, $args = array(), $timestamp = null ) {
     512        if ( ! is_array( $args ) ) {
     513                _doing_it_wrong( __FUNCTION__, __( 'Cron arguments are expected to be an array. Please update your function call.' ), '2.1.0' );
     514                $args = _cron_cast_to_array_helper( $args );
     515        }
    496516        if ( ! $timestamp ) {
    497517                // Get the next scheduled event.
    498518                $timestamp = wp_next_scheduled( $hook, $args );
    function wp_get_scheduled_event( $hook, $args = array(), $timestamp = null ) { 
    560580 * @return false|int The Unix timestamp of the next time the event will occur. False if the event doesn't exist.
    561581 */
    562582function wp_next_scheduled( $hook, $args = array() ) {
     583        if ( ! is_array( $args ) ) {
     584                _doing_it_wrong( __FUNCTION__, __( 'Cron arguments are expected to be an array. Please update your function call.' ), '2.1.0' );
     585                $args = _cron_cast_to_array_helper( $args );
     586        }
    563587        /**
    564588         * Filter to preflight or hijack retrieving the next scheduled event timestamp.
    565589         *
    function _get_cron_array() { 
    872896                return false;
    873897        }
    874898
    875         if ( ! isset( $cron['version'] ) ) {
     899        if ( ! isset( $cron['version'] ) || $cron['version'] < 3 ) {
    876900                $cron = _upgrade_cron_array( $cron );
    877901        }
    878902
    function _get_cron_array() { 
    885909 * Updates the CRON option with the new CRON array.
    886910 *
    887911 * @since 2.1.0
    888  * @since 5.0.0 Return value modified to outcome of {@see update_option}.
     912 * @since 5.1.0 Return value modified to outcome of {@see update_option}.
    889913 *
    890914 * @access private
    891915 *
    function _get_cron_array() { 
    893917 * @return bool True if cron array updated, false on failure.
    894918 */
    895919function _set_cron_array( $cron ) {
    896         $cron['version'] = 2;
     920        $cron['version'] = 3;
    897921        return update_option( 'cron', $cron );
    898922}
    899923
    function _set_cron_array( $cron ) { 
    909933 * @return array An upgraded Cron info array.
    910934 */
    911935function _upgrade_cron_array( $cron ) {
    912         if ( isset( $cron['version'] ) && 2 == $cron['version'] ) {
     936        if ( isset( $cron['version'] ) && 3 === $cron['version'] ) {
    913937                return $cron;
    914938        }
    915939
    916940        $new_cron = array();
    917941
    918942        foreach ( (array) $cron as $timestamp => $hooks ) {
    919                 foreach ( (array) $hooks as $hook => $args ) {
    920                         $key                                     = md5( serialize( $args['args'] ) );
    921                         $new_cron[ $timestamp ][ $hook ][ $key ] = $args;
     943                foreach ( (array) $hooks as $hook => $event ) {
     944                        $event['args']                           = _cron_cast_to_array_helper( $event );
     945                        $key                                     = md5( serialize( $event['args'] ) );
     946                        $new_cron[ $timestamp ][ $hook ][ $key ] = $event;
    922947                }
    923948        }
    924949
    925         $new_cron['version'] = 2;
     950        $new_cron['version'] = 3;
    926951        update_option( 'cron', $new_cron );
    927952        return $new_cron;
    928953}
     954
     955/**
     956 * Compatibility function for consistent casting to array of cron arguments.
     957 *
     958 * @since 5.1.0
     959 *
     960 * @access private
     961 *
     962 * @param mixed $args Cron arguments.
     963 * @return array
     964 */
     965function _cron_cast_to_array_helper( $args ) {
     966        if ( is_object( $args ) ) {
     967                return array( $args );
     968        }
     969        return (array) $args;
     970}
  • src/wp-includes/version.php

    diff --git src/wp-includes/version.php src/wp-includes/version.php
    index d479d97724..0d4da23167 100644
    $wp_version = '5.1-alpha-43677-src'; 
    2020 *
    2121 * @global int $wp_db_version
    2222 */
    23 $wp_db_version = 42836;
     23$wp_db_version = 43680;
    2424
    2525/**
    2626 * Holds the TinyMCE version
  • tests/phpunit/tests/cron.php

    diff --git tests/phpunit/tests/cron.php tests/phpunit/tests/cron.php
    index 8b9878e53c..15a02a48a5 100644
    class Tests_Cron extends WP_UnitTestCase { 
    259259                $this->assertFalse( wp_next_scheduled( $hook ) );
    260260        }
    261261
     262        /**
     263         * Ensure cron events created without arguments as an array can be unscheduled.
     264         *
     265         * @ticket 34913
     266         *
     267         * @dataProvider data_clear_schedule_non_array_args
     268         *
     269         * @expectedDeprecated wp_clear_scheduled_hook
     270         * @expectedIncorrectUsage wp_schedule_single_event
     271         * @expectedIncorrectUsage wp_next_scheduled
     272         */
     273        function test_clear_schedule_non_array_args( $args ) {
     274                $hook = __FUNCTION__;
     275                $timestamp = strtotime('+1 hour' );
     276
     277                // Schedule event with non-array arguments.
     278                wp_schedule_single_event( $timestamp, $hook, $args );
     279
     280                // Make sure it's returned by wp_next_scheduled().
     281                $this->assertEquals( $timestamp, wp_next_scheduled( $hook, $args ) );
     282
     283                // Make sure it was converted to an array.
     284                $this->assertEquals( $timestamp, wp_next_scheduled( $hook, array( $args ) ) );
     285
     286                // Clear the schedule and make sure it's gone.
     287                wp_clear_scheduled_hook( $hook, $args );
     288                $this->assertFalse( wp_next_scheduled( $hook, $args ) );
     289                $this->assertFalse( wp_next_scheduled( $hook, array( $args ) ) );
     290        }
     291
     292        /**
     293         * Data provider for test_clear_schedule_non_array_args.
     294         *
     295         * @return array {
     296         *     @type array $0... {
     297         *         @type mixed $0 Cron arguments.
     298         *     }
     299         * }
     300         */
     301        function data_clear_schedule_non_array_args() {
     302                return array(
     303                        // Boolean
     304                        array( true ),
     305
     306                        // Integer
     307                        array( 34913 ),
     308
     309                        // Float
     310                        array( 34.913 ),
     311
     312                        // String
     313                        array( 'Ticket 34913' ),
     314
     315                        // stdClass
     316                        array(
     317                                (object) array(
     318                                        'a' => 'Ticket 34913',
     319                                        'b' => 34913,
     320                                        'c' => false,
     321                                ),
     322                        ),
     323                );
     324        }
     325
    262326        /**
    263327         * @ticket 6966
    264328         */