From f905bc61f91f980f8a6eb337282b10eb13ca60c2 Mon Sep 17 00:00:00 2001 From: Robin Cornett Date: Thu, 11 Dec 2014 17:33:29 -0500 Subject: [PATCH] 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. --- .../class-displayfeaturedimagegenesis.php | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/includes/class-displayfeaturedimagegenesis.php b/includes/class-displayfeaturedimagegenesis.php index 76f4be5..50de2cf 100644 --- a/includes/class-displayfeaturedimagegenesis.php +++ b/includes/class-displayfeaturedimagegenesis.php @@ -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 *