PluginProbe
Cool Timeline (Horizontal & Vertical Timeline) / trunk
Cool Timeline (Horizontal & Vertical Timeline) vtrunk
3.4.0 3.3.6 3.3.5 3.3.4 3.3.3 3.3.2 2.2.3 2.3.3 2.4 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.6.1 2.7.1 2.8.3 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 2.9.8 2.9.9 3.0.0 All 79 releases
cool-timeline / admin / codestar-framework / fields / select / select.php

select.php in Cool Timeline (Horizontal & Vertical Timeline) trunk, at admin/codestar-framework/fields/select/select.php

135 lines 5.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
2 // phpcs:ignoreFile WordPress.Security.EscapeOutput.OutputNotEscaped
3 /**
4 *
5 * Field: select
6 *
7 * @since 1.0.0
8 * @version 1.0.0
9 *
10 */
11 if ( ! class_exists( 'CSF_Field_select' ) ) {
12 class CSF_Field_select extends CSF_Fields {
13
14 public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
15 parent::__construct( $field, $value, $unique, $where, $parent );
16 }
17
18 public function render() {
19
20 $args = wp_parse_args( $this->field, array(
21 'placeholder' => '',
22 'chosen' => false,
23 'multiple' => false,
24 'sortable' => false,
25 'ajax' => false,
26 'settings' => array(),
27 'query_args' => array(),
28 ) );
29
30 $this->value = ( is_array( $this->value ) ) ? $this->value : array_filter( (array) $this->value );
31
32 echo $this->field_before();
33
34 if ( isset( $this->field['options'] ) ) {
35
36 if ( ! empty( $args['ajax'] ) ) {
37 $args['settings']['data']['type'] = $args['options'];
38 $args['settings']['data']['nonce'] = wp_create_nonce( 'csf_chosen_ajax_nonce' );
39 if ( ! empty( $args['query_args'] ) ) {
40 $args['settings']['data']['query_args'] = $args['query_args'];
41 }
42 }
43
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'] ) ? ' csf-chosen-sortable' : '';
48 $chosen_ajax = ( $args['chosen'] && $args['ajax'] ) ? ' csf-chosen-ajax' : '';
49 $placeholder_attr = ( $args['chosen'] && $args['placeholder'] ) ? ' data-placeholder="'. esc_attr( $args['placeholder'] ) .'"' : '';
50 $field_class = ( $args['chosen'] ) ? ' class="csf-chosen'. esc_attr( $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="'. esc_attr( json_encode( $args['settings'] ) ) .'"' : '';
55
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 } else if ( is_string( $maybe_options ) ) {
59 $options = $this->field_data( $maybe_options, false, $args['query_args'] );
60 } else {
61 $options = $maybe_options;
62 }
63
64 if ( ( is_array( $options ) && ! empty( $options ) ) || ( ! empty( $args['chosen'] ) && ! empty( $args['ajax'] ) ) ) {
65
66 if ( ! empty( $args['chosen'] ) && ! empty( $args['multiple'] ) ) {
67
68 echo '<select name="'. $field_name .'" class="csf-hide-select hidden"'. $multiple_attr . $field_attr .'>';
69 foreach ( $this->value as $option_key ) {
70 echo '<option value="'. esc_attr( $option_key ) .'" selected>'. esc_attr( $option_key ) .'</option>';
71 }
72 echo '</select>';
73
74 $field_name = '_pseudo';
75 $field_attr = '';
76
77 }
78
79 // These attributes has been serialized above.
80 echo '<select name="'. esc_attr( $field_name ) .'"'. $field_class . $multiple_attr . $placeholder_attr . $field_attr . $chosen_data_attr .'>';
81
82 if ( $args['placeholder'] && empty( $args['multiple'] ) ) {
83 if ( ! empty( $args['chosen'] ) ) {
84 echo '<option value=""></option>';
85 } else {
86 echo '<option value="">'. esc_attr( $args['placeholder'] ) .'</option>';
87 }
88 }
89
90 foreach ( $options as $option_key => $option ) {
91
92 if ( is_array( $option ) && ! empty( $option ) ) {
93
94 echo '<optgroup label="'. esc_attr( $option_key ) .'">';
95
96 foreach ( $option as $sub_key => $sub_value ) {
97 $selected = ( in_array( $sub_key, $this->value ) ) ? ' selected' : '';
98 echo '<option value="'. esc_attr( $sub_key ) .'" '. esc_attr( $selected ) .'>'. esc_attr( $sub_value ) .'</option>';
99 }
100
101 echo '</optgroup>';
102
103 } else {
104 $selected = ( in_array( $option_key, $this->value ) ) ? ' selected' : '';
105 echo '<option value="'. esc_attr( $option_key ) .'" '. esc_attr( $selected ) .'>'. esc_attr( $option ) .'</option>';
106 }
107
108 }
109
110 echo '</select>';
111
112 } else {
113
114 // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
115 echo ( ! empty( $this->field['empty_message'] ) ) ? esc_attr( $this->field['empty_message'] ) : esc_html__( 'No data available.', 'csf' );
116
117 }
118
119 }
120
121 echo $this->field_after();
122
123 }
124
125 public function enqueue() {
126
127 if ( ! wp_script_is( 'jquery-ui-sortable' ) ) {
128 wp_enqueue_script( 'jquery-ui-sortable' );
129 }
130
131 }
132
133 }
134 }
135