PluginProbe
Darkify – Dark Mode & Night Mode for Website & Admin (Dark Theme Included) / 1.4.6
Darkify – Dark Mode & Night Mode for Website & Admin (Dark Theme Included) v1.4.6
2.1.3 2.1.2 2.1.1 2.1.0 2.0.4 2.0.3 2.0.2 2.0.1 2.0.0 1.5.5 1.5.4 1.5.3 1.5.2 1.5.1 1.5.0 trunk 1.0.1 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 All 57 releases
darkify / src / Admin / Framework / fields / select / select.php

select.php in Darkify – Dark Mode & Night Mode for Website & Admin (Dark Theme Included) 1.4.6, at src/Admin/Framework/fields/select/select.php

131 lines 4.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php if ( ! defined( 'ABSPATH' ) ) {
2 die; } // Cannot access directly.
3 /**
4 *
5 * Field: select
6 *
7 * @since 1.0.0
8 * @version 1.0.0
9 */
10 if ( ! class_exists( 'DarkifyField_select' ) ) {
11 class DarkifyField_select extends DarkifyFields {
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 'placeholder' => '',
23 'chosen' => false,
24 'multiple' => false,
25 'sortable' => false,
26 'ajax' => false,
27 'settings' => array(),
28 'query_args' => array(),
29 )
30 );
31
32 $this->value = ( is_array( $this->value ) ) ? $this->value : array_filter( (array) $this->value );
33
34 echo wp_kses_post( $this->field_before() );
35
36 if ( isset( $this->field['options'] ) ) {
37
38 if ( ! empty( $args['ajax'] ) ) {
39 $args['settings']['data']['type'] = $args['options'];
40 $args['settings']['data']['nonce'] = wp_create_nonce( 'darkify_chosen_ajax_nonce' );
41 if ( ! empty( $args['query_args'] ) ) {
42 $args['settings']['data']['query_args'] = $args['query_args'];
43 }
44 }
45
46 $chosen_rtl = ( is_rtl() ) ? ' chosen-rtl' : '';
47 $multiple_name = ( $args['multiple'] ) ? '[]' : '';
48 $multiple_attr = ( $args['multiple'] ) ? ' multiple="multiple"' : '';
49 $chosen_sortable = ( $args['chosen'] && $args['sortable'] ) ? ' darkify-chosen-sortable' : '';
50 $chosen_ajax = ( $args['chosen'] && $args['ajax'] ) ? ' darkify-chosen-ajax' : '';
51 $placeholder_attr = ( $args['chosen'] && $args['placeholder'] ) ? ' data-placeholder="' . esc_attr( $args['placeholder'] ) . '"' : '';
52 $field_class = ( $args['chosen'] ) ? ' class="darkify-chosen' . esc_attr( $chosen_rtl . $chosen_sortable . $chosen_ajax ) . '"' : '';
53 $field_name = $this->field_name( $multiple_name );
54 $field_attr = $this->field_attributes();
55 $maybe_options = $this->field['options'];
56 $chosen_data_attr = ( $args['chosen'] && ! empty( $args['settings'] ) ) ? ' data-chosen-settings="' . esc_attr( wp_json_encode( $args['settings'] ) ) . '"' : '';
57
58 if ( is_string( $maybe_options ) && ! empty( $args['chosen'] ) && ! empty( $args['ajax'] ) ) {
59 $options = $this->field_wp_query_data_title( $maybe_options, $this->value );
60 } elseif ( is_string( $maybe_options ) ) {
61 $options = $this->field_data( $maybe_options, false, $args['query_args'] );
62 } else {
63 $options = $maybe_options;
64 }
65
66 if ( ( is_array( $options ) && ! empty( $options ) ) || ( ! empty( $args['chosen'] ) && ! empty( $args['ajax'] ) ) ) {
67
68 if ( ! empty( $args['chosen'] ) && ! empty( $args['multiple'] ) ) {
69
70 echo '<select name="' . esc_attr($field_name) . '" class="darkify-hide-select hidden"' . wp_kses_post($multiple_attr . $field_attr) . '>';
71 foreach ( $this->value as $option_key ) {
72 echo '<option value="' . esc_attr( $option_key ) . '" selected>' . esc_attr( $option_key ) . '</option>';
73 }
74 echo '</select>';
75
76 $field_name = '_pseudo';
77 $field_attr = '';
78
79 }
80
81 // These attributes has been serialized above.
82 echo '<select name="' . esc_attr( $field_name ) . '"' . wp_kses_post($field_class . $multiple_attr . $placeholder_attr . $field_attr . $chosen_data_attr) . '>';
83
84 if ( $args['placeholder'] && empty( $args['multiple'] ) ) {
85 if ( ! empty( $args['chosen'] ) ) {
86 echo '<option value=""></option>';
87 } else {
88 echo '<option value="">' . esc_attr( $args['placeholder'] ) . '</option>';
89 }
90 }
91
92 foreach ( $options as $option_key => $option ) {
93
94 if ( is_array( $option ) && ! empty( $option ) ) {
95
96 echo '<optgroup label="' . esc_attr( $option_key ) . '">';
97
98 foreach ( $option as $sub_key => $sub_value ) {
99 $selected = ( in_array( $sub_key, $this->value ) ) ? ' selected' : '';
100 echo '<option value="' . esc_attr( $sub_key ) . '" ' . esc_attr( $selected ) . '>' . esc_attr( $sub_value ) . '</option>';
101 }
102
103 echo '</optgroup>';
104
105 } else {
106 $selected = ( in_array( $option_key, $this->value ) ) ? ' selected' : '';
107 echo '<option value="' . esc_attr( $option_key ) . '" ' . esc_attr( $selected ) . '>' . esc_attr( $option ) . '</option>';
108 }
109 }
110
111 echo '</select>';
112
113 } else {
114
115 echo ( ! empty( $this->field['empty_message'] ) ) ? esc_attr( $this->field['empty_message'] ) : esc_html__( 'No data available.', 'darkify' );
116
117 }
118 }
119
120 echo wp_kses_post( $this->field_after() );
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