PluginProbe
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News / 2.4.2
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News v2.4.2
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 4.0.2 4.0.1 2.3.5 2.3.6 2.4.0 2.4.1 2.4.10 2.4.11 2.4.12 2.4.13 2.4.14 2.4.15 2.4.16 2.4.17 2.4.18 2.4.19 2.4.2 2.4.20 2.4.21 All 88 releases
post-carousel / admin / views / sp-framework / fields / select / select.php

select.php in Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News 2.4.2, at admin/views/sp-framework/fields/select/select.php

129 lines 5.2 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( 'SP_PC_Field_select' ) ) {
11 class SP_PC_Field_select extends SP_PC_Fields {
12
13 /**
14 * The select field constructor.
15 *
16 * @param string $field The field type.
17 * @param string $value The field value.
18 * @param string $unique The unique ID.
19 * @param string $where The place to show the field.
20 * @param string $parent If it has any parent.
21 */
22 public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
23 parent::__construct( $field, $value, $unique, $where, $parent );
24 }
25
26 /**
27 * The render function.
28 *
29 * @return void
30 */
31 public function render() {
32
33 $args = wp_parse_args(
34 $this->field,
35 array(
36 'placeholder' => '',
37 'chosen' => false,
38 'multiple' => false,
39 'sortable' => false,
40 'ajax' => false,
41 'settings' => array(),
42 'query_args' => array(),
43 )
44 );
45
46 $this->value = ( is_array( $this->value ) ) ? $this->value : array_filter( (array) $this->value );
47
48 echo wp_kses_post( $this->field_before() );
49
50 if ( isset( $this->field['options'] ) ) {
51
52 if ( ! empty( $args['ajax'] ) ) {
53 $args['settings']['data']['type'] = $args['options'];
54 $args['settings']['data']['nonce'] = wp_create_nonce( 'spf_chosen_ajax_nonce' );
55 if ( ! empty( $args['query_args'] ) ) {
56 $args['settings']['data']['query_args'] = $args['query_args'];
57 }
58 }
59 $chosen_rtl = ( is_rtl() ) ? ' chosen-rtl' : '';
60 $multiple_name = ( $args['multiple'] ) ? '[]' : '';
61 $multiple_attr = ( $args['multiple'] ) ? ' multiple="multiple"' : '';
62 $chosen_sortable = ( $args['chosen'] && $args['sortable'] ) ? ' spf-chosen-sortable' : '';
63 $chosen_attr = ( $args['chosen'] ) ? ' class="spf-chosen' . $chosen_rtl . '"' : '';
64 $chosen_ajax = ( $args['chosen'] && $args['ajax'] ) ? ' spf-chosen-ajax' : '';
65 $placeholder_attr = ( $args['chosen'] && $args['placeholder'] ) ? ' data-placeholder="' . $args['placeholder'] . '"' : '';
66 $field_class = ( $args['chosen'] ) ? ' class="spf-chosen' . $chosen_rtl . $chosen_sortable . $chosen_ajax . '"' : '';
67 $field_name = $this->field_name( $multiple_name );
68 $field_attr = $this->field_attributes();
69 $maybe_options = $this->field['options'];
70 $field_unique = $this->unique;
71 $chosen_data_attr = ( $args['chosen'] && ! empty( $args['settings'] ) ) ? ' data-chosen-settings="' . esc_attr( json_encode( $args['settings'] ) ) . '"' : '';
72 if ( is_string( $maybe_options ) && ! empty( $args['chosen'] ) && ! empty( $args['ajax'] ) ) {
73 $options = $this->field_wp_query_data_title( $maybe_options, $this->value );
74 } elseif ( is_string( $maybe_options ) ) {
75 $options = $this->field_data( $maybe_options, false, $args['query_args'], $field_unique );
76 } else {
77 $options = $maybe_options;
78 }
79 if ( ( is_array( $options ) && ! empty( $options ) ) || ( ! empty( $args['chosen'] ) && ! empty( $args['ajax'] ) ) ) {
80 if ( ! empty( $args['chosen'] ) && ! empty( $args['multiple'] ) ) {
81 echo '<select name="' . esc_attr( $field_name ) . '" class="spf-hidden-select spf-hidden"' . wp_kses_post( $multiple_attr . $field_attr ) . '>';
82 foreach ( $this->value as $option_key ) {
83 echo '<option value="' . esc_attr( $option_key ) . '" selected>' . esc_html( $option_key ) . '</option>';
84 }
85 echo '</select>';
86 $field_name = '_pseudo';
87 $field_attr = '';
88 }
89 echo '<select name="' . esc_attr( $field_name ) . '"' . wp_kses_post( $field_class . $multiple_attr . $placeholder_attr . $field_attr . $chosen_data_attr ) . '>';
90 if ( $args['placeholder'] && empty( $args['multiple'] ) ) {
91 if ( ! empty( $args['chosen'] ) ) {
92 echo '<option value=""></option>';
93 } else {
94 echo '<option value="">' . esc_html( $args['placeholder'] ) . '</option>';
95 }
96 }
97 foreach ( $options as $option_key => $option ) {
98 if ( is_array( $option ) && ! empty( $option ) ) {
99 echo '<optgroup label="' . esc_attr( $option_key ) . '">';
100 foreach ( $option as $sub_key => $sub_value ) {
101 $selected = ( in_array( $sub_key, $this->value ) ) ? ' selected' : '';
102 echo '<option value="' . esc_attr( $sub_key ) . '" ' . esc_attr( $selected ) . '>' . wp_kses_post( $sub_value ) . '</option>';
103 }
104 echo '</optgroup>';
105 } else {
106 $selected = ( in_array( $option_key, $this->value ) ) ? ' selected' : '';
107 echo '<option value="' . esc_attr( $option_key ) . '" ' . esc_attr( $selected ) . '>' . wp_kses_post( $option ) . '</option>';
108 }
109 }
110 echo '</select>';
111 } else {
112 echo ( esc_html( ! empty( $this->field['empty_message'] ) ) ) ? esc_html( $this->field['empty_message'] ) : esc_html__( 'No data provided for this option type.', 'smart-post-show' );
113 }
114 }
115 echo wp_kses_post( $this->field_after() );
116 }
117 /**
118 * Enqueue UI Sortable.
119 *
120 * @return void
121 */
122 public function enqueue() {
123 if ( ! wp_script_is( 'jquery-ui-sortable' ) ) {
124 wp_enqueue_script( 'jquery-ui-sortable' );
125 }
126 }
127 }
128 }
129