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-helper.php +175 -89 1.2.21.3.17 View file →
@@ -1,5 +1,6 @@
1 1 <?php
2 +
2 3 namespace UiCoreElements;
3 4
4 5 use Elementor\Plugin;
5 6
@@ -29,9 +30,9 @@
29 30 foreach ($attributes as $att) {
30 31 $taxonomies['pa_' . $att->attribute_name] = $att->attribute_label;
31 32 }
32 33
33 - // All taxonomies
34 + // All taxonomies
34 35 } else {
35 36
36 37 $taxonomies = get_taxonomies(['public' => true], 'objects');
37 38 $exclusions = ['nav_menu', 'link_category', 'post_format']; // Exclude these taxonomies from the list
@@ -40,9 +41,9 @@
40 41 return !in_array($taxonomy->name, $exclusions);
41 42 });
42 43
43 44 $taxonomies = array_map(function ($taxonomy) {
44 - if('portfolio_category' === $taxonomy->name){
45 + if ('portfolio_category' === $taxonomy->name) {
45 46 return 'Portfolio Category';
46 47 }
47 48 return $taxonomy->label;
48 49 }, $taxonomies);
@@ -57,15 +58,15 @@
57 58
58 59 static function get_taxonomy($name)
59 60 {
60 61 global $post;
61 - $categories = get_the_terms( $post->ID, $name );
62 + $categories = get_the_terms($post->ID, $name);
62 63
63 - if ( ! $categories || is_wp_error( $categories ) ) {
64 + if (! $categories || is_wp_error($categories)) {
64 65 return false;
65 66 }
66 67
67 - $categories = array_values( $categories );
68 + $categories = array_values($categories);
68 69 foreach ($categories as $t) {
69 70 $term_name[] =
70 71 '<a href="' . get_term_link($t) . '" title="View ' . \esc_attr($t->name) . ' posts">' . esc_html($t->name) . '</a>';
71 72 }
@@ -73,16 +74,20 @@
73 74
74 75 return $category;
75 76 }
76 77
77 - static function get_custom_meta($name)
78 + static function get_custom_meta($name, $product_id = null)
78 79 {
79 - global $post;
80 + if (isset($product_id)) {
81 + $product = wc_get_product($product_id);
82 + $meta = $product->get_meta($name);
83 + } else {
84 + global $post;
85 + $meta = get_post_meta($post->ID, $name, true);
86 + }
80 87
81 - $meta = get_post_meta( $post->ID, $name, true );
82 -
83 88 // If is an array means meta is not valid since we are expecting a single value string
84 - if ( ! $meta || is_array($meta) ) {
89 + if (! $meta || is_array($meta)) {
85 90 return false;
86 91 }
87 92
88 93 return $meta;
@@ -92,17 +97,18 @@
92 97 {
93 98 global $post;
94 99
95 100 $the_content = $post->post_content;
96 - $words = str_word_count( wp_strip_all_tags( $the_content ) ); // count the number of words
97 - $minute = floor( $words / 200 ); // rounding off and deviding per 200 words per minute
101 + $words = str_word_count(wp_strip_all_tags($the_content)); // count the number of words
102 + $minute = floor($words / 200); // rounding off and deviding per 200 words per minute
98 103
99 104 return $minute;
100 105 }
101 106
102 - static function get_site_domain() {
103 - return str_ireplace( 'www.', '', parse_url( home_url(), PHP_URL_HOST ) );
104 - }
107 + static function get_site_domain()
108 + {
109 + return str_ireplace('www.', '', parse_url(home_url(), PHP_URL_HOST));
110 + }
105 111
106 112 /**
107 113 * Returns the Uicore Elements settings page URL. You may pass a message so it'll be wrapped under a <a> tag.
108 114 *
@@ -109,87 +115,98 @@
109 115 * @param string $message Optional. A clickable message to be displayed that'll redirect, in a new tab, to settings page.
110 116 *
111 117 * @return string Uicore Elements settings page URL or an <a> tag HTML with the url and the passed message.
112 118 */
113 - static function get_admin_settings_url(string $message = '') {
114 - $url = admin_url( 'options-general.php?page=uicore-elements' );
119 + static function get_admin_settings_url(string $message = '')
120 + {
121 + $url = admin_url('options-general.php?page=uicore-elements');
115 122 return !empty($message)
116 - ? '<a href="'.esc_url($url).'" target="_blank">' . esc_html($message) . '</a>'
123 + ? '<a href="' . esc_url($url) . '" target="_blank">' . esc_html($message) . '</a>'
117 124 : $url;
118 125 }
119 126
120 - static function register_widget_style($name,$deps=[],$external=false)
127 + static function register_widget_style($name, $deps = [], $external = false)
121 128 {
122 - $handle = (!$external ? 'ui-e-' : '' ). $name;
123 - wp_register_style($handle, UICORE_ELEMENTS_ASSETS . '/css/elements/'.$name.'.css',$deps,UICORE_ELEMENTS_VERSION);
129 + $handle = (!$external ? 'ui-e-' : '') . $name;
130 + wp_register_style($handle, UICORE_ELEMENTS_ASSETS . '/css/elements/' . $name . '.css', $deps, UICORE_ELEMENTS_VERSION);
124 131 return $handle;
125 132 }
126 - static function register_widget_script($name,$deps=[],$external=false)
133 + static function register_widget_script($name, $deps = [], $external = false)
127 134 {
128 - $handle = (!$external ? 'ui-e-' : '' ). $name;
135 + $handle = (!$external ? 'ui-e-' : '') . $name;
129 136 //if name contains / then we need to set a custom path
130 - if(strpos($name,'/') !== false){
131 - $path ='';
132 - }else{
137 + if (strpos($name, '/') !== false) {
138 + $path = '';
139 + } else {
133 140 $path = 'elements/';
134 141 }
135 - wp_register_script($handle, UICORE_ELEMENTS_ASSETS . '/js/'.$path.$name.'.js',$deps,UICORE_ELEMENTS_VERSION,true);
142 + wp_register_script($handle, UICORE_ELEMENTS_ASSETS . '/js/' . $path . $name . '.js', $deps, UICORE_ELEMENTS_VERSION, true);
136 143 return $handle;
137 144 }
138 145
139 - public static function get_related($filter, $number)
146 + /**
147 + * Build the related posts query in REST API context.
148 + *
149 + * @param int $page_number The current page number for pagination.
150 + * @param int $per_page The number of posts to retrieve per page.
151 + * @param string/int $pageID The current post/page ID.
152 + *
153 + * @return \WP_Query Returns a WP_Query object.
154 + */
155 + public static function get_related_ajax(int $page_number, int $per_page, $pageID)
140 156 {
141 - global $post;
157 + $args = [
158 + 'post__not_in' => [$pageID],
159 + 'posts_per_page' => $per_page,
160 + 'paged' => $page_number,
161 + ];
142 162
143 - $args = [];
163 + $categories = get_the_category($pageID);
164 + $tags = wp_get_post_tags($pageID);
144 165
145 - if ($filter == 'category') {
146 - $categories = get_the_category($post->ID);
166 + $tax_query = [];
147 167
148 - if ($categories) {
149 - $category_ids = array_map(fn($cat) => $cat->term_id, $categories);
168 + if ($categories) {
169 + $category_ids = array_map(fn($cat) => $cat->term_id, $categories);
170 + $tax_query[] = [
171 + 'taxonomy' => 'category',
172 + 'field' => 'term_id',
173 + 'terms' => $category_ids,
174 + 'operator' => 'IN',
175 + ];
176 + }
150 177
151 - // basic args
152 - $args = [
153 - 'post__not_in' => [$post->ID],
154 - 'posts_per_page' => $number,
155 - 'category__in' => $category_ids,
156 - 'ignore_sticky_posts' => 1,
157 - ];
158 - }
178 + if ($tags) {
179 + $tag_ids = array_map(fn($tag) => $tag->term_id, $tags);
180 + $tax_query[] = [
181 + 'taxonomy' => 'post_tag',
182 + 'field' => 'term_id',
183 + 'terms' => $tag_ids,
184 + 'operator' => 'IN',
185 + ];
186 + }
159 187
160 - } elseif ($filter == 'tag') {
161 - $tags = wp_get_post_tags($post->ID);
162 -
163 - if ($tags) {
164 - $tag_ids = array_map(fn($tag) => $tag->term_id, $tags);
165 -
166 - $args = [
167 - 'post__not_in' => [$post->ID],
168 - 'posts_per_page' => $number,
169 - 'tag__in' => $tag_ids,
170 - 'ignore_sticky_posts' => 1,
171 - ];
172 - }
173 -
174 - // default/random filter
175 - } else {
176 - $args = [
177 - 'post__not_in' => [$post->ID],
178 - 'posts_per_page' => $number,
179 - 'orderby' => 'rand',
188 + if (!empty($tax_query)) {
189 + $args['tax_query'] = [
190 + 'relation' => 'OR',
191 + ...$tax_query,
180 192 ];
181 193 }
182 194
183 - $related_query = new \WP_Query($args);
184 - return $related_query->have_posts() ? $related_query : false;
195 + return new \WP_Query($args);
185 196 }
186 197
187 - public static function get_product_related($limit)
198 + /**
199 + * Returns an array of related products IDs.
200 + */
201 + public static function get_product_related($limit, $ID)
188 202 {
189 - global $post;
203 + if (empty($ID)) {
204 + global $post;
205 + $ID = $post->ID;
206 + }
190 207
191 - return wc_get_related_products($post->ID, $limit);
208 + return wc_get_related_products($ID, $limit);
192 209 }
193 210
194 211 /*
195 212 * Get the current post id (used in Theme Builder - UiCore Framework)
@@ -195,13 +212,13 @@
195 212 * Get the current post id (used in Theme Builder - UiCore Framework)
196 213 */
197 214 static function get_current_meta_id()
198 215 {
199 - if(\class_exists('\UiCore\Blog\Frontend') && \UiCore\Blog\Frontend::is_blog() && !is_singular('post')){
216 + if (\class_exists('\UiCore\Blog\Frontend') && \UiCore\Blog\Frontend::is_blog() && !is_singular('post')) {
200 217 $post_id = get_option('page_for_posts', true);
201 - }elseif(\class_exists('\UiCore\Portfolio\Frontend') && \UiCore\Portfolio\Frontend::is_portfolio() && !is_singular('portfolio')){
218 + } elseif (\class_exists('\UiCore\Portfolio\Frontend') && \UiCore\Portfolio\Frontend::is_portfolio() && !is_singular('portfolio')) {
202 219 $post_id = \UiCore\Portfolio\Frontend::get_portfolio_page_id();
203 - }else{
220 + } else {
204 221 $post_id = get_queried_object_id();
205 222 }
206 223
207 224 return $post_id;
@@ -209,9 +226,10 @@
209 226
210 227 /**
211 228 * Return a list of textual html tags for Elementor Controls Options
212 229 */
213 - public static function get_title_tags() {
230 + public static function get_title_tags()
231 + {
214 232
215 233 $tags = [
216 234 'h1' => 'H1',
217 235 'h2' => 'H2',
@@ -236,13 +254,14 @@
236 254 * @param string $custom The custom format to use if $format is set to 'custom'.
237 255 *
238 256 * @return string The formatted date value.
239 257 */
240 - public static function format_date($date, $format, $custom) {
258 + public static function format_date($date, $format, $custom)
259 + {
241 260
242 - if ( 'custom' === $format ) {
261 + if ('custom' === $format) {
243 262 $date_format = $custom;
244 - } else if ('default' === $format ) {
263 + } else if ('default' === $format) {
245 264 $date_format = get_option('date_format');
246 265 } else {
247 266 $date_format = $format;
248 267 }
@@ -252,8 +271,37 @@
252 271 return wp_kses_post($value);
253 272 }
254 273
255 274 /**
275 + * Sanitizes HTML tags. Since is a custom sanitizer, require us, by wp plugin repo security standards,
276 + * to add `//phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped` comment.
277 + *
278 + * @param mixed $raw_tag The HTML tag to sanitize.
279 + * @param string $default Default HTML value to fallback to in case an invalid tag is passed. Default is 'h3'.
280 + * @param bool $spacing Whether to add a trailing space after the tag. Default is false.
281 + * @return string The sanitized HTML tag.
282 + *
283 + * @since 1.3.5
284 + */
285 + public static function esc_tag($raw_tag, $default = 'h3', $spacing = false)
286 + {
287 +
288 + $allowed_tags_names = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'div', 'span', 'p', 'a'];
289 + $tag = sanitize_key(strtolower($raw_tag)); // normalizes to [a-z0-9_]
290 +
291 + // fallback if tag not whitelisted
292 + if (! in_array($tag, $allowed_tags_names, true)) {
293 + $tag = $default;
294 + }
295 +
296 + if ($spacing) {
297 + return $tag . ' ';
298 + }
299 +
300 + return $tag;
301 + }
302 +
303 + /**
256 304 * Sanitizes SVG content, also allowing `post` tags and atts. Since is a custom sanitizer, require us,
257 305 * by wp plugin repo security standards, to add `//phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped` comment.
258 306 *
259 307 * @param string $svg The raw SVG content to be sanitized.
@@ -260,10 +308,11 @@
260 308 * @return string The sanitized SVG content, with only allowed tags and attributes.
261 309 *
262 310 * @since 1.0.2
263 311 */
264 - public static function esc_svg($svg) {
265 - $default = wp_kses_allowed_html( 'post' );
312 + public static function esc_svg($svg)
313 + {
314 + $default = wp_kses_allowed_html('post');
266 315
267 316 $args = array(
268 317 'svg' => array(
269 318 'class' => true,
@@ -276,18 +325,18 @@
276 325 // has to be lowercase
277 326 'viewbox' => true,
278 327 'preserveaspectratio' => true
279 328 ),
280 - 'g' => array( 'fill' => true ),
281 - 'title' => array( 'title' => true ),
329 + 'g' => array('fill' => true),
330 + 'title' => array('title' => true),
282 331 'path' => array(
283 332 'd' => true,
284 333 'fill' => true
285 334 )
286 335 );
287 - $allowed_tags = array_merge( $default, $args );
336 + $allowed_tags = array_merge($default, $args);
288 337
289 - return wp_kses( $svg, $allowed_tags );
338 + return wp_kses($svg, $allowed_tags);
290 339 }
291 340
292 341 /**
293 342 * Sanitizes text strings, but allowing some html tags usefull for styling and manipulating texts. Since is a custom sanitizer,
@@ -297,9 +346,10 @@
297 346 * @return string The sanitized string content.
298 347 *
299 348 * @since 1.0.3
300 349 */
301 - public static function esc_string($content) {
350 + public static function esc_string($content)
351 + {
302 352
303 353 $allowed_tags = [
304 354 'strong' => array(),
305 355 'em' => array(),
@@ -318,9 +368,9 @@
318 368 'rel' => true
319 369 ]
320 370 ];
321 371
322 - return wp_kses( $content, $allowed_tags );
372 + return wp_kses($content, $allowed_tags);
323 373 }
324 374
325 375 /**
326 376 * Retrieves the available image sizes.
@@ -328,9 +378,10 @@
328 378 * @return array An array of image sizes.
329 379 *
330 380 * @since 1.0.0
331 381 */
332 - public static function get_images_sizes() {
382 + public static function get_images_sizes()
383 + {
333 384 $sizes = [];
334 385 foreach (get_intermediate_image_sizes() as $size) {
335 386 $sizes[$size] = $size;
336 387 }
@@ -339,9 +390,10 @@
339 390
340 391 /**
341 392 * @since 1.0.5
342 393 */
343 - private static function get_element_recursive($elements, $form_id) {
394 + private static function get_element_recursive($elements, $form_id)
395 + {
344 396
345 397 foreach ($elements as $element) {
346 398 if ($form_id === $element['id']) {
347 399 return $element;
@@ -368,9 +420,10 @@
368 420 *
369 421 * @since 1.0.5
370 422 * @deprecated Deprecated since version 1.0.11 Use the transient method instead.
371 423 */
372 - public static function get_widget_settings($post_id, $widget_id) {
424 + public static function get_widget_settings($post_id, $widget_id)
425 + {
373 426
374 427 if (!$post_id || !$widget_id) {
375 428 return false;
376 429 }
@@ -405,14 +458,14 @@
405 458 *
406 459 * @since 1.2.1
407 460 * @return int The number of posts per page.
408 461 */
409 - public static function get_framework_visible_posts( string $post_type )
462 + public static function get_framework_visible_posts(string $post_type)
410 463 {
411 464 // Get from Uicore Framework, if available
412 - if(defined('UICORE_ASSETS')){
465 + if (defined('UICORE_ASSETS')) {
413 466
414 - switch($post_type){
467 + switch ($post_type) {
415 468 case 'product':
416 469 return \Uicore\Helper::get_option('woocommerce_posts_number');
417 470
418 471 case 'post':
@@ -422,12 +475,45 @@
422 475 return \Uicore\Helper::get_option('portfolio_posts_number');
423 476
424 477 default:
425 478 return get_option('posts_per_page');
426 -
427 479 }
428 480 }
429 481
430 482 return get_option('posts_per_page');
431 483 }
484 + /**
485 + * Retrieves the list of Uicore Framework registered popups.
486 + *
487 + * @return array
488 + *
489 + * @since 1.3.3
490 + */
491 + public static function get_uicore_popups(): array
492 + {
493 + // get elementor popups posts
494 + $args = [
495 + 'post_type' => 'uicore-tb',
496 + 'post_status' => 'publish',
497 + 'posts_per_page' => 50,
498 + 'tax_query' => [
499 + [
500 + 'taxonomy' => 'tb_type',
501 + 'field' => 'slug',
502 + 'terms' => '_type_popup',
503 + ]
504 + ]
505 + ];
432 506
507 + $query = new \WP_Query($args);
508 + $popups = [];
509 + if ($query->have_posts()) {
510 + while ($query->have_posts()) {
511 + $query->the_post();
512 + $popups[esc_html(get_the_ID())] = esc_html(html_entity_decode(get_the_title()));
513 + }
514 + wp_reset_postdata();
515 + }
516 +
517 + return $popups;
518 + }
433 519 }