add function to check/update new setting

since feed_image is a new setting in the array, there is an error if it's not set for users
upgrading from 1.4.3. this function checks if it isn't there and if it's not, adds it.

for new users, there is no need to check.
This commit is contained in:
Robin Cornett
2014-12-11 17:33:29 -05:00
parent 58545926fc
commit f905bc61f9
@@ -31,6 +31,7 @@ class Display_Featured_Image_Genesis {
}
add_action( 'init', array( $this, 'add_plugin_supports' ) );
add_action( 'admin_init', array( $this, 'check_settings' ) );
add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) );
add_action( 'admin_menu', array( $this->settings, 'do_submenu_page' ) );
add_action( 'get_header', array( $this->output, 'manage_output' ) );
@@ -93,6 +94,40 @@ class Display_Featured_Image_Genesis {
}
}
/**
* check existing settings array to see if a setting is in the array
* @return updated setting updates to default (0)
* @since x.y.z
*/
public function check_settings() {
$displaysetting = get_option( 'displayfeaturedimagegenesis' );
//* return early if the option doesn't exist yet
if ( empty( $displaysetting ) ) {
return;
}
if ( empty( $displaysetting['feed_image'] ) ) {
$this->update_settings( array(
'feed_image' => 0
) );
}
}
/**
* Takes an array of new settings, merges them with the old settings, and pushes them into the database.
*
* @since x.y.z
*
* @param string|array $new New settings. Can be a string, or an array.
* @param string $setting Optional. Settings field name. Default is displayfeaturedimagegenesis.
*/
protected function update_settings( $new = '', $setting = 'displayfeaturedimagegenesis' ) {
return update_option( $setting, wp_parse_args( $new, get_option( $setting ) ) );
}
/**
* Set up text domain for translations
*