Make WordPress Core


Ignore:
Timestamp:
08/30/2021 03:19:38 PM (3 years ago)
Author:
hellofromTonya
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/cron.php

    r51619 r51695  
    11921192 */
    11931193function _set_cron_array( $cron, $wp_error = false ) {
     1194    if ( ! is_array( $cron ) ) {
     1195        $cron = array();
     1196    }
     1197
    11941198    $cron['version'] = 2;
    11951199    $result          = update_option( 'cron', $cron );
Note: See TracChangeset for help on using the changeset viewer.