Ticket #34913: 34913.diff
File 34913.diff, 8.4 KB (added by , 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() { 793 793 upgrade_460(); 794 794 } 795 795 796 if ( $wp_current_db_version < 43680 ) { 797 upgrade_510(); 798 } 799 796 800 maybe_disable_link_manager(); 797 801 798 802 maybe_disable_automattic_widgets(); … … function upgrade_460() { 2069 2073 } 2070 2074 } 2071 2075 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 */ 2084 function 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 2072 2093 /** 2073 2094 * Executes network-level upgrade routines. 2074 2095 * -
src/wp-includes/cron.php
diff --git src/wp-includes/cron.php src/wp-includes/cron.php index db3fc51601..bf20179f86 100644
32 32 * @return bool True if event successfully scheduled. False for failure. 33 33 */ 34 34 function 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 } 35 39 // Make sure timestamp is a positive integer 36 40 if ( ! is_numeric( $timestamp ) || $timestamp <= 0 ) { 37 41 return false; … … function wp_schedule_single_event( $timestamp, $hook, $args = array() ) { 149 153 * @return bool True if event successfully scheduled. False for failure. 150 154 */ 151 155 function 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 } 152 160 // Make sure timestamp is a positive integer 153 161 if ( ! is_numeric( $timestamp ) || $timestamp <= 0 ) { 154 162 return false; … … function wp_schedule_event( $timestamp, $recurrence, $hook, $args = array() ) { 214 222 * @return bool True if event successfully rescheduled. False for failure. 215 223 */ 216 224 function 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 } 217 229 // Make sure timestamp is a positive integer 218 230 if ( ! is_numeric( $timestamp ) || $timestamp <= 0 ) { 219 231 return false; … … function wp_unschedule_event( $timestamp, $hook, $args = array() ) { 308 320 if ( ! is_numeric( $timestamp ) || $timestamp <= 0 ) { 309 321 return false; 310 322 } 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 } 311 327 312 328 /** 313 329 * Filter to preflight or hijack unscheduling of events. … … function wp_unschedule_hook( $hook ) { 493 509 * @return bool|object The event object. False if the event does not exist. 494 510 */ 495 511 function 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 } 496 516 if ( ! $timestamp ) { 497 517 // Get the next scheduled event. 498 518 $timestamp = wp_next_scheduled( $hook, $args ); … … function wp_get_scheduled_event( $hook, $args = array(), $timestamp = null ) { 560 580 * @return false|int The Unix timestamp of the next time the event will occur. False if the event doesn't exist. 561 581 */ 562 582 function 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 } 563 587 /** 564 588 * Filter to preflight or hijack retrieving the next scheduled event timestamp. 565 589 * … … function _get_cron_array() { 872 896 return false; 873 897 } 874 898 875 if ( ! isset( $cron['version'] ) ) {899 if ( ! isset( $cron['version'] ) || $cron['version'] < 3 ) { 876 900 $cron = _upgrade_cron_array( $cron ); 877 901 } 878 902 … … function _get_cron_array() { 885 909 * Updates the CRON option with the new CRON array. 886 910 * 887 911 * @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}. 889 913 * 890 914 * @access private 891 915 * … … function _get_cron_array() { 893 917 * @return bool True if cron array updated, false on failure. 894 918 */ 895 919 function _set_cron_array( $cron ) { 896 $cron['version'] = 2;920 $cron['version'] = 3; 897 921 return update_option( 'cron', $cron ); 898 922 } 899 923 … … function _set_cron_array( $cron ) { 909 933 * @return array An upgraded Cron info array. 910 934 */ 911 935 function _upgrade_cron_array( $cron ) { 912 if ( isset( $cron['version'] ) && 2== $cron['version'] ) {936 if ( isset( $cron['version'] ) && 3 === $cron['version'] ) { 913 937 return $cron; 914 938 } 915 939 916 940 $new_cron = array(); 917 941 918 942 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; 922 947 } 923 948 } 924 949 925 $new_cron['version'] = 2;950 $new_cron['version'] = 3; 926 951 update_option( 'cron', $new_cron ); 927 952 return $new_cron; 928 953 } 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 */ 965 function _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'; 20 20 * 21 21 * @global int $wp_db_version 22 22 */ 23 $wp_db_version = 4 2836;23 $wp_db_version = 43680; 24 24 25 25 /** 26 26 * 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 { 259 259 $this->assertFalse( wp_next_scheduled( $hook ) ); 260 260 } 261 261 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 262 326 /** 263 327 * @ticket 6966 264 328 */