Allow us to define a setting in API but not save as option

This commit is contained in:
Mike Jolley 2019-03-20 15:26:38 +00:00
parent 18266a6eb8
commit b387444136
1 changed files with 18 additions and 11 deletions

View File

@ -156,6 +156,10 @@ if ( ! class_exists( 'WC_Admin_Settings', false ) ) :
* @return mixed
*/
public static function get_option( $option_name, $default = '' ) {
if ( ! $option_name ) {
return $default;
}
// Array value.
if ( strstr( $option_name, '[' ) ) {
@ -227,6 +231,9 @@ if ( ! class_exists( 'WC_Admin_Settings', false ) ) :
if ( ! isset( $value['suffix'] ) ) {
$value['suffix'] = '';
}
if ( ! isset( $value['value'] ) ) {
$value['value'] = self::get_option( $value['id'], $value['default'] );
}
// Custom attribute handling.
$custom_attributes = array();
@ -285,7 +292,7 @@ if ( ! class_exists( 'WC_Admin_Settings', false ) ) :
case 'email':
case 'url':
case 'tel':
$option_value = self::get_option( $value['id'], $value['default'] );
$option_value = $value['value'];
?><tr valign="top">
<th scope="row" class="titledesc">
@ -309,7 +316,7 @@ if ( ! class_exists( 'WC_Admin_Settings', false ) ) :
// Color picker.
case 'color':
$option_value = self::get_option( $value['id'], $value['default'] );
$option_value = $value['value'];
?>
<tr valign="top">
@ -337,7 +344,7 @@ if ( ! class_exists( 'WC_Admin_Settings', false ) ) :
// Textarea.
case 'textarea':
$option_value = self::get_option( $value['id'], $value['default'] );
$option_value = $value['value'];
?>
<tr valign="top">
@ -363,7 +370,7 @@ if ( ! class_exists( 'WC_Admin_Settings', false ) ) :
// Select boxes.
case 'select':
case 'multiselect':
$option_value = self::get_option( $value['id'], $value['default'] );
$option_value = $value['value'];
?>
<tr valign="top">
@ -404,7 +411,7 @@ if ( ! class_exists( 'WC_Admin_Settings', false ) ) :
// Radio inputs.
case 'radio':
$option_value = self::get_option( $value['id'], $value['default'] );
$option_value = $value['value'];
?>
<tr valign="top">
@ -441,7 +448,7 @@ if ( ! class_exists( 'WC_Admin_Settings', false ) ) :
// Checkbox input.
case 'checkbox':
$option_value = self::get_option( $value['id'], $value['default'] );
$option_value = $value['value'];
$visibility_class = array();
if ( ! isset( $value['hide_if_checked'] ) ) {
@ -547,7 +554,7 @@ if ( ! class_exists( 'WC_Admin_Settings', false ) ) :
'show_option_none' => ' ',
'class' => $value['class'],
'echo' => false,
'selected' => absint( self::get_option( $value['id'], $value['default'] ) ),
'selected' => absint( $value['value'] ),
'post_status' => 'publish,private,draft',
);
@ -569,7 +576,7 @@ if ( ! class_exists( 'WC_Admin_Settings', false ) ) :
// Single country selects.
case 'single_select_country':
$country_setting = (string) self::get_option( $value['id'], $value['default'] );
$country_setting = (string) $value['value'];
if ( strstr( $country_setting, ':' ) ) {
$country_setting = explode( ':', $country_setting );
@ -594,7 +601,7 @@ if ( ! class_exists( 'WC_Admin_Settings', false ) ) :
// Country multiselects.
case 'multi_select_countries':
$selections = (array) self::get_option( $value['id'], $value['default'] );
$selections = (array) $value['value'];
if ( ! empty( $value['options'] ) ) {
$countries = $value['options'];
@ -631,7 +638,7 @@ if ( ! class_exists( 'WC_Admin_Settings', false ) ) :
'months' => __( 'Month(s)', 'woocommerce' ),
'years' => __( 'Year(s)', 'woocommerce' ),
);
$option_value = wc_parse_relative_date_option( self::get_option( $value['id'], $value['default'] ) );
$option_value = wc_parse_relative_date_option( $value['value'] );
?>
<tr valign="top">
<th scope="row" class="titledesc">
@ -734,7 +741,7 @@ if ( ! class_exists( 'WC_Admin_Settings', false ) ) :
// Loop options and get values to save.
foreach ( $options as $option ) {
if ( ! isset( $option['id'] ) || ! isset( $option['type'] ) ) {
if ( ! isset( $option['id'] ) || ! isset( $option['type'] ) || ( isset( $option['is_option'] ) && false === $option['is_option'] ) ) {
continue;
}