number-sanitizer-trait.php
26 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace JFB_Modules\Sanitize_Value\Traits; |
| 5 | |
| 6 | use JFB_Modules\Block_Parsers\Field_Data_Parser; |
| 7 | |
| 8 | // If this file is called directly, abort. |
| 9 | if ( ! defined( 'WPINC' ) ) { |
| 10 | die; |
| 11 | } |
| 12 | |
| 13 | trait Number_Sanitizer_Trait { |
| 14 | |
| 15 | public function do_sanitize( Field_Data_Parser $parser ) { |
| 16 | if ( ! is_numeric( $parser->get_value() ) ) { |
| 17 | $parser->set_value( 0 ); |
| 18 | |
| 19 | return; |
| 20 | } |
| 21 | |
| 22 | $this->do_number_sanitize( $parser ); |
| 23 | } |
| 24 | |
| 25 | } |
| 26 |