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