Make WordPress Core

Ticket #34913: 34913-6.9.diff

File 34913-6.9.diff, 6.7 KB (added by johnjamesjacoby, 8 months ago)

Refresh for 6.9

  • src/wp-admin/includes/upgrade.php

     
    886886                upgrade_682();
    887887        }
    888888
     889        if ( $wp_current_db_version < 60445 ) {
     890                upgrade_690();
     891        }
     892
    889893        maybe_disable_link_manager();
    890894
    891895        maybe_disable_automattic_widgets();
     
    24812485}
    24822486
    24832487/**
     2488 * Executes changes made in WordPress 6.9.0.
     2489 *
     2490 * @ignore
     2491 * @since 6.9.0
     2492 *
     2493 * @global int $wp_current_db_version Current database version.
     2494 */
     2495function upgrade_690() {
     2496        global $wp_current_db_version;
     2497
     2498        // Getting the cron array will automatically update it to version 3.
     2499        if ( $wp_current_db_version < 60445 ) {
     2500                _get_cron_array();
     2501        }
     2502}
     2503
     2504/**
    24842505 * Executes network-level upgrade routines.
    24852506 *
    24862507 * @since 3.0.0
  • src/wp-includes/cron.php

     
    4949                return false;
    5050        }
    5151
     52        // Make sure args parameter is an array.
     53        if ( ! is_array( $args ) ) {
     54                _doing_it_wrong( __FUNCTION__, __( 'Cron arguments are expected to be an array. Please update your function call.' ), '6.9.0' );
     55                $args = _cron_cast_to_array_helper( $args );
     56        }
     57
    5258        $event = (object) array(
    5359                'hook'      => $hook,
    5460                'timestamp' => $timestamp,
     
    244250                return false;
    245251        }
    246252
     253        // Make sure args parameter is an array.
     254        if ( ! is_array( $args ) ) {
     255                _doing_it_wrong( __FUNCTION__, __( 'Cron arguments are expected to be an array. Please update your function call.' ), '6.9.0' );
     256                $args = _cron_cast_to_array_helper( $args );
     257        }
     258
    247259        $schedules = wp_get_schedules();
    248260
    249261        if ( ! isset( $schedules[ $recurrence ] ) ) {
     
    350362                return false;
    351363        }
    352364
     365        // Make sure args parameter is an array.
     366        if ( ! is_array( $args ) ) {
     367                _doing_it_wrong( __FUNCTION__, __( 'Cron arguments are expected to be an array. Please update your function call.' ), '6.9.0' );
     368                $args = _cron_cast_to_array_helper( $args );
     369        }
     370
    353371        $schedules = wp_get_schedules();
    354372        $interval  = 0;
    355373
     
    472490                return false;
    473491        }
    474492
     493        // Make sure args parameter is an array.
     494        if ( ! is_array( $args ) ) {
     495                _doing_it_wrong( __FUNCTION__, __( 'Cron arguments are expected to be an array. Please update your function call.' ), '6.9.0' );
     496                $args = _cron_cast_to_array_helper( $args );
     497        }
     498
    475499        /**
    476500         * Filter to override unscheduling of events.
    477501         *
     
    782806                return false;
    783807        }
    784808
     809        // Make sure args parameter is an array.
     810        if ( ! is_array( $args ) ) {
     811                _doing_it_wrong( __FUNCTION__, __( 'Cron arguments are expected to be an array. Please update your function call.' ), '6.9.0' );
     812                $args = _cron_cast_to_array_helper( $args );
     813        }
     814
    785815        $key = md5( serialize( $args ) );
    786816
    787817        if ( ! $timestamp ) {
     
    830860 * @return int|false The Unix timestamp (UTC) of the next time the event will occur. False if the event doesn't exist.
    831861 */
    832862function wp_next_scheduled( $hook, $args = array() ) {
     863        // Make sure args parameter is an array.
     864        if ( ! is_array( $args ) ) {
     865                _doing_it_wrong( __FUNCTION__, __( 'Cron arguments are expected to be an array. Please update your function call.' ), '6.9.0' );
     866                $args = _cron_cast_to_array_helper( $args );
     867        }
     868
    833869        $next_event = wp_get_scheduled_event( $hook, $args );
    834870
    835871        if ( ! $next_event ) {
     
    12311267                return array();
    12321268        }
    12331269
    1234         if ( ! isset( $cron['version'] ) ) {
     1270        if ( ! isset( $cron['version'] ) || $cron['version'] < 3 ) {
    12351271                $cron = _upgrade_cron_array( $cron );
    12361272        }
    12371273
     
    12581294                $cron = array();
    12591295        }
    12601296
    1261         $cron['version'] = 2;
     1297        $cron['version'] = 3;
    12621298
    12631299        $result = update_option( 'cron', $cron, true );
    12641300
     
    12841320 * @return array An upgraded cron info array.
    12851321 */
    12861322function _upgrade_cron_array( $cron ) {
    1287         if ( isset( $cron['version'] ) && 2 === $cron['version'] ) {
     1323        if ( isset( $cron['version'] ) && 3 === $cron['version'] ) {
    12881324                return $cron;
    12891325        }
    12901326
    12911327        $new_cron = array();
    12921328
    12931329        foreach ( (array) $cron as $timestamp => $hooks ) {
    1294                 foreach ( (array) $hooks as $hook => $args ) {
    1295                         $key = md5( serialize( $args['args'] ) );
    1296 
    1297                         $new_cron[ $timestamp ][ $hook ][ $key ] = $args;
     1330                foreach ( (array) $hooks as $hook => $event ) {
     1331                        $event['args']                           = _cron_cast_to_array_helper( $event );
     1332                        $key                                     = md5( serialize( $event['args'] ) );
     1333                        $new_cron[ $timestamp ][ $hook ][ $key ] = $event;
    12981334                }
    12991335        }
    13001336
    1301         $new_cron['version'] = 2;
     1337        $new_cron['version'] = 3;
    13021338
    13031339        update_option( 'cron', $new_cron, true );
    13041340
    13051341        return $new_cron;
    13061342}
     1343
     1344/**
     1345 * Compatibility function for consistent casting to array of cron arguments.
     1346 *
     1347 * @since 6.9.0
     1348 * @access private
     1349 *
     1350 * @param mixed $args Cron arguments.
     1351 * @return array
     1352 */
     1353function _cron_cast_to_array_helper( $args ) {
     1354        if ( is_object( $args ) ) {
     1355                return array( $args );
     1356        }
     1357        return (array) $args;
     1358}
  • src/wp-includes/version.php

     
    2323 *
    2424 * @global int $wp_db_version
    2525 */
    26 $wp_db_version = 60421;
     26$wp_db_version = 60445;
    2727
    2828/**
    2929 * Holds the TinyMCE version.
  • tests/phpunit/tests/cron.php

     
    342342        }
    343343
    344344        /**
     345         * Ensure cron events created without arguments as an array can be unscheduled.
     346         *
     347         * @ticket 34913
     348         *
     349         * @dataProvider data_clear_schedule_non_array_args
     350         *
     351         * @expectedDeprecated wp_clear_scheduled_hook
     352         * @expectedIncorrectUsage wp_schedule_single_event
     353         * @expectedIncorrectUsage wp_next_scheduled
     354         */
     355        function test_clear_schedule_non_array_args( $args ) {
     356                $hook = __FUNCTION__;
     357                $timestamp = strtotime('+1 hour' );
     358
     359                // Schedule event with non-array arguments.
     360                wp_schedule_single_event( $timestamp, $hook, $args );
     361
     362                // Make sure it's returned by wp_next_scheduled().
     363                $this->assertEquals( $timestamp, wp_next_scheduled( $hook, $args ) );
     364
     365                // Make sure it was converted to an array.
     366                $this->assertEquals( $timestamp, wp_next_scheduled( $hook, array( $args ) ) );
     367
     368                // Clear the schedule and make sure it's gone.
     369                wp_clear_scheduled_hook( $hook, $args );
     370                $this->assertFalse( wp_next_scheduled( $hook, $args ) );
     371                $this->assertFalse( wp_next_scheduled( $hook, array( $args ) ) );
     372        }
     373
     374        /**
     375         * Data provider for test_clear_schedule_non_array_args.
     376         *
     377         * @return array {
     378         *     @type array $0... {
     379         *         @type mixed $0 Cron arguments.
     380         *     }
     381         * }
     382         */
     383        function data_clear_schedule_non_array_args() {
     384                return array(
     385                        // Boolean
     386                        array( true ),
     387
     388                        // Integer
     389                        array( 34913 ),
     390
     391                        // Float
     392                        array( 34.913 ),
     393
     394                        // String
     395                        array( 'Ticket 34913' ),
     396
     397                        // stdClass
     398                        array(
     399                                (object) array(
     400                                        'a' => 'Ticket 34913',
     401                                        'b' => 34913,
     402                                        'c' => false,
     403                                ),
     404                        ),
     405                );
     406        }
     407
     408        /**
    345409         * @ticket 6966
    346410         *
    347411         * @covers ::wp_schedule_single_event