| 1 |
<?php if ( ! defined( 'ABSPATH' ) ) { |
| 2 |
die; } // Cannot access directly. |
| 3 |
/** |
| 4 |
* |
| 5 |
* Field: switcher |
| 6 |
* |
| 7 |
* @since 1.0.0 |
| 8 |
* @version 1.0.0 |
| 9 |
*/ |
| 10 |
if ( ! class_exists( 'ADMINIFY_Field_switcher' ) ) { |
| 11 |
class ADMINIFY_Field_switcher extends ADMINIFY_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 |
$active = ( ! empty( $this->value ) ) ? ' adminify--active' : ''; |
| 19 |
$text_on = ( ! empty( $this->field['text_on'] ) ) ? $this->field['text_on'] : esc_html__( 'On', 'adminify' ); |
| 20 |
$text_off = ( ! empty( $this->field['text_off'] ) ) ? $this->field['text_off'] : esc_html__( 'Off', 'adminify' ); |
| 21 |
$text_width = ( ! empty( $this->field['text_width'] ) ) ? ' style="width: ' . esc_attr( $this->field['text_width'] ) . 'px;"' : ''; |
| 22 |
|
| 23 |
echo wp_kses_post( $this->field_before() ); |
| 24 |
|
| 25 |
echo '<div class="adminify--switcher' . esc_attr( $active ) . '"' . wp_kses_post( $text_width ) . '>'; |
| 26 |
echo '<span class="adminify--on">' . wp_kses_post( $text_on ) . '</span>'; |
| 27 |
echo '<span class="adminify--off">' . wp_kses_post( $text_off ) . '</span>'; |
| 28 |
echo '<span class="adminify--ball"></span>'; |
| 29 |
echo '<input type="hidden" name="' . esc_attr( $this->field_name() ) . '" value="' . esc_attr( $this->value ) . '"' . wp_kses_post( $this->field_attributes() ) . ' />'; |
| 30 |
echo '</div>'; |
| 31 |
|
| 32 |
echo ( ! empty( $this->field['label'] ) ) ? '<span class="adminify--label">' . wp_kses_post( $this->field['label'] ) . '</span>' : ''; |
| 33 |
|
| 34 |
echo wp_kses_post( $this->field_after() ); |
| 35 |
} |
| 36 |
|
| 37 |
} |
| 38 |
} |
| 39 |
|