class-kirki-field-spacing.php (2090B)
1 <?php 2 /** 3 * Override field methods 4 * 5 * @package Kirki 6 * @subpackage Controls 7 * @copyright Copyright (c) 2016, Aristeides Stathopoulos 8 * @license http://opensource.org/licenses/https://opensource.org/licenses/MIT 9 * @since 2.2.7 10 */ 11 12 if ( ! class_exists( 'Kirki_Field_Spacing' ) ) { 13 14 /** 15 * Field overrides. 16 */ 17 class Kirki_Field_Spacing extends Kirki_Field_Number { 18 19 /** 20 * Sets the control type. 21 * 22 * @access protected 23 */ 24 protected function set_type() { 25 26 $this->type = 'kirki-spacing'; 27 28 } 29 30 /** 31 * Sets the $sanitize_callback. 32 * 33 * @access protected 34 */ 35 protected function set_sanitize_callback() { 36 37 // If a custom sanitize_callback has been defined, 38 // then we don't need to proceed any further. 39 if ( ! empty( $this->sanitize_callback ) ) { 40 return; 41 } 42 $this->sanitize_callback = array( $this, 'sanitize' ); 43 44 } 45 46 /** 47 * Sanitizes the value. 48 * 49 * @access public 50 * @param array $value The value. 51 * @return array 52 */ 53 public function sanitize( $value ) { 54 55 // Sanitize each sub-value separately. 56 foreach ( $value as $key => $sub_value ) { 57 $value[ $key ] = Kirki_Sanitize_Values::css_dimension( $sub_value ); 58 } 59 return $value; 60 61 } 62 63 /** 64 * Sets the $js_vars. 65 * Currentlly postMessage does not work with spacing fields 66 * so we have to force using the `refresh` mode. 67 * 68 * @access protected 69 */ 70 protected function set_js_vars() { 71 parent::set_js_vars(); 72 // $this->js_vars = array(); 73 // $this->transport = 'refresh'; 74 } 75 76 /** 77 * Set the choices. 78 * Adds a pseudo-element "controls" that helps with the JS API. 79 * 80 * @access protected 81 */ 82 protected function set_choices() { 83 84 $this->choices['controls'] = array(); 85 86 $this->choices['controls']['top'] = ( isset( $this->default['top'] ) ); 87 $this->choices['controls']['bottom'] = ( isset( $this->default['bottom'] ) ); 88 $this->choices['controls']['left'] = ( isset( $this->default['left'] ) ); 89 $this->choices['controls']['right'] = ( isset( $this->default['right'] ) ); 90 91 } 92 } 93 }