ru-se.com

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

class-kirki-field-checkbox.php (1671B)


      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_Checkbox' ) ) {
     13 
     14 	/**
     15 	 * Field overrides.
     16 	 */
     17 	class Kirki_Field_Checkbox extends Kirki_Field {
     18 
     19 		/**
     20 		 * Sets the control type.
     21 		 *
     22 		 * @access protected
     23 		 */
     24 		protected function set_type() {
     25 
     26 			$this->type = 'kirki-checkbox';
     27 			// Tweaks for backwards-compatibility:
     28 			// Prior to version 0.8 switch & toggle were part of the checkbox control.
     29 			if ( in_array( $this->mode, array( 'switch', 'toggle' ) ) ) {
     30 				$this->type = $this->mode;
     31 			}
     32 
     33 		}
     34 
     35 		/**
     36 		 * Sets the $sanitize_callback.
     37 		 *
     38 		 * @access protected
     39 		 */
     40         protected function set_sanitize_callback()
     41         {
     42 
     43 			$this->sanitize_callback = array( 'Kirki_Field_Checkbox', 'sanitize' );
     44 
     45 		}
     46 
     47 		/**
     48 		 * Sanitizes checkbox values.
     49 		 *
     50 		 * @static
     51 		 * @access public
     52 		 * @param bool|string $value The checkbox value.
     53 		 * @return bool
     54 		 */
     55         public static function sanitize($value = null)
     56         {
     57 
     58 			if ( is_null( $value ) ) {
     59                 return false;
     60 			}
     61 
     62             return (intval($value) !== 0);
     63 
     64 		}
     65 
     66 		/**
     67 		 * Sets the default value.
     68 		 *
     69 		 * @access protected
     70 		 */
     71         protected function set_default()
     72         {
     73 
     74 			if ( 1 === $this->default || '1' === $this->default || true === $this->default || 'true' === $this->default || 'on' === $this->default ) {
     75                 $this->default = true;
     76 			} else {
     77                 $this->default = false;
     78 			}
     79 		}
     80 	}
     81 }