Skip to content

Commit

Permalink
simplify number controls sanitization.
Browse files Browse the repository at this point in the history
  • Loading branch information
aristath committed Jun 23, 2017
1 parent 16c1d05 commit cdccd55
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions field/class-kirki-field-number.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,12 @@ public function sanitize( $value = null ) {
return $max;
}

// Step divider.
// Only multiple of steps.
if ( isset( $this->choices['min'] ) && isset( $this->choices['step'] ) ) {
// Keep calculation simple to avoid memory issues.
if ( 1 > $step || $max - $min > 100 ) {
return $value;
$steps = ( $value - $min ) / $step;
if ( (int) $steps !== $steps ) {
$value = $min + ( round( $steps ) * $step );
}
$valid = range( $min, $max, $step );

$smallest = array();
foreach ( $valid as $possible_value ) {
$smallest[ $possible_value ] = abs( $possible_value - $value );
}
asort( $smallest );
$value = key( $smallest );
}

return $value;
Expand Down

0 comments on commit cdccd55

Please sign in to comment.