PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 3.1.9
Adminify – White Label, Admin Menu Editor, Login Customizer v3.1.9
4.3.1 4.3.0 4.2.26 4.2.25 4.2.24 4.2.23 4.2.22 4.2.21 4.2.20 4.2.19 4.2.18 4.2.17 4.2.16 4.2.15 4.2.14 4.2.13 4.2.12 4.2.11 4.2.10 4.2.9 4.2.8 4.2.7 4.2.6 4.2.5 4.1.17 All 164 releases
← All changes | Libs/adminify-framework/fields/select/select.php +96 -105 4.2.143.1.9 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: select
5 6 *
@@ -4,129 +5,119 @@
4 5 * Field: select
5 6 *
6 7 * @since 1.0.0
7 8 * @version 1.0.0
8 - *
9 9 */
10 10 if ( ! class_exists( 'ADMINIFY_Field_select' ) ) {
11 - class ADMINIFY_Field_select extends ADMINIFY_Fields {
11 + class ADMINIFY_Field_select 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 + 'placeholder' => '',
22 + 'chosen' => false,
23 + 'multiple' => false,
24 + 'sortable' => false,
25 + 'ajax' => false,
26 + 'settings' => [],
27 + 'query_args' => [],
28 + ]
29 + );
18 30
19 - $args = wp_parse_args( $this->field, array(
20 - 'placeholder' => '',
21 - 'chosen' => false,
22 - 'multiple' => false,
23 - 'sortable' => false,
24 - 'ajax' => false,
25 - 'settings' => array(),
26 - 'query_args' => array(),
27 - ) );
31 + $this->value = ( is_array( $this->value ) ) ? $this->value : array_filter( (array) $this->value );
28 32
29 - $this->value = ( is_array( $this->value ) ) ? $this->value : array_filter( (array) $this->value );
33 + echo wp_kses_post( $this->field_before() );
30 34
31 - echo wp_kses_post( $this->field_before() );
35 + if ( isset( $this->field['options'] ) ) {
36 + if ( ! empty( $args['ajax'] ) ) {
37 + $args['settings']['data']['type'] = $args['options'];
38 + $args['settings']['data']['nonce'] = wp_create_nonce( 'adminify_chosen_ajax_nonce' );
39 + if ( ! empty( $args['query_args'] ) ) {
40 + $args['settings']['data']['query_args'] = $args['query_args'];
41 + }
42 + }
32 43
33 - if ( isset( $this->field['options'] ) ) {
44 + $chosen_rtl = ( is_rtl() ) ? ' chosen-rtl' : '';
45 + $multiple_name = ( $args['multiple'] ) ? '[]' : '';
46 + $multiple_attr = ( $args['multiple'] ) ? ' multiple="multiple"' : '';
47 + $chosen_sortable = ( $args['chosen'] && $args['sortable'] ) ? ' adminify-chosen-sortable' : '';
48 + $chosen_ajax = ( $args['chosen'] && $args['ajax'] ) ? ' adminify-chosen-ajax' : '';
49 + $placeholder_attr = ( $args['chosen'] && $args['placeholder'] ) ? ' data-placeholder="' . $args['placeholder'] . '"' : '';
50 + $field_class = ( $args['chosen'] ) ? ' class="adminify-chosen' . $chosen_rtl . $chosen_sortable . $chosen_ajax . '"' : '';
51 + $field_name = $this->field_name( $multiple_name );
52 + $field_attr = $this->field_attributes();
53 + $maybe_options = $this->field['options'];
54 + $chosen_data_attr = ( $args['chosen'] && ! empty( $args['settings'] ) ) ? ' data-chosen-settings="' . json_encode( $args['settings'] ) . '"' : '';
34 55
35 - if ( ! empty( $args['ajax'] ) ) {
36 - $args['settings']['data']['type'] = $args['options'];
37 - $args['settings']['data']['nonce'] = wp_create_nonce( 'adminify_chosen_ajax_nonce' );
38 - if ( ! empty( $args['query_args'] ) ) {
39 - $args['settings']['data']['query_args'] = $args['query_args'];
40 - }
41 - }
56 + if ( is_string( $maybe_options ) && ! empty( $args['chosen'] ) && ! empty( $args['ajax'] ) ) {
57 + $options = $this->field_wp_query_data_title( $maybe_options, $this->value );
58 + } elseif ( is_string( $maybe_options ) ) {
59 + $options = $this->field_data( $maybe_options, false, $args['query_args'] );
60 + } else {
61 + $options = $maybe_options;
62 + }
42 63
43 - $chosen_rtl = ( is_rtl() ) ? ' chosen-rtl' : '';
44 - $multiple_name = ( $args['multiple'] ) ? '[]' : '';
45 - $multiple_attr = ( $args['multiple'] ) ? ' multiple="multiple"' : '';
46 - $chosen_sortable = ( $args['chosen'] && $args['sortable'] ) ? ' adminify-chosen-sortable' : '';
47 - $chosen_ajax = ( $args['chosen'] && $args['ajax'] ) ? ' adminify-chosen-ajax' : '';
48 - $placeholder_attr = ( $args['chosen'] && $args['placeholder'] ) ? ' data-placeholder="'. esc_attr( $args['placeholder'] ) .'"' : '';
49 - $field_class = ( $args['chosen'] ) ? ' class="adminify-chosen'. esc_attr( $chosen_rtl . $chosen_sortable . $chosen_ajax ) .'"' : '';
50 - $field_name = $this->field_name( $multiple_name );
51 - $field_attr = $this->field_attributes();
52 - $maybe_options = $this->field['options'];
53 - $chosen_data_attr = ( $args['chosen'] && ! empty( $args['settings'] ) ) ? ' data-chosen-settings="'. esc_attr( wp_json_encode( $args['settings'] ) ) .'"' : '';
64 + if ( ( is_array( $options ) && ! empty( $options ) ) || ( ! empty( $args['chosen'] ) && ! empty( $args['ajax'] ) ) ) {
65 + if ( ! empty( $args['chosen'] ) && ! empty( $args['multiple'] ) ) {
66 + echo '<select name="' . esc_attr( $field_name ) . '" class="adminify-hide-select hidden"' . wp_kses_post( $multiple_attr . $field_attr ) . '>';
67 + foreach ( $this->value as $option_key ) {
68 + echo '<option value="' . esc_attr( $option_key ) . '" selected>' . wp_kses_post( $option_key ) . '</option>';
69 + }
70 + echo '</select>';
54 71
55 - if ( is_string( $maybe_options ) && ! empty( $args['chosen'] ) && ! empty( $args['ajax'] ) ) {
56 - $options = $this->field_wp_query_data_title( $maybe_options, $this->value );
57 - } else if ( is_string( $maybe_options ) ) {
58 - $options = $this->field_data( $maybe_options, false, $args['query_args'] );
59 - } else {
60 - $options = $maybe_options;
61 - }
72 + $field_name = '_pseudo';
73 + $field_attr = '';
74 + }
62 75
63 - if ( ( is_array( $options ) && ! empty( $options ) ) || ( ! empty( $args['chosen'] ) && ! empty( $args['ajax'] ) ) ) {
76 + // These attributes has been serialized above.
77 + echo '<select name="' . esc_attr( $field_name ) . '"' . wp_kses_post( $field_class . $multiple_attr . $placeholder_attr . $field_attr . $chosen_data_attr ) . '>';
64 78
65 - if ( ! empty( $args['chosen'] ) && ! empty( $args['multiple'] ) ) {
79 + if ( $args['placeholder'] && empty( $args['multiple'] ) ) {
80 + if ( ! empty( $args['chosen'] ) ) {
81 + echo '<option value=""></option>';
82 + } else {
83 + echo '<option value="">' . esc_attr( $args['placeholder'] ) . '</option>';
84 + }
85 + }
66 86
67 - echo '<select name="'. esc_attr( $field_name ) .'" class="adminify-hide-select hidden"'. $multiple_attr . $field_attr .'>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- value pre-escaped where built.
68 - foreach ( $this->value as $option_key ) {
69 - echo '<option value="'. esc_attr( $option_key ) .'" selected>'. esc_attr( $option_key ) .'</option>';
70 - }
71 - echo '</select>';
87 + foreach ( $options as $option_key => $option ) {
88 + if ( is_array( $option ) && ! empty( $option ) ) {
89 + echo '<optgroup label="' . esc_attr( $option_key ) . '">';
72 90
73 - $field_name = '_pseudo';
74 - $field_attr = '';
91 + foreach ( $option as $sub_key => $sub_value ) {
92 + $selected = ( in_array( $sub_key, $this->value ) ) ? ' selected' : '';
93 + echo '<option value="' . esc_attr( $sub_key ) . '" ' . esc_attr( $selected ) . '>' . esc_attr( $sub_value ) . '</option>';
94 + }
75 95
76 - }
96 + echo '</optgroup>';
97 + } else {
98 + $selected = ( in_array( $option_key, $this->value ) ) ? ' selected' : '';
99 + echo '<option value="' . esc_attr( $option_key ) . '" ' . esc_attr( $selected ) . '>' . esc_attr( $option ) . '</option>';
100 + }
101 + }
77 102
78 - // These attributes has been serialized above.
79 - echo '<select name="'. esc_attr( $field_name ) .'"'. $field_class . $multiple_attr . $placeholder_attr . $field_attr . $chosen_data_attr .'>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- value pre-escaped where built.
103 + echo '</select>';
104 + } else {
105 + if ( ! empty( $this->field['empty_message'] ) ) {
106 + echo esc_attr( $this->field['empty_message'] );
107 + } else {
108 + echo esc_html__( 'No data available.', 'adminify' );
109 + }
110 + }
111 + }
80 112
81 - if ( $args['placeholder'] && empty( $args['multiple'] ) ) {
82 - if ( ! empty( $args['chosen'] ) ) {
83 - echo '<option value=""></option>';
84 - } else {
85 - echo '<option value="">'. esc_attr( $args['placeholder'] ) .'</option>';
86 - }
87 - }
113 + echo wp_kses_post( $this->field_after() );
114 + }
88 115
89 - foreach ( $options as $option_key => $option ) {
116 + public function enqueue() {
117 + if ( ! wp_script_is( 'jquery-ui-sortable' ) ) {
118 + wp_enqueue_script( 'jquery-ui-sortable' );
119 + }
120 + }
90 121
91 - if ( is_array( $option ) && ! empty( $option ) ) {
92 -
93 - echo '<optgroup label="'. esc_attr( $option_key ) .'">';
94 -
95 - foreach ( $option as $sub_key => $sub_value ) {
96 - $selected = ( in_array( $sub_key, $this->value ) ) ? ' selected' : '';
97 - echo '<option value="'. esc_attr( $sub_key ) .'" '. esc_attr( $selected ) .'>'. esc_attr( $sub_value ) .'</option>';
98 - }
99 -
100 - echo '</optgroup>';
101 -
102 - } else {
103 - $selected = ( in_array( $option_key, $this->value ) ) ? ' selected' : '';
104 - echo '<option value="'. esc_attr( $option_key ) .'" '. esc_attr( $selected ) .'>'. esc_attr( $option ) .'</option>';
105 - }
106 -
107 - }
108 -
109 - echo '</select>';
110 -
111 - } else {
112 -
113 - echo ( ! empty( $this->field['empty_message'] ) ) ? esc_attr( $this->field['empty_message'] ) : esc_html__( 'No data available.', 'adminify' );
114 -
115 - }
116 -
117 - }
118 -
119 - echo wp_kses_post( $this->field_after() );
120 -
121 - }
122 -
123 - public function enqueue() {
124 -
125 - if ( ! wp_script_is( 'jquery-ui-sortable' ) ) {
126 - wp_enqueue_script( 'jquery-ui-sortable' );
127 - }
128 -
129 - }
130 -
131 - }
122 + }
132 123 }