_set_cron_array()WP 2.1.0

Updates the cron option with the new cron array.

This is an internal function for using it by WP core itself. It's not recommended to use this function in your code.

No Hooks.

Return

true|false|WP_Error. True if cron array updated. False or WP_Error on failure.

Usage

_set_cron_array( $cron, $wp_error );
$cron(array[]) (required)
Array of cron info arrays from _get_cron_array().
$wp_error(true|false)
Whether to return a WP_Error on failure.
Default: false

Changelog

Since 2.1.0 Introduced.
Since 5.1.0 Return value modified to outcome of update_option().
Since 5.7.0 The $wp_error parameter was added.

_set_cron_array() code WP 6.1.1

function _set_cron_array( $cron, $wp_error = false ) {
	if ( ! is_array( $cron ) ) {
		$cron = array();
	}

	$cron['version'] = 2;
	$result          = update_option( 'cron', $cron );

	if ( $wp_error && ! $result ) {
		return new WP_Error(
			'could_not_set',
			__( 'The cron event list could not be saved.' )
		);
	}

	return $result;
}