| 1 |
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly. |
| 2 |
/** |
| 3 |
* |
| 4 |
* Field: switcher |
| 5 |
* |
| 6 |
* @since 1.0.0 |
| 7 |
* @version 1.0.0 |
| 8 |
* |
| 9 |
*/ |
| 10 |
if ( ! class_exists( 'CSF_Field_switcher' ) ) { |
| 11 |
class CSF_Field_switcher extends CSF_Fields { |
| 12 |
|
| 13 |
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) { |
| 14 |
parent::__construct( $field, $value, $unique, $where, $parent ); |
| 15 |
} |
| 16 |
|
| 17 |
public function render() { |
| 18 |
|
| 19 |
$active = ( ! empty( $this->value ) ) ? ' csf--active' : ''; |
| 20 |
$text_on = ( ! empty( $this->field['text_on'] ) ) ? $this->field['text_on'] : esc_html__( 'On', 'csf' ); |
| 21 |
$text_off = ( ! empty( $this->field['text_off'] ) ) ? $this->field['text_off'] : esc_html__( 'Off', 'csf' ); |
| 22 |
$text_width = ( ! empty( $this->field['text_width'] ) ) ? ' style="width: '. esc_attr( $this->field['text_width'] ) .'px;"': ''; |
| 23 |
|
| 24 |
echo $this->field_before(); |
| 25 |
|
| 26 |
echo '<div class="csf--switcher'. esc_attr( $active ) .'"'. $text_width .'>'; |
| 27 |
echo '<span class="csf--on">'. esc_attr( $text_on ) .'</span>'; |
| 28 |
echo '<span class="csf--off">'. esc_attr( $text_off ) .'</span>'; |
| 29 |
echo '<span class="csf--ball"></span>'; |
| 30 |
echo '<input type="hidden" name="'. esc_attr( $this->field_name() ) .'" value="'. esc_attr( $this->value ) .'"'. $this->field_attributes() .' />'; |
| 31 |
echo '</div>'; |
| 32 |
|
| 33 |
echo ( ! empty( $this->field['label'] ) ) ? '<span class="csf--label">'. esc_attr( $this->field['label'] ) . '</span>' : ''; |
| 34 |
|
| 35 |
echo $this->field_after(); |
| 36 |
|
| 37 |
} |
| 38 |
|
| 39 |
} |
| 40 |
} |
| 41 |
|