← All changes
|
Libs/adminify-framework/fields/button_set/button_set.php
+44
-47
4.2.11
→
3.2.4.1
View file →
| @@ -1,5 +1,6 @@ | ||
| 1 | -<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly. | |
| 1 | +<?php if ( ! defined( 'ABSPATH' ) ) { | |
| 2 | + die; } // Cannot access directly. | |
| 2 | 3 | /** |
| 3 | 4 | * |
| 4 | 5 | * Field: button_set |
| 5 | 6 | * |
| @@ -4,64 +5,60 @@ | ||
| 4 | 5 | * Field: button_set |
| 5 | 6 | * |
| 6 | 7 | * @since 1.0.0 |
| 7 | 8 | * @version 1.0.0 |
| 8 | - * | |
| 9 | 9 | */ |
| 10 | 10 | if ( ! class_exists( 'ADMINIFY_Field_button_set' ) ) { |
| 11 | - class ADMINIFY_Field_button_set extends ADMINIFY_Fields { | |
| 11 | + class ADMINIFY_Field_button_set extends ADMINIFY_Fields { | |
| 12 | 12 | |
| 13 | - public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) { | |
| 14 | - parent::__construct( $field, $value, $unique, $where, $parent ); | |
| 15 | - } | |
| 13 | + public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) { | |
| 14 | + parent::__construct( $field, $value, $unique, $where, $parent ); | |
| 15 | + } | |
| 16 | 16 | |
| 17 | - public function render() { | |
| 17 | + public function render() { | |
| 18 | + $args = wp_parse_args( | |
| 19 | + $this->field, | |
| 20 | + [ | |
| 21 | + 'multiple' => false, | |
| 22 | + 'options' => [], | |
| 23 | + 'query_args' => [], | |
| 24 | + ] | |
| 25 | + ); | |
| 18 | 26 | |
| 19 | - $args = wp_parse_args( $this->field, array( | |
| 20 | - 'multiple' => false, | |
| 21 | - 'options' => array(), | |
| 22 | - 'query_args' => array(), | |
| 23 | - ) ); | |
| 27 | + $value = ( is_array( $this->value ) ) ? $this->value : array_filter( (array) $this->value ); | |
| 24 | 28 | |
| 25 | - $value = ( is_array( $this->value ) ) ? $this->value : array_filter( (array) $this->value ); | |
| 29 | + echo wp_kses_post( $this->field_before() ); | |
| 26 | 30 | |
| 27 | - echo wp_kses_post( $this->field_before() ); | |
| 31 | + if ( isset( $this->field['options'] ) ) { | |
| 32 | + $options = $this->field['options']; | |
| 33 | + $options = ( is_array( $options ) ) ? $options : array_filter( $this->field_data( $options, false, $args['query_args'] ) ); | |
| 28 | 34 | |
| 29 | - if ( isset( $this->field['options'] ) ) { | |
| 35 | + if ( is_array( $options ) && ! empty( $options ) ) { | |
| 36 | + echo '<div class="adminify-siblings adminify--button-group" data-multiple="' . esc_attr( $args['multiple'] ) . '">'; | |
| 30 | 37 | |
| 31 | - $options = $this->field['options']; | |
| 32 | - $options = ( is_array( $options ) ) ? $options : array_filter( $this->field_data( $options, false, $args['query_args'] ) ); | |
| 38 | + foreach ( $options as $key => $option ) { | |
| 39 | + $type = ( $args['multiple'] ) ? 'checkbox' : 'radio'; | |
| 40 | + $extra = ( $args['multiple'] ) ? '[]' : ''; | |
| 41 | + $active = ( in_array( $key, $value ) || ( empty( $value ) && empty( $key ) ) ) ? ' adminify--active' : ''; | |
| 42 | + $checked = ( in_array( $key, $value ) || ( empty( $value ) && empty( $key ) ) ) ? ' checked' : ''; | |
| 33 | 43 | |
| 34 | - if ( is_array( $options ) && ! empty( $options ) ) { | |
| 44 | + echo '<div class="adminify--sibling adminify--button' . esc_attr( $active ) . '">'; | |
| 45 | + 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 ) . '/>'; | |
| 46 | + echo wp_kses_post( $option ); | |
| 47 | + echo '</div>'; | |
| 48 | + } | |
| 35 | 49 | |
| 36 | - echo '<div class="adminify-siblings adminify--button-group" data-multiple="'. esc_attr( $args['multiple'] ) .'">'; | |
| 50 | + echo '</div>'; | |
| 51 | + } else { | |
| 52 | + if ( ! empty( $this->field['empty_message'] ) ) { | |
| 53 | + echo esc_attr( $this->field['empty_message'] ); | |
| 54 | + } else { | |
| 55 | + echo esc_html__( 'No data available.', 'adminify' ); | |
| 56 | + } | |
| 57 | + } | |
| 58 | + } | |
| 37 | 59 | |
| 38 | - foreach ( $options as $key => $option ) { | |
| 60 | + echo wp_kses_post( $this->field_after() ); | |
| 61 | + } | |
| 39 | 62 | |
| 40 | - $type = ( $args['multiple'] ) ? 'checkbox' : 'radio'; | |
| 41 | - $extra = ( $args['multiple'] ) ? '[]' : ''; | |
| 42 | - $active = ( in_array( $key, $value ) || ( empty( $value ) && empty( $key ) ) ) ? ' adminify--active' : ''; | |
| 43 | - $checked = ( in_array( $key, $value ) || ( empty( $value ) && empty( $key ) ) ) ? ' checked' : ''; | |
| 44 | - | |
| 45 | - echo '<div class="adminify--sibling adminify--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 -- field_attributes() escapes each attribute via esc_attr() | |
| 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.', 'adminify' ); | |
| 57 | - | |
| 58 | - } | |
| 59 | - | |
| 60 | - } | |
| 61 | - | |
| 62 | - echo wp_kses_post( $this->field_after() ); | |
| 63 | - | |
| 64 | - } | |
| 65 | - | |
| 66 | - } | |
| 63 | + } | |
| 67 | 64 | } |