The code below is what I created in a plugin I created that runs on both multi-site and single site installations. My plugin depends on the All in One Event Calendar and the recent upgrade locked calendar access for event creation and edits. This code may be placed in your theme’s function.php file if you are not using a custom plugin as I do.
/*******************************
* This checks if the ai1ec api settings are enabled, and
* if not calls the function to enable them. It was required
* due to Time.ly changes that turned off the options in
* an update unless an account was created.
*******************************************/
$option_name = ‘ai1ec_api_settings’;
$options_array = array(
array (
‘option_name’ => ‘enabled’,
‘option_value’ => true
),
); // option array set ai1ec api to enabled
$wp_options_array = get_option($option_name);
if (!$wp_options_array[‘enabled’]) set_or_update_wp_options($option_name,$options_array);
//Set enabled only if it isn’t already set.
/********************************/
/********************************************
* function set_or_update_wp_options($option_name,$options_array)
* This sets or updates an option stored in the
* WordPress options table. An array saved in
* this program is passed to this function an we
* iterate through the array to get desired
* options. Options are retrived from options
* table, the array is updated and then saved
* back to WP options using WP functions.
**********************************************/
function set_or_update_wp_options($option_name,$options_array) {
//Get entire array
$wp_options_array = get_option($option_name);
if (!$wp_options_array) $wp_options_array = array (
$option_name => $options_array);
foreach ( $options_array as $option_value) {
// Alter the options array with new value if it existed already
if ($wp_options_array) $wp_options_array = array_replace($wp_options_array, array (
$option_value[‘option_name’] => $option_value[‘option_value’]));
} // end foreach
//Update entire array
$status = update_option( $option_name, $wp_options_array );
return $status; // this is boolean true if update saved ok
}
// end set_or_update_wp_options($option_name,$options_array)
/************************************************/