When saving settings, only allow values found in “options” for “select” type fields.

This commit is contained in:
Jeff Stieler 2016-06-13 16:11:51 -06:00 committed by Justin Shreve
parent a0f227a17c
commit e14d77a987
1 changed files with 9 additions and 0 deletions

View File

@ -718,6 +718,15 @@ class WC_Admin_Settings {
$value['crop'] = $option['default']['crop'];
}
break;
case 'select':
$allowed_values = empty( $option['options'] ) ? array() : array_keys( $option['options'] );
if ( empty( $option['default'] ) && empty( $allowed_values ) ) {
$value = null;
break;
}
$default = ( empty( $option['default'] ) ? $allowed_values[0] : $option['default'] );
$value = in_array( $raw_value, $allowed_values ) ? $raw_value : $default;
break;
default :
$value = wc_clean( $raw_value );
break;