handle non-existent settings

This commit is contained in:
Ron Rennick 2020-11-06 14:51:45 -04:00
parent a8aefacad8
commit 0d83c6a7c2
1 changed files with 8 additions and 1 deletions

View File

@ -153,8 +153,12 @@ class WC_Beta_Tester_Import_Export {
continue;
}
$setting = maybe_unserialize( $settings[ $option_name ] );
if ( is_null( $setting ) ) {
delete_option( $option_name );
} else {
update_option( $option_name, $setting );
}
}
$this->add_message( __( 'Settings Imported', 'woocommerce-beta-tester' ), 'updated' );
} else {
$this->add_message( __( 'File did not contain well formed JSON.', 'woocommerce-beta-tester' ) );
@ -175,6 +179,9 @@ class WC_Beta_Tester_Import_Export {
if ( current_user_can( 'manage_woocommerce' ) ) {
foreach ( $this->get_setting_list() as $option_name ) {
$setting = get_option( $option_name );
if ( false === $setting ) {
$setting = null;
}
$settings[ $option_name ] = is_string( $setting ) ? $setting : serialize( $setting );
}
}