| 1 |
<?php |
| 2 |
|
| 3 |
// Exit if accessed directly |
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
exit; |
| 6 |
} |
| 7 |
|
| 8 |
if ( ! class_exists( 'ReduxFrameworkLegacy_switch' ) ) { |
| 9 |
class ReduxFrameworkLegacy_switch { |
| 10 |
|
| 11 |
public $parent; |
| 12 |
public $field; |
| 13 |
public $value; |
| 14 |
|
| 15 |
/** |
| 16 |
* Field Constructor. |
| 17 |
* Required - must call the parent constructor, then assign field and value to vars, and obviously call the render field function |
| 18 |
* |
| 19 |
* @since ReduxFrameworkLegacy 0.0.4 |
| 20 |
*/ |
| 21 |
function __construct( $field = array(), $value = '', $parent = null ) { |
| 22 |
$this->parent = $parent; |
| 23 |
$this->field = $field; |
| 24 |
$this->value = $value; |
| 25 |
} |
| 26 |
|
| 27 |
/** |
| 28 |
* Field Render Function. |
| 29 |
* Takes the vars and outputs the HTML for the field in the settings |
| 30 |
* |
| 31 |
* @since ReduxFrameworkLegacy 0.0.4 |
| 32 |
*/ |
| 33 |
function render() { |
| 34 |
|
| 35 |
$cb_enabled = $cb_disabled = ''; // no errors, please |
| 36 |
// |
| 37 |
// Get selected |
| 38 |
if ( (int) $this->value == 1 ) { |
| 39 |
$cb_enabled = ' selected'; |
| 40 |
} else { |
| 41 |
$cb_disabled = ' selected'; |
| 42 |
} |
| 43 |
|
| 44 |
// Label ON |
| 45 |
$this->field['on'] = isset( $this->field['on'] ) ? $this->field['on'] : __( 'On', 'redux-framework' ); |
| 46 |
|
| 47 |
// Label OFF |
| 48 |
$this->field['off'] = isset( $this->field['off'] ) ? $this->field['off'] : __( 'Off', 'redux-framework' ); |
| 49 |
|
| 50 |
echo '<div class="switch-options">'; |
| 51 |
echo '<label class="cb-enable' . $cb_enabled . '" data-id="' . $this->field['id'] . '"><span>' . $this->field['on'] . '</span></label>'; |
| 52 |
echo '<label class="cb-disable' . $cb_disabled . '" data-id="' . $this->field['id'] . '"><span>' . $this->field['off'] . '</span></label>'; |
| 53 |
echo '<input type="hidden" class="checkbox checkbox-input ' . $this->field['class'] . '" id="' . $this->field['id'] . '" name="' . $this->field['name'] . $this->field['name_suffix'] . '" value="' . $this->value . '" />'; |
| 54 |
echo '</div>'; |
| 55 |
} //function |
| 56 |
|
| 57 |
/** |
| 58 |
* Enqueue Function. |
| 59 |
* If this field requires any scripts, or css define this function and register/enqueue the scripts/css |
| 60 |
* |
| 61 |
* @since ReduxFrameworkLegacy 0.0.4 |
| 62 |
*/ |
| 63 |
function enqueue() { |
| 64 |
wp_enqueue_script( |
| 65 |
'redux-field-switch-js', |
| 66 |
ReduxFrameworkLegacy::$_url . 'inc/fields/switch/field_switch' . ReduxLegacy_Functions::isMin() . '.js', |
| 67 |
array( 'jquery', 'redux-js' ), |
| 68 |
time(), |
| 69 |
true |
| 70 |
); |
| 71 |
|
| 72 |
if ( $this->parent->args['dev_mode'] ) { |
| 73 |
wp_enqueue_style( |
| 74 |
'redux-field-switch-css', |
| 75 |
ReduxFrameworkLegacy::$_url . 'inc/fields/switch/field_switch.css', |
| 76 |
array(), |
| 77 |
time(), |
| 78 |
'all' |
| 79 |
); |
| 80 |
} |
| 81 |
} |
| 82 |
} |
| 83 |
} |
| 84 |
|