class-redux-validation-date.php (1388B)
1 <?php 2 /** 3 * Date validation 4 * 5 * @package Redux Framework 6 * @subpackage Validation 7 * @author Kevin Provance (kprovance) & Dovy Paukstys 8 * @version 4.0.0 9 */ 10 11 defined( 'ABSPATH' ) || exit; 12 13 if ( ! class_exists( 'Redux_Validation_Date', false ) ) { 14 15 /** 16 * Class Redux_Validation_Date 17 */ 18 class Redux_Validation_Date extends Redux_Validate { 19 20 /** 21 * Field Validation Function. 22 * Takes the vars and validates them. 23 * 24 * @since ReduxFramework 1.0.0 25 */ 26 public function validate() { 27 $this->field['msg'] = ( isset( $this->field['msg'] ) ) ? $this->field['msg'] : esc_html__( 'This field must be a valid date.', 'redux-framework' ); 28 29 $string = str_replace( '/', '', $this->value ); 30 31 if ( ! is_numeric( $string ) ) { 32 $this->value = ( isset( $this->current ) ) ? $this->current : ''; 33 $this->field['current'] = $this->value; 34 $this->error = $this->field; 35 36 return; 37 } 38 39 if ( '/' !== $this->value[2] ) { 40 $this->value = ( isset( $this->current ) ) ? $this->current : ''; 41 $this->field['current'] = $this->value; 42 $this->error = $this->field; 43 44 return; 45 } 46 47 if ( '/' !== $this->value[5] ) { 48 $this->value = ( isset( $this->current ) ) ? $this->current : ''; 49 $this->field['current'] = $this->value; 50 $this->error = $this->field; 51 } 52 } 53 } 54 }