Code Modernization: Add input validation to `_set_cron_array()`.

The private `_set_cron_array()` function expects a cron array as the first parameter, but will often be passed the - potentially updated - output of a call to `_get_cron_array()`.

When the `_get_cron_array()` function returns `false`, a "Deprecated: Automatic conversion of false to array is deprecated" warning will be thrown on PHP 8.1.

The input validation resolves the deprecation warning by setting the cron value to an empty array when not given an `array` data type.

Adds a full set of `_set_cron_array()` tests.

Follow-up to [4189], [50152].

Props jrf, hellofromTonya, peterwilsoncc.
See #53635.
Built from https://develop.svn.wordpress.org/trunk@51695


git-svn-id: http://core.svn.wordpress.org/trunk@51301 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
hellofromTonya 2021-08-30 15:20:56 +00:00
parent 5090761b4f
commit 6b2eccb0e3
2 changed files with 5 additions and 1 deletions

View File

@ -1191,6 +1191,10 @@ function _get_cron_array() {
* @return bool|WP_Error True if cron array updated. False or WP_Error on failure. * @return bool|WP_Error True if cron array updated. False or WP_Error on failure.
*/ */
function _set_cron_array( $cron, $wp_error = false ) { function _set_cron_array( $cron, $wp_error = false ) {
if ( ! is_array( $cron ) ) {
$cron = array();
}
$cron['version'] = 2; $cron['version'] = 2;
$result = update_option( 'cron', $cron ); $result = update_option( 'cron', $cron );

View File

@ -13,7 +13,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '5.9-alpha-51693'; $wp_version = '5.9-alpha-51695';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.