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

145 lines 5.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The framework select fields file.
4 *
5 * @package Smart_Post_Show
6 * @subpackage Smart_Post_Show/admin
7 */
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 die;
11 } // Cannot access directly.
12
13 if ( ! class_exists( 'SP_PC_Field_select' ) ) {
14 /**
15 * SP_PC_Field_select
16 */
17 class SP_PC_Field_select extends SP_PC_Fields {
18
19 /**
20 * The select field constructor.
21 *
22 * @param string $field The field type.
23 * @param string $value The field value.
24 * @param string $unique The unique ID.
25 * @param string $where The place to show the field.
26 * @param string $parent If it has any parent.
27 */
28 public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
29 parent::__construct( $field, $value, $unique, $where, $parent );
30 }
31
32 /**
33 * The render function.
34 *
35 * @return void
36 */
37 public function render() {
38
39 $args = wp_parse_args(
40 $this->field,
41 array(
42 'placeholder' => '',
43 'chosen' => false,
44 'multiple' => false,
45 'sortable' => false,
46 'ajax' => false,
47 'settings' => array(),
48 'query_args' => array(),
49 )
50 );
51
52 $this->value = ( is_array( $this->value ) ) ? $this->value : array_filter( (array) $this->value );
53
54 echo wp_kses_post( $this->field_before() );
55
56 if ( isset( $this->field['options'] ) ) {
57
58 $multiple_type = isset( $this->field['multiple_type'] ) ? $this->field['multiple_type'] : false;
59
60 if ( ! empty( $args['ajax'] ) ) {
61 $args['settings']['data']['type'] = $args['options'];
62 $args['settings']['data']['nonce'] = wp_create_nonce( 'spf_chosen_ajax_nonce' );
63 if ( ! empty( $args['query_args'] ) ) {
64 $args['settings']['data']['query_args'] = $args['query_args'];
65 }
66 }
67 $chosen_rtl = ( is_rtl() ) ? ' chosen-rtl' : '';
68 $multiple_name = ( $args['multiple'] ) ? '[]' : '';
69 $multiple_attr = ( $args['multiple'] ) ? ' multiple="multiple"' : '';
70 $chosen_sortable = ( $args['chosen'] && $args['sortable'] ) ? ' spf-chosen-sortable' : '';
71 $chosen_attr = ( $args['chosen'] ) ? ' class="spf-chosen' . $chosen_rtl . '"' : '';
72 $chosen_ajax = ( $args['chosen'] && $args['ajax'] ) ? ' spf-chosen-ajax' : '';
73 $placeholder_attr = ( $args['chosen'] && $args['placeholder'] ) ? ' data-placeholder="' . $args['placeholder'] . '"' : '';
74 $field_class = ( $args['chosen'] ) ? ' class="spf-chosen' . $chosen_rtl . $chosen_sortable . $chosen_ajax . '"' : '';
75 $field_name = $this->field_name( $multiple_name );
76 $field_attr = $this->field_attributes();
77 $maybe_options = $this->field['options'];
78 $field_unique = $this->unique;
79 $chosen_data_attr = ( $args['chosen'] && ! empty( $args['settings'] ) ) ? ' data-chosen-settings="' . esc_attr( json_encode( $args['settings'] ) ) . '"' : '';
80 if ( is_string( $maybe_options ) && ! empty( $args['chosen'] ) && ! empty( $args['ajax'] ) ) {
81 $options = $this->field_wp_query_data_title( $maybe_options, $this->value );
82 } elseif ( is_string( $maybe_options ) ) {
83 $options = $this->field_data( $maybe_options, false, $args['query_args'], $field_unique );
84 } else {
85 $options = $maybe_options;
86 }
87 if ( ( is_array( $options ) && ! empty( $options ) ) || ( ! empty( $args['chosen'] ) && ! empty( $args['ajax'] ) ) ) {
88 if ( ! empty( $args['chosen'] ) && ! empty( $args['multiple'] ) ) {
89 echo '<select name="' . esc_attr( $field_name ) . '" class="spf-hidden-select spf-hidden"' . wp_kses_post( $multiple_attr . $field_attr ) . '>';
90 foreach ( $this->value as $option_key ) {
91 echo '<option value="' . esc_attr( $option_key ) . '" selected>' . esc_html( $option_key ) . '</option>';
92 }
93 echo '</select>';
94 $field_name = '_pseudo';
95 $field_attr = '';
96 }
97 echo '<select name="' . esc_attr( $field_name ) . '"' . wp_kses_post( $field_class . $multiple_attr . $placeholder_attr . $field_attr . $chosen_data_attr ) . '>';
98 if ( $args['placeholder'] && empty( $args['multiple'] ) ) {
99 if ( ! empty( $args['chosen'] ) ) {
100 echo '<option value=""></option>';
101 } else {
102 echo '<option value="">' . esc_html( $args['placeholder'] ) . '</option>';
103 }
104 }
105 if ( $multiple_type ) {
106 $options = array_merge(
107 $options,
108 array(
109 'multiple_post_type' => __( 'Multiple Post Types (Pro)', 'post-carousel' ),
110 )
111 );
112 }
113 foreach ( $options as $option_key => $option ) {
114 if ( is_array( $option ) && ! empty( $option ) ) {
115 echo '<optgroup label="' . esc_attr( $option_key ) . '">';
116 foreach ( $option as $sub_key => $sub_value ) {
117 $selected = ( in_array( $sub_key, $this->value ) ) ? ' selected' : '';
118 echo '<option value="' . esc_attr( $sub_key ) . '" ' . esc_attr( $selected ) . '>' . wp_kses_post( $sub_value ) . '</option>';
119 }
120 echo '</optgroup>';
121 } else {
122 $selected = ( in_array( $option_key, $this->value ) ) ? ' selected' : '';
123 echo '<option value="' . esc_attr( $option_key ) . '" ' . esc_attr( $selected ) . '>' . wp_kses_post( $option ) . '</option>';
124 }
125 }
126 echo '</select>';
127 } else {
128 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' );
129 }
130 }
131 echo wp_kses_post( $this->field_after() );
132 }
133 /**
134 * Enqueue UI Sortable.
135 *
136 * @return void
137 */
138 public function enqueue() {
139 if ( ! wp_script_is( 'jquery-ui-sortable' ) ) {
140 wp_enqueue_script( 'jquery-ui-sortable' );
141 }
142 }
143 }
144 }
145