wp-china-yes/framework/fields/switcher/switcher.php
2025-01-02 10:36:40 +08:00

40 lines
1.6 KiB
PHP
Executable file

<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
/**
*
* Field: switcher
*
* @since 1.0.0
* @version 1.0.0
*
*/
if ( ! class_exists( 'WP_CHINA_YES_Field_switcher' ) ) {
class WP_CHINA_YES_Field_switcher extends WP_CHINA_YES_Fields {
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
parent::__construct( $field, $value, $unique, $where, $parent );
}
public function render() {
$active = ( ! empty( $this->value ) ) ? ' wp_china_yes--active' : '';
$text_on = ( ! empty( $this->field['text_on'] ) ) ? $this->field['text_on'] : esc_html__( 'On', 'wp_china_yes' );
$text_off = ( ! empty( $this->field['text_off'] ) ) ? $this->field['text_off'] : esc_html__( 'Off', 'wp_china_yes' );
$text_width = ( ! empty( $this->field['text_width'] ) ) ? ' style="width: '. esc_attr( $this->field['text_width'] ) .'px;"': '';
echo $this->field_before();
echo '<div class="wp_china_yes--switcher'. esc_attr( $active ) .'"'. $text_width .'>';
echo '<span class="wp_china_yes--on">'. esc_attr( $text_on ) .'</span>';
echo '<span class="wp_china_yes--off">'. esc_attr( $text_off ) .'</span>';
echo '<span class="wp_china_yes--ball"></span>';
echo '<input type="hidden" name="'. esc_attr( $this->field_name() ) .'" value="'. esc_attr( $this->value ) .'"'. $this->field_attributes() .' />';
echo '</div>';
echo ( ! empty( $this->field['label'] ) ) ? '<span class="wp_china_yes--label">'. esc_attr( $this->field['label'] ) . '</span>' : '';
echo $this->field_after();
}
}
}