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
 * Fix bug in remove shortcodes function.
 * Upgrade azurecurve plugin to store available plugins in options.
  • Loading branch information
azurecurve committed Apr 4, 2020
1 parent 47e3603 commit 36973ed
Show file tree
Hide file tree
Showing 3 changed files with 196 additions and 196 deletions.
57 changes: 47 additions & 10 deletions azrcrv-shortcodes-in-comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* ------------------------------------------------------------------------------
* Plugin Name: Shortcodes in Comments
* Description: Allows shortcodes to be used in comments
* Version: 1.1.2
* Version: 1.1.3
* Author: azurecurve
* Author URI: https://development.azurecurve.co.uk/classicpress-plugins/
* Plugin URI: https://development.azurecurve.co.uk/classicpress-plugins/shortcodes-in-comments/
Expand Down Expand Up @@ -88,30 +88,67 @@ function azrcrv_sic_set_default_options($networkwide){

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

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

azrcrv_sic_update_options($option_name, $new_options, false);
}

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

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


/**
* Add default options to existing options.
*
* @since 1.1.3
*
*/
function azrcrv_sic_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_sic_update_default_options($value, $updated_options[$key], true);
} else {
$updated_options[$key] = $value;
}
}
return $updated_options;
}

/**
* Add Shortcodes in Comments action link on plugins page.
*
Expand Down Expand Up @@ -411,7 +448,7 @@ function azrcrv_sic_remove_unallowed_shortcodes(){

// get site options
$options = get_option('azrcrv-sic');
if ($options['use-network'] == 1){
if (isset($options['use-network']) AND $options['use-network'] == 1){
// if using network options, get network options
$options = get_site_option('azrcrv-sic');
}
Expand Down
Loading

0 comments on commit 36973ed

Please sign in to comment.