PluginProbe
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News / 2.4.10
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News v2.4.10
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.10, at admin/views/sp-framework/fields/select/select.php

139 lines 5.4 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 $multiple_type = isset( $this->field['multiple_type'] ) ? $this->field['multiple_type'] : false;
53
54 if ( ! empty( $args['ajax'] ) ) {
55 $args['settings']['data']['type'] = $args['options'];
56 $args['settings']['data']['nonce'] = wp_create_nonce( 'spf_chosen_ajax_nonce' );
57 if ( ! empty( $args['query_args'] ) ) {
58 $args['settings']['data']['query_args'] = $args['query_args'];
59 }
60 }
61 $chosen_rtl = ( is_rtl() ) ? ' chosen-rtl' : '';
62 $multiple_name = ( $args['multiple'] ) ? '[]' : '';
63 $multiple_attr = ( $args['multiple'] ) ? ' multiple="multiple"' : '';
64 $chosen_sortable = ( $args['chosen'] && $args['sortable'] ) ? ' spf-chosen-sortable' : '';
65 $chosen_attr = ( $args['chosen'] ) ? ' class="spf-chosen' . $chosen_rtl . '"' : '';
66 $chosen_ajax = ( $args['chosen'] && $args['ajax'] ) ? ' spf-chosen-ajax' : '';
67 $placeholder_attr = ( $args['chosen'] && $args['placeholder'] ) ? ' data-placeholder="' . $args['placeholder'] . '"' : '';
68 $field_class = ( $args['chosen'] ) ? ' class="spf-chosen' . $chosen_rtl . $chosen_sortable . $chosen_ajax . '"' : '';
69 $field_name = $this->field_name( $multiple_name );
70 $field_attr = $this->field_attributes();
71 $maybe_options = $this->field['options'];
72 $field_unique = $this->unique;
73 $chosen_data_attr = ( $args['chosen'] && ! empty( $args['settings'] ) ) ? ' data-chosen-settings="' . esc_attr( json_encode( $args['settings'] ) ) . '"' : '';
74 if ( is_string( $maybe_options ) && ! empty( $args['chosen'] ) && ! empty( $args['ajax'] ) ) {
75 $options = $this->field_wp_query_data_title( $maybe_options, $this->value );
76 } elseif ( is_string( $maybe_options ) ) {
77 $options = $this->field_data( $maybe_options, false, $args['query_args'], $field_unique );
78 } else {
79 $options = $maybe_options;
80 }
81 if ( ( is_array( $options ) && ! empty( $options ) ) || ( ! empty( $args['chosen'] ) && ! empty( $args['ajax'] ) ) ) {
82 if ( ! empty( $args['chosen'] ) && ! empty( $args['multiple'] ) ) {
83 echo '<select name="' . esc_attr( $field_name ) . '" class="spf-hidden-select spf-hidden"' . wp_kses_post( $multiple_attr . $field_attr ) . '>';
84 foreach ( $this->value as $option_key ) {
85 echo '<option value="' . esc_attr( $option_key ) . '" selected>' . esc_html( $option_key ) . '</option>';
86 }
87 echo '</select>';
88 $field_name = '_pseudo';
89 $field_attr = '';
90 }
91 echo '<select name="' . esc_attr( $field_name ) . '"' . wp_kses_post( $field_class . $multiple_attr . $placeholder_attr . $field_attr . $chosen_data_attr ) . '>';
92 if ( $args['placeholder'] && empty( $args['multiple'] ) ) {
93 if ( ! empty( $args['chosen'] ) ) {
94 echo '<option value=""></option>';
95 } else {
96 echo '<option value="">' . esc_html( $args['placeholder'] ) . '</option>';
97 }
98 }
99 if ( $multiple_type ) {
100 $options = array_merge(
101 $options,
102 array(
103 'multiple_post_type' => __( 'Multiple Post Types (Pro)', 'post-carousel' ),
104 )
105 );
106 }
107 foreach ( $options as $option_key => $option ) {
108 if ( is_array( $option ) && ! empty( $option ) ) {
109 echo '<optgroup label="' . esc_attr( $option_key ) . '">';
110 foreach ( $option as $sub_key => $sub_value ) {
111 $selected = ( in_array( $sub_key, $this->value ) ) ? ' selected' : '';
112 echo '<option value="' . esc_attr( $sub_key ) . '" ' . esc_attr( $selected ) . '>' . wp_kses_post( $sub_value ) . '</option>';
113 }
114 echo '</optgroup>';
115 } else {
116 $selected = ( in_array( $option_key, $this->value ) ) ? ' selected' : '';
117 echo '<option value="' . esc_attr( $option_key ) . '" ' . esc_attr( $selected ) . '>' . wp_kses_post( $option ) . '</option>';
118 }
119 }
120 echo '</select>';
121 } else {
122 echo ( esc_html( ! empty( $this->field['empty_message'] ) ) ) ? esc_html( $this->field['empty_message'] ) : esc_html__( 'No data provided for this option type.', 'post-carousel' );
123 }
124 }
125 echo wp_kses_post( $this->field_after() );
126 }
127 /**
128 * Enqueue UI Sortable.
129 *
130 * @return void
131 */
132 public function enqueue() {
133 if ( ! wp_script_is( 'jquery-ui-sortable' ) ) {
134 wp_enqueue_script( 'jquery-ui-sortable' );
135 }
136 }
137 }
138 }
139