balmet.com

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

class-redux-switch.php (2262B)


      1 <?php
      2 /**
      3  * Switch Field
      4  *
      5  * @package     Redux Framework
      6  * @author      Dovy Paukstys & Kevin Provance (kprovance)
      7  * @version     4.0.0
      8  */
      9 
     10 defined( 'ABSPATH' ) || exit;
     11 
     12 if ( ! class_exists( 'Redux_Switch', false ) ) {
     13 
     14 	/**
     15 	 * Class Redux_Switch
     16 	 */
     17 	class Redux_Switch extends Redux_Field {
     18 
     19 		/**
     20 		 * Field Render Function.
     21 		 * Takes the vars and outputs the HTML for the field in the settings
     22 		 *
     23 		 * @since ReduxFramework 0.0.4
     24 		 */
     25 		public function render() {
     26 			$cb_enabled  = '';
     27 			$cb_disabled = '';
     28 
     29 			// Get selected.
     30 			if ( 1 === (int) $this->value ) {
     31 				$cb_enabled = ' selected';
     32 			} else {
     33 				$cb_disabled = ' selected';
     34 			}
     35 
     36 			// Label ON.
     37 			$this->field['on'] = $this->field['on'] ?? esc_html__( 'On', 'redux-framework' );
     38 
     39 			// Label OFF.
     40 			$this->field['off'] = $this->field['off'] ?? esc_html__( 'Off', 'redux-framework' );
     41 
     42 			echo '<div class="switch-options">';
     43 			echo '<label class="cb-enable' . esc_attr( $cb_enabled ) . '" data-id="' . esc_attr( $this->field['id'] ) . '"><span>' . esc_html( $this->field['on'] ) . '</span></label>';
     44 			echo '<label class="cb-disable' . esc_attr( $cb_disabled ) . '" data-id="' . esc_attr( $this->field['id'] ) . '"><span>' . esc_html( $this->field['off'] ) . '</span></label>';
     45 			echo '<input type="hidden" class="checkbox checkbox-input ' . esc_attr( $this->field['class'] ) . '" id="' . esc_attr( $this->field['id'] ) . '" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '" value="' . esc_attr( $this->value ) . '" />';
     46 			echo '</div>';
     47 		}
     48 
     49 		/**
     50 		 * Enqueue Function.
     51 		 * If this field requires any scripts, or css define this function and register/enqueue the scripts/css
     52 		 *
     53 		 * @since ReduxFramework 0.0.4
     54 		 */
     55 		public function enqueue() {
     56 			wp_enqueue_script(
     57 				'redux-field-switch-js',
     58 				Redux_Core::$url . 'inc/fields/switch/redux-switch' . Redux_Functions::is_min() . '.js',
     59 				array( 'jquery', 'redux-js' ),
     60 				$this->timestamp,
     61 				true
     62 			);
     63 
     64 			if ( $this->parent->args['dev_mode'] ) {
     65 				wp_enqueue_style(
     66 					'redux-field-switch-css',
     67 					Redux_Core::$url . 'inc/fields/switch/redux-switch.css',
     68 					array(),
     69 					$this->timestamp
     70 				);
     71 			}
     72 		}
     73 	}
     74 }
     75 
     76 class_alias( 'Redux_Switch', 'ReduxFramework_Switch' );