Skip to content

Commit

Permalink
* Rewrite default option creation function to resolve several bugs.
Browse files Browse the repository at this point in the history
 * Upgrade azurecurve plugin to store available plugins in options.
  • Loading branch information
azurecurve committed Apr 4, 2020
1 parent 21672d5 commit fa42627
Show file tree
Hide file tree
Showing 3 changed files with 203 additions and 212 deletions.
81 changes: 55 additions & 26 deletions azrcrv-timelines.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* ------------------------------------------------------------------------------
* Plugin Name: Timelines
* Description: Create a multiple timelines and place on pages or posts using the timeline shortcode.
* Version: 1.1.3
* Version: 1.1.4
* Author: azurecurve
* Author URI: https://development.azurecurve.co.uk/classicpress-plugins/
* Plugin URI: https://development.azurecurve.co.uk/classicpress-plugins/timelines/
Expand Down Expand Up @@ -145,46 +145,75 @@ function azrcrv_t_set_default_options($networkwide){

foreach ($blog_ids as $blog_id){
switch_to_blog($blog_id);

if (get_option($option_name) === false){
if (get_option($old_option_name) === false){
add_option($option_name, $new_options);
}else{
add_option($option_name, get_option($old_option_name));
}
}

azrcrv_t_update_options($option_name, $new_options, false, $old_option_name);
}

switch_to_blog($original_blog_id);
}else{
if (get_option($option_name) === false){
if (get_option($old_option_name) === false){
add_option($option_name, $new_options);
}else{
add_option($option_name, get_option($old_option_name));
}
}
azrcrv_t_update_options( $option_name, $new_options, false, $old_option_name);
}
if (get_site_option($option_name) === false){
if (get_option($old_option_name) === false){
add_option($option_name, $new_options);
}else{
add_option($option_name, get_option($old_option_name));
}
azrcrv_t_update_options($option_name, $new_options, true, $old_option_name);
}
}
//set defaults for single site
else{
azrcrv_t_update_options($option_name, $new_options, false, $old_option_name);
}
}

/**
* Update options.
*
* @since 1.1.3
*
*/
function azrcrv_t_update_options($option_name, $new_options, $is_network_site, $old_option_name){
if ($is_network_site == true){
if (get_site_option($option_name) === false){
if (get_site_option($old_option_name) === false){
add_site_option($option_name, $new_options);
}else{
add_site_option($option_name, azrcrv_t_update_default_options($new_options, get_site_option($old_option_name)));
}
}else{
update_site_option($option_name, azrcrv_t_update_default_options($new_options, get_site_option($option_name)));
}
}else{
if (get_option($option_name) === false){
if (get_option($old_option_name) === false){
add_option($option_name, $new_options);
}else{
add_option($option_name, get_option($old_option_name));
}
if (get_option($old_option_name) === false){
add_option($option_name, $new_options);
}else{
add_option($option_name, azrcrv_t_update_default_options($new_options, get_option($old_option_name)));
}
}else{
update_option($option_name, azrcrv_t_update_default_options($new_options, get_option($option_name)));
}
}
}


/**
* Add default options to existing options.
*
* @since 1.1.3
*
*/
function azrcrv_t_update_default_options( &$default_options, $current_options ) {
$default_options = (array) $default_options;
$current_options = (array) $current_options;
$updated_options = $current_options;
foreach ($default_options as $key => &$value) {
if (is_array( $value) && isset( $updated_options[$key ])){
$updated_options[$key] = azrcrv_t_update_default_options($value, $updated_options[$key]);
} else {
$updated_options[$key] = $value;
}
}
return $updated_options;
}

/**
* Add Timelines action link on plugins page.
*
Expand Down
Loading

0 comments on commit fa42627

Please sign in to comment.