PluginProbe
Ultimate Store Kit / 3.1.2
Ultimate Store Kit v3.1.2
3.0.8 3.0.9 3.1.0 3.1.2 3.1.3 3.0.7 3.0.5 3.0.4 3.0.3 3.0.2 trunk 1.5.0 1.5.1 1.5.2 1.6.1 1.6.2 1.6.3 1.6.4 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 All 92 releases
ultimate-store-kit / includes / controls / select-input / dynamic-select.php

dynamic-select.php in Ultimate Store Kit 3.1.2, at includes/controls/select-input/dynamic-select.php

127 lines 4.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace UltimateStoreKit\Includes\Controls\SelectInput;
4
5 use Elementor\Base_Data_Control;
6 use Elementor\Plugin;
7
8 if (!defined('ABSPATH')) {
9 exit; // Exit if accessed directly.
10 }
11
12 /**
13 * Dynamic select control.
14 *
15 * A base control for creating Dynamic_Select control. Displays a select box control
16 * based on select on elementor select2 control .
17 * It accepts an array in which the `key` is the value and the `value` is the
18 * option name. Set `multiple` to `true` to allow multiple value selection.
19 *
20 * @since 5.8.0
21 */
22 class Dynamic_Select extends Base_Data_Control {
23
24 const TYPE = 'usk-dynamic-select';
25
26 /**
27 * Get control type.
28 *
29 * Retrieve the control type.
30 * @since 5.8.0
31 * @access public
32 */
33 public function get_type() {
34 return self::TYPE;
35 }
36
37 /**
38 * Get select2 control default settings.
39 *
40 * Retrieve the default settings of the select2 control. Used to return the
41 * default settings while initializing the select2 control.
42 *
43 * @return array Control default settings.
44 * @since 5.8.0
45 * @access protected
46 *
47 */
48 protected function get_default_settings() {
49 return [
50 'options' => [],
51 'multiple' => false,
52 // Select2 library options
53 'select2options' => [],
54 // the lockedOptions array can be passed option keys. The passed option keys will be non-deletable.
55 'lockedOptions' => [],
56 // the query arguments array can be passed,
57 'query_args' => array(),
58
59 ];
60 }
61
62 /**
63 * Render select2 control output in the editor.
64 *
65 * Used to generate the control HTML in the editor using Underscore JS
66 * template. The variables for the class are available using `data` JS
67 * object.
68 * @since 5.8.0
69 * @access public
70 */
71 public function content_template() {
72 $control_uid = $this->get_control_uid();
73 ?>
74 <div class="elementor-control-field">
75 <# if ( data.label ) {#>
76 <label for="<?php echo esc_attr($control_uid); ?>" class="elementor-control-title">{{{data.label }}}</label>
77 <# } #>
78 <div class="elementor-control-input-wrapper elementor-control-unit-5">
79 <# var multiple = ( data.multiple ) ? 'multiple' : ''; #>
80 <select id="<?php echo esc_attr($control_uid); ?>" class="elementor-select2" type="select2" {{ multiple }}
81 data-setting="{{ data.name }}">
82 <# _.each( data.options, function( option_title, option_value ) {
83 var value = data.controlValue;
84 if ( typeof value == 'string' ) {
85 var selected = ( option_value === value ) ? 'selected' : '';
86 } else if ( null !== value ) {
87 var value = _.values( value );
88 var selected = ( -1 !== value.indexOf( option_value ) ) ? 'selected' : '';
89 }
90 #>
91 <option {{ selected }} value="{{ option_value }}">{{{option_title }}}</option>
92 <# } ); #>
93 </select>
94 </div>
95 </div>
96 <# if ( data.description ) { #>
97 <div class="elementor-control-field-description">{{{data.description }}}</div>
98 <# } #>
99 <?php
100 }
101
102 /**
103 * Enqueue control scripts and styles.
104 *
105 * Used to register and enqueue custom scripts and styles used by the control.
106 * @since 5.8.0
107 */
108 public function enqueue() {
109 wp_enqueue_script('usk-dynamic-select', BDTUSK_URL . 'includes/controls/assets/js/usk-dynamic-select.min.js', array('jquery'), BDTUSK_VER, true);
110
111 wp_localize_script(
112 'usk-dynamic-select',
113 'usk_dynamic_select',
114 [
115 'nonce' => wp_create_nonce('usk_dynamic_select'),
116 'action' => 'ultimate_store_kit_dynamic_select_input_data',
117 'ajax_url' => admin_url('admin-ajax.php')
118 ]
119 );
120 }
121 }
122
123 add_action('elementor/controls/register', function () {
124 $controls_manager = Plugin::$instance->controls_manager;
125 $controls_manager->register(new Dynamic_Select());
126 });
127