← All changes
|
frameworks/codestar-framework/fields/button_set/button_set.php
+67
-67
2.3.4
→
2.4.0
View file →
| @@ -1,67 +1,67 @@ | ||
| 1 | -<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly. | |
| 2 | -/** | |
| 3 | - * | |
| 4 | - * Field: button_set | |
| 5 | - * | |
| 6 | - * @since 1.0.0 | |
| 7 | - * @version 1.0.0 | |
| 8 | - * | |
| 9 | - */ | |
| 10 | -if ( ! class_exists( 'CSF_Field_button_set' ) ) { | |
| 11 | - class CSF_Field_button_set 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 | - $args = wp_parse_args( $this->field, array( | |
| 20 | - 'multiple' => false, | |
| 21 | - 'options' => array(), | |
| 22 | - 'query_args' => array(), | |
| 23 | - ) ); | |
| 24 | - | |
| 25 | - $value = ( is_array( $this->value ) ) ? $this->value : array_filter( (array) $this->value ); | |
| 26 | - | |
| 27 | - echo $this->field_before(); | |
| 28 | - | |
| 29 | - if ( isset( $this->field['options'] ) ) { | |
| 30 | - | |
| 31 | - $options = $this->field['options']; | |
| 32 | - $options = ( is_array( $options ) ) ? $options : array_filter( $this->field_data( $options, false, $args['query_args'] ) ); | |
| 33 | - | |
| 34 | - if ( is_array( $options ) && ! empty( $options ) ) { | |
| 35 | - | |
| 36 | - echo '<div class="csf-siblings csf--button-group" data-multiple="'. esc_attr( $args['multiple'] ) .'">'; | |
| 37 | - | |
| 38 | - foreach ( $options as $key => $option ) { | |
| 39 | - | |
| 40 | - $type = ( $args['multiple'] ) ? 'checkbox' : 'radio'; | |
| 41 | - $extra = ( $args['multiple'] ) ? '[]' : ''; | |
| 42 | - $active = ( in_array( $key, $value ) || ( empty( $value ) && empty( $key ) ) ) ? ' csf--active' : ''; | |
| 43 | - $checked = ( in_array( $key, $value ) || ( empty( $value ) && empty( $key ) ) ) ? ' checked' : ''; | |
| 44 | - | |
| 45 | - echo '<div class="csf--sibling csf--button'. esc_attr( $active ) .'">'; | |
| 46 | - echo '<input type="'. esc_attr( $type ) .'" name="'. esc_attr( $this->field_name( $extra ) ) .'" value="'. esc_attr( $key ) .'"'. $this->field_attributes() . esc_attr( $checked ) .'/>'; | |
| 47 | - echo $option; | |
| 48 | - echo '</div>'; | |
| 49 | - | |
| 50 | - } | |
| 51 | - | |
| 52 | - echo '</div>'; | |
| 53 | - | |
| 54 | - } else { | |
| 55 | - | |
| 56 | - echo ( ! empty( $this->field['empty_message'] ) ) ? esc_attr( $this->field['empty_message'] ) : esc_html__( 'No data available.', 'csf' ); | |
| 57 | - | |
| 58 | - } | |
| 59 | - | |
| 60 | - } | |
| 61 | - | |
| 62 | - echo $this->field_after(); | |
| 63 | - | |
| 64 | - } | |
| 65 | - | |
| 66 | - } | |
| 67 | -} | |
| 1 | +<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly. | |
| 2 | +/** | |
| 3 | + * | |
| 4 | + * Field: button_set | |
| 5 | + * | |
| 6 | + * @since 1.0.0 | |
| 7 | + * @version 1.0.0 | |
| 8 | + * | |
| 9 | + */ | |
| 10 | +if ( ! class_exists( 'CSF_Field_button_set' ) ) { | |
| 11 | + class CSF_Field_button_set 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 | + $args = wp_parse_args( $this->field, array( | |
| 20 | + 'multiple' => false, | |
| 21 | + 'options' => array(), | |
| 22 | + 'query_args' => array(), | |
| 23 | + ) ); | |
| 24 | + | |
| 25 | + $value = ( is_array( $this->value ) ) ? $this->value : array_filter( (array) $this->value ); | |
| 26 | + | |
| 27 | + echo $this->field_before(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 28 | + | |
| 29 | + if ( isset( $this->field['options'] ) ) { | |
| 30 | + | |
| 31 | + $options = $this->field['options']; | |
| 32 | + $options = ( is_array( $options ) ) ? $options : array_filter( $this->field_data( $options, false, $args['query_args'] ) ); | |
| 33 | + | |
| 34 | + if ( is_array( $options ) && ! empty( $options ) ) { | |
| 35 | + | |
| 36 | + echo '<div class="csf-siblings csf--button-group" data-multiple="'. esc_attr( $args['multiple'] ) .'">'; | |
| 37 | + | |
| 38 | + foreach ( $options as $key => $option ) { | |
| 39 | + | |
| 40 | + $type = ( $args['multiple'] ) ? 'checkbox' : 'radio'; | |
| 41 | + $extra = ( $args['multiple'] ) ? '[]' : ''; | |
| 42 | + $active = ( in_array( $key, $value ) || ( empty( $value ) && empty( $key ) ) ) ? ' csf--active' : ''; | |
| 43 | + $checked = ( in_array( $key, $value ) || ( empty( $value ) && empty( $key ) ) ) ? ' checked' : ''; | |
| 44 | + | |
| 45 | + echo '<div class="csf--sibling csf--button'. esc_attr( $active ) .'">'; | |
| 46 | + echo '<input type="'. esc_attr( $type ) .'" name="'. esc_attr( $this->field_name( $extra ) ) .'" value="'. esc_attr( $key ) .'"'. $this->field_attributes() . esc_attr( $checked ) .'/>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 47 | + echo wp_kses_post( $option ); | |
| 48 | + echo '</div>'; | |
| 49 | + | |
| 50 | + } | |
| 51 | + | |
| 52 | + echo '</div>'; | |
| 53 | + | |
| 54 | + } else { | |
| 55 | + | |
| 56 | + echo ( ! empty( $this->field['empty_message'] ) ) ? esc_attr( $this->field['empty_message'] ) : esc_html__( 'No data available.', 'streamcast' ); | |
| 57 | + | |
| 58 | + } | |
| 59 | + | |
| 60 | + } | |
| 61 | + | |
| 62 | + echo $this->field_after(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 63 | + | |
| 64 | + } | |
| 65 | + | |
| 66 | + } | |
| 67 | +} | |