1
0

switcher.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
  13. parent::__construct( $field, $value, $unique, $where, $parent );
  14. }
  15. public function render() {
  16. $active = ( ! empty( $this->value ) ) ? ' csf--active' : '';
  17. $text_on = ( ! empty( $this->field['text_on'] ) ) ? $this->field['text_on'] : esc_html__( 'On', 'sakurairo_csf' );
  18. $text_off = ( ! empty( $this->field['text_off'] ) ) ? $this->field['text_off'] : esc_html__( 'Off', 'sakurairo_csf' );
  19. $text_width = ( ! empty( $this->field['text_width'] ) ) ? ' style="width: '. esc_attr( $this->field['text_width'] ) .'px;"': '';
  20. echo $this->field_before();
  21. echo '<div class="csf--switcher'. esc_attr( $active ) .'"'. $text_width .'>';
  22. echo '<span class="csf--on">'. esc_attr( $text_on ) .'</span>';
  23. echo '<span class="csf--off">'. esc_attr( $text_off ) .'</span>';
  24. echo '<span class="csf--ball"></span>';
  25. echo '<input type="hidden" name="'. esc_attr( $this->field_name() ) .'" value="'. esc_attr( $this->value ) .'"'. $this->field_attributes() .' />';
  26. echo '</div>';
  27. echo ( ! empty( $this->field['label'] ) ) ? '<span class="csf--label">'. esc_attr( $this->field['label'] ) . '</span>' : '';
  28. echo $this->field_after();
  29. }
  30. }
  31. }