Title: _set_cron_array
Published: April 25, 2014
Last modified: February 24, 2026

---

# _set_cron_array( array[] $cron, bool $wp_error = false ): bool|󠀁[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)󠁿

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/_set_cron_array/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/_set_cron_array/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/_set_cron_array/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/_set_cron_array/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/_set_cron_array/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/_set_cron_array/?output_format=md#wp--skip-link--target)

This function’s access is marked private. This means it is not intended for use 
by plugin or theme developers, only by core. It is listed here for completeness.

Updates the cron option with the new cron array.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/_set_cron_array/?output_format=md#parameters)󠁿

 `$cron`array[]required

Array of cron info arrays from [_get_cron_array()](https://developer.wordpress.org/reference/functions/_get_cron_array/).

`$wp_error`booloptional

Whether to return a [WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)
on failure.

Default:`false`

## 󠀁[Return](https://developer.wordpress.org/reference/functions/_set_cron_array/?output_format=md#return)󠁿

 bool|[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/) True
if cron array updated. False or [WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)
on failure.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/_set_cron_array/?output_format=md#source)󠁿

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

    	$cron['version'] = 2;

    	$result = update_option( 'cron', $cron, true );

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

    	return $result;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/cron.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/cron.php#L1259)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/cron.php#L1259-L1276)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/_set_cron_array/?output_format=md#related)󠁿

| Uses | Description | 
| [__()](https://developer.wordpress.org/reference/functions/__/)`wp-includes/l10n.php` |

Retrieves the translation of $text.

  | 
| [update_option()](https://developer.wordpress.org/reference/functions/update_option/)`wp-includes/option.php` |

Updates the value of an option that was already added.

  | 
| [WP_Error::__construct()](https://developer.wordpress.org/reference/classes/wp_error/__construct/)`wp-includes/class-wp-error.php` |

Initializes the error.

  |

[Show 1 more](https://developer.wordpress.org/reference/functions/_set_cron_array/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/_set_cron_array/?output_format=md#)

| Used by | Description | 
| [wp_unschedule_hook()](https://developer.wordpress.org/reference/functions/wp_unschedule_hook/)`wp-includes/cron.php` |

Unschedules all events attached to the hook.

  | 
| [wp_schedule_event()](https://developer.wordpress.org/reference/functions/wp_schedule_event/)`wp-includes/cron.php` |

Schedules a recurring event.

  | 
| [wp_unschedule_event()](https://developer.wordpress.org/reference/functions/wp_unschedule_event/)`wp-includes/cron.php` |

Unschedules a previously scheduled event.

  | 
| [wp_schedule_single_event()](https://developer.wordpress.org/reference/functions/wp_schedule_single_event/)`wp-includes/cron.php` |

Schedules an event to run only once.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/_set_cron_array/?output_format=md#changelog)󠁿

| Version | Description | 
| [5.7.0](https://developer.wordpress.org/reference/since/5.7.0/) | The `$wp_error` parameter was added. | 
| [5.1.0](https://developer.wordpress.org/reference/since/5.1.0/) | Return value modified to outcome of [update_option()](https://developer.wordpress.org/reference/functions/update_option/) . | 
| [2.1.0](https://developer.wordpress.org/reference/since/2.1.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2F_set_cron_array%2F)
before being able to contribute a note or feedback.