Enforce min and max

Closes #9761
This commit is contained in:
Mike Jolley 2015-12-04 14:53:23 +00:00
parent d01f1eea3c
commit 1c364e79e4
1 changed files with 10 additions and 1 deletions

View File

@ -142,8 +142,17 @@ abstract class WC_Widget extends WP_Widget {
} }
foreach ( $this->settings as $key => $setting ) { foreach ( $this->settings as $key => $setting ) {
if ( 'number' === $setting['type'] ) {
$instance[ $key ] = sanitize_text_field( $new_instance[ $key ] );
if ( isset( $new_instance[ $key ] ) ) { if ( isset( $setting['min'] ) && '' !== $setting['min'] ) {
$instance[ $key ] = max( $instance[ $key ], $setting['min'] );
}
if ( isset( $setting['max'] ) && '' !== $setting['max'] ) {
$instance[ $key ] = min( $instance[ $key ], $setting['max'] );
}
} elseif ( isset( $new_instance[ $key ] ) ) {
$instance[ $key ] = sanitize_text_field( $new_instance[ $key ] ); $instance[ $key ] = sanitize_text_field( $new_instance[ $key ] );
} elseif ( 'checkbox' === $setting['type'] ) { } elseif ( 'checkbox' === $setting['type'] ) {
$instance[ $key ] = 0; $instance[ $key ] = 0;