PluginProbe
UiCore Elements – Free widgets and templates for Elementor / 1.3.17
UiCore Elements – Free widgets and templates for Elementor v1.3.17
1.3.17 1.3.16 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 All 41 releases
← All changes | includes/class-widget-base.php +96 -17 1.2.01.3.17 View file →
@@ -1,10 +1,13 @@
1 1 <?php
2 +
2 3 namespace UiCoreElements;
4 +
3 5 use Elementor\Widget_Base;
4 6 use UiCoreElements\Helper;
5 7
6 -abstract class UiCoreWidget extends Widget_Base {
8 +abstract class UiCoreWidget extends Widget_Base
9 +{
7 10
8 11 /**
9 12 * Get widget categories.
10 13 *
@@ -14,9 +17,9 @@
14 17 public abstract function get_styles();
15 18
16 19 /**
17 20 * Get widget categories.
18 - *
21 + *
19 22 * custom_condition need to always return true if $this->is_edit_mode() is true
20 23 * @return object ['assets-name' => ['condition' => ['key' => 'value'] ,'custom_condition' => true , 'deps' => ['global-handler-name','other-handler-name'], 'external' => true]]
21 24 */
22 25 public abstract function get_scripts();
@@ -23,9 +26,9 @@
23 26
24 27 public function get_style_depends()
25 28 {
26 29 $assets = $this->get_styles();
27 - $final_list = $this->parse_asset_list($assets,'style');
30 + $final_list = $this->parse_asset_list($assets, 'style');
28 31
29 32 //TODO: combine all the styles into one file and return it
30 33 return $final_list;
31 34 }
@@ -32,9 +35,9 @@
32 35
33 36 public function get_script_depends()
34 37 {
35 38 $assets = $this->get_scripts();
36 - $final_list = $this->parse_asset_list($assets,'script');
39 + $final_list = $this->parse_asset_list($assets, 'script');
37 40
38 41 //TODO: combine all the styles into one file and return it
39 42 return $final_list;
40 43 }
@@ -40,51 +43,53 @@
40 43 }
41 44
42 45
43 46
44 - private function parse_asset_list($list,$type='style'){
47 + private function parse_asset_list($list, $type = 'style')
48 + {
45 49 $final_list = [];
46 50 foreach ($list as $key => $value) {
47 51 $deps = (isset($value) && isset($value['deps'])) ? $value['deps'] : [];
48 52 $external = (isset($value) && isset($value['external'])) ? $value['external'] : false;
49 - $name = $this->get_asset_name($key,$value);
53 + $name = $this->get_asset_name($key, $value);
50 54
51 55 //if name is not empty then we need to add it to the list
52 - if($name){
56 + if ($name) {
53 57 $method_name = "register_widget_$type";
54 - $final_list[] = Helper::$method_name($name,$deps,$external);
58 + $final_list[] = Helper::$method_name($name, $deps, $external);
55 59 }
56 60 }
57 61 return $final_list;
58 62 }
59 63
60 - private function get_asset_name($key,$value){
64 + private function get_asset_name($key, $value)
65 + {
61 66 //check the condition/s
62 67 if (\is_array($value) && !empty($value)) {
63 68
64 69 //custom condition
65 - if(isset($value['custom_condition'])){
66 - if($value['custom_condition']){
70 + if (isset($value['custom_condition'])) {
71 + if ($value['custom_condition']) {
67 72 return $key;
68 - }else{
73 + } else {
69 74 return '';
70 75 }
71 76 }
72 77
73 78 //check if the condition is true using elementor's function (always return true if we are in edit mode)
74 - if($this->is_edit_mode() || $this->is_control_visible($value,$this->get_settings())){
79 + if ($this->is_edit_mode() || $this->is_control_visible($value, $this->get_settings())) {
75 80 return $key;
76 - }else{
81 + } else {
77 82 return '';
78 83 }
79 84 }
80 85 // if list is only declaring the assets without any condition then we need to return the key
81 86 return $value;
82 -
83 87 }
84 - protected function is_edit_mode() {
88 + protected function is_edit_mode()
89 + {
85 90 $elementor_instance = \Elementor\Plugin::instance();
86 - if ( $elementor_instance->preview->is_preview_mode() || $elementor_instance->editor->is_edit_mode() ) {
91 + if ($elementor_instance->preview->is_preview_mode() || $elementor_instance->editor->is_edit_mode()) {
87 92 return true;
88 93 }
89 94
90 95 return false;
@@ -89,6 +94,80 @@
89 94
90 95 return false;
91 96 }
92 97
98 + /**
99 + * Verify if the control exists and if matches the given value.
100 + * Usefull for controls that may not be returned, in the settings stack, under certain conditions.
101 + *
102 + * @param string $control The control slug.
103 + * @param string|null $value Optional. The value to check against.
104 + * @param string $operator Optional. The operator to use for comparing `control` and `value`. Default is '==='.
105 + *
106 + * @return bool
107 + * @since 1.0.15
108 + */
109 + protected function is_option(string $control, $value = null, $operator = '==='): bool
110 + {
111 + $option = $this->get_settings_for_display($control);
93 112
113 + if (isset($option)) {
114 +
115 + if (!isset($value)) {
116 + return true;
117 + }
118 +
119 + switch ($operator) {
120 + case '===':
121 + return $option === $value;
122 + case '!==':
123 + return $option !== $value;
124 + case '<':
125 + return $option < $value;
126 + case '<=':
127 + return $option <= $value;
128 + case '>':
129 + return $option > $value;
130 + case '>=':
131 + return $option >= $value;
132 + default:
133 + return false;
134 + }
135 + }
136 +
137 + return false;
138 + }
139 +
140 + /**
141 + * Verify if the control exists and get both `size` and `unit` values, if requested.
142 + *
143 + * @param string $control The control slug.
144 + * @param array $fallback The fallback value to return if the control does not exist. Should have `size` and, if requested, `unit` keys.
145 + * @param bool $use_unit If true, the unit will also be checked and returned.
146 + *
147 + * @return string `size` and, if requested, `unit` values from the control or the fallback value.
148 + * @since 1.0.15
149 + */
150 + public function get_option_size($control, array $fallback, $use_unit = false)
151 + {
152 + $option = $this->get_settings_for_display($control);
153 +
154 + if (isset($option) && ! empty($option['size'])) {
155 + $size = $control['size'];
156 + $unit = $use_unit && isset($option['unit']) ? $option['unit'] : '';
157 + return $size . $unit;
158 + }
159 +
160 + $fallback_size = $fallback['size'];
161 + $fallback_unit = $use_unit ? $fallback['unit'] : '';
162 + return $fallback_size . $fallback_unit;
163 + }
164 +
165 + /**
166 + * Determine if the widget content is dynamic. Dynamic widgets always have
167 + * their render content refreshed on each page load.
168 + */
169 + protected function is_dynamic_content(): bool
170 + {
171 + return true;
172 + }
94 173 }