PluginProbe ʕ •ᴥ•ʔ
Spider Elements – Premium Elementor Widgets & Addons Library / 1.6.4
Spider Elements – Premium Elementor Widgets & Addons Library v1.6.4
trunk 1.0.0 1.1.0 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.7.0 1.8.0 1.9.0
spider-elements / includes / functions.php
spider-elements / includes Last commit date
Admin 1 year ago Frontend 1 year ago freemius 1 year ago filters.php 1 year ago functions.php 1 year ago
functions.php
726 lines
1 <?php
2 // Exit if accessed directly
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7 /**
8 * Check if the pro-plugin and plan is active
9 *
10 * @return bool
11 */
12 function spel_is_premium(): bool
13 {
14 return spel_fs()->is_plan('pro') && spel_fs()->can_use_premium_code();
15 }
16
17 function spel_unlock_docy_theme(): bool {
18 $theme = wp_get_theme();
19 $theme_name = $theme->get('Name');
20 $docy_themes = [ 'Docy', 'docy', 'Docy Child', 'docy-child' ];
21
22 return in_array($theme_name, $docy_themes, true) || spel_is_premium();
23 }
24
25 if ( ! function_exists( 'spel_rtl') ) {
26 function spel_rtl(): string {
27 return is_rtl() ? 'true' : 'false';
28 }
29 }
30
31
32 /**
33 * @return bool
34 * Elementor is edit mode
35 */
36 function spider_elements_is_edit(): bool
37 {
38 return \Elementor\Plugin::$instance->editor->is_edit_mode();
39 }
40
41 /**
42 * @return bool
43 * Elementor is preview mode
44 */
45 function spider_elements_is_preview(): bool
46 {
47 return \Elementor\Plugin::$instance->preview->is_preview_mode();
48 }
49
50
51 /**
52 * Elementor Title tags
53 */
54 if ( ! function_exists( 'spel_get_title_tags' ) ) {
55 function spel_get_title_tags(): array
56 {
57 return [
58 'h1' => esc_html__( 'H1', 'spider-elements' ),
59 'h2' => esc_html__( 'H2', 'spider-elements' ),
60 'h3' => esc_html__( 'H3', 'spider-elements' ),
61 'h4' => esc_html__( 'H4', 'spider-elements' ),
62 'h5' => esc_html__( 'H5', 'spider-elements' ),
63 'h6' => esc_html__( 'H6', 'spider-elements' ),
64 'div' => esc_html__( 'Div', 'spider-elements' ),
65 'span' => esc_html__( 'Span', 'spider-elements' ),
66 'p' => esc_html__( 'Paragraph', 'spider-elements' ),
67 ];
68 }
69 }
70
71
72 /**
73 * Echo button link attributes.
74 *
75 * @param array $settings_key
76 * @param bool $is_echo
77 */
78 if ( ! function_exists( 'spel_button_link' ) ) {
79 function spel_button_link( $settings_key, $is_echo = true ): void
80 {
81 if ( $is_echo ) {
82 echo ! empty( $settings_key['url'] ) ? 'href="' . esc_url( $settings_key['url'] ) . '"' : '';
83 echo $settings_key['is_external'] ? ' target="_blank"' : '';
84 echo $settings_key['nofollow'] ? ' rel="nofollow"' : '';
85
86 if ( ! empty( $settings_key['custom_attributes'] ) ) {
87 $attrs = explode( ',', $settings_key['custom_attributes'] );
88
89 if ( is_array( $attrs ) ) {
90 foreach ( $attrs as $data ) {
91 $data_attrs = explode( '|', $data );
92 echo ' ' . esc_attr( $data_attrs[0] ) . '="' . esc_attr( $data_attrs[1] ) . '"';
93 }
94 }
95 }
96 }
97 }
98 }
99
100 /**
101 * Category IDs
102 * @return array
103 */
104 if ( ! function_exists( 'spel_cat_ids') ) {
105 function spel_cat_ids() {
106
107 $taxonomys = get_terms( array(
108 'taxonomy' => 'category',
109 'hide_empty' => true,
110 ) );
111 $taxonomy = [];
112 if ( is_array( $taxonomys ) ) {
113 foreach ( $taxonomys as $cat_id ) {
114 $taxonomy[ $cat_id->term_id ] = $cat_id->name;
115 }
116 }
117
118 return $taxonomy;
119
120 }
121 }
122
123
124
125 /**
126 * Day link to archive page
127 **/
128 if ( ! function_exists( 'spel_day_link' ) ) {
129 function spel_day_link(): void
130 {
131 $archive_year = get_the_time( 'Y' );
132 $archive_month = get_the_time( 'm' );
133 $archive_day = get_the_time( 'd' );
134 echo esc_url( get_day_link( $archive_year, $archive_month, $archive_day ) );
135 }
136 }
137
138
139 /**
140 * Get title excerpt length
141 *
142 * @param $settings
143 * @param $settings_key
144 * @param int $default
145 *
146 * @return string|void
147 */
148 if ( ! function_exists( 'spel_get_title_length' ) ) {
149 function spel_get_title_length( $settings, $settings_key, $default = 10 ): string
150 {
151
152 $title_length = ! empty( $settings[ $settings_key ] ) ? $settings[ $settings_key ] : $default;
153 return get_the_title() ? wp_trim_words( get_the_title(), $title_length, '' ) : the_title();
154
155 }
156 }
157
158
159
160
161 /**
162 * Post's excerpt text
163 *
164 * @param $settings_key
165 * @param bool $echo
166 *
167 * @return string
168 **/
169 if ( ! function_exists( 'spel_get_excerpt_length' ) ) {
170 function spel_get_excerpt_length( $settings, $settings_key, $default = 10 ): string
171 {
172
173 $excerpt_length = ! empty( $settings[ $settings_key ] ) ? $settings[ $settings_key ] : $default;
174 return get_the_excerpt() ? wp_trim_words(
175 get_the_excerpt(),
176 $excerpt_length,
177 '...'
178 ) : wp_trim_words( get_the_content(), $excerpt_length, '...' );
179 }
180 }
181
182
183 /**
184 * Get the first category name
185 *
186 * @param string $term
187 *
188 * @return string
189 */
190 if ( ! function_exists( 'spel_get_first_taxonomy' ) ) {
191 function spel_get_first_taxonomy( $term = 'category' ): string
192 {
193 $cats = get_the_terms( get_the_ID(), $term );
194 $cat = is_array( $cats ) ? $cats[0]->name : '';
195
196 return esc_html( $cat );
197 }
198 }
199
200
201 /**
202 * Get the first category link
203 *
204 * @param string $term
205 *
206 * @return string
207 */
208 if ( ! function_exists( 'spel_get_first_taxonomy_link' ) ) {
209 function spel_get_first_taxonomy_link( $term = 'category' ): string
210 {
211
212 $cats = get_the_terms( get_the_ID(), $term );
213 $cat = is_array( $cats ) ? get_category_link( $cats[0]->term_id ) : '';
214
215 return esc_url( $cat );
216 }
217 }
218
219
220 /**
221 * Get categories array
222 *
223 * @param string $term
224 *
225 * @return array
226 */
227 if ( ! function_exists( 'spel_get_categories' ) ) {
228 function spel_get_categories( $term = 'category' ) {
229
230 $cats = get_terms( array(
231 'taxonomy' => $term,
232 'hide_empty' => true
233 ) );
234
235 $cat_array = [];
236 $cat_array['all'] = esc_html__( 'All', 'spider-elements' );
237
238 if ( is_array( $cats ) ) {
239 foreach ( $cats as $cat ) {
240 $cat_array[ $cat->term_id ] = $cat->name;
241 }
242 }
243
244 return $cat_array;
245 }
246 }
247
248
249 /**
250 * Get a category list
251 *
252 * @param string $term
253 *
254 * @return string
255 */
256 if ( ! function_exists( 'spel_get_post_category_list' ) ) {
257 function spel_get_post_category_list(): void
258 {
259 $categories = get_categories();
260
261 if ( ! empty( $categories ) ) {
262 echo '<span class="blog-category">';
263
264 $category_names = array();
265
266 if ( is_array( $categories ) ) {
267 foreach ( $categories as $category ) {
268 $category_link = get_category_link( $category->term_id );
269 $category_names[] = '<a href="' . esc_url( $category_link ) . '">' . esc_html( $category->name ) . '</a>';
270 }
271 }
272
273 echo esc_html( implode( ', ', $category_names ) );
274
275 echo '</span>';
276 } else {
277 echo esc_html__( 'No categories found.', 'spider-elements' );
278 }
279 }
280 }
281
282
283 /**
284 * Get an author name array
285 *
286 * @param string $term
287 *
288 * @return array
289 */
290 if ( ! function_exists( 'spel_get_post_author_name' ) ) {
291 function spel_get_post_author_name(): void
292 {
293 global $post;
294 $byline = sprintf(
295 /* translators: %s: post author. */
296 esc_html_x( 'By: %s', 'post author', 'spider-elements' ),
297 '<span class="author"><a class="url fn n" href="' . esc_url( get_author_posts_url( $post->post_author ) ) . '">' . esc_html( get_the_author_meta(
298 'display_name',
299 $post->post_author
300 ) ) . '</a></span>'
301 );
302
303 echo wp_kses_post( $byline ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
304 }
305 }
306
307 /**
308 * Get Default Image Elementor
309 *
310 * @param $settins_key
311 * @param string $class
312 * @param string $alt
313 */
314 if ( ! function_exists( 'spel_el_image' ) ) {
315 function spel_el_image( $settings_key = '', $alt = '', $class = '', $atts = [] ): void
316 {
317 if ( ! empty( $settings_key['id'] ) ) {
318 echo wp_get_attachment_image( $settings_key['id'], 'full', '', array( 'class' => $class ) );
319 } elseif ( ! empty( $settings_key['url'] ) && empty( $settings_key['id'] ) ) {
320 $class = ! empty( $class ) ? "class='$class'" : '';
321 $attss = '';
322 if ( ! empty( $atts ) ) {
323 foreach ( $atts as $k => $att ) {
324 $attss .= "$k=" . "'$att'";
325 }
326 }
327 echo "<img src='{$settings_key['url']}' $class alt='$alt' $attss>";
328 }
329 }
330 }
331
332
333 /**
334 * Get Default Image Elementor
335 *
336 * @param $settins_key
337 * @param string $class
338 * @param string $alt
339 */
340 if ( ! function_exists( 'spel_el_image_caption' ) ) {
341 function spel_el_image_caption( $image_id = '' ): array
342 {
343 $img_attachment = get_post( $image_id );
344
345 return array(
346 'alt' => get_post_meta( $img_attachment->ID, '_wp_attachment_image_alt', true ),
347 'caption' => $img_attachment->post_excerpt,
348 'href' => get_permalink( $img_attachment->ID ),
349 'src' => $img_attachment->guid,
350 'title' => $img_attachment->post_title
351 );
352 }
353 }
354
355
356 /**
357 * @param string $content Text content to filter.
358 *
359 * @return string Filtered content containing only the allowed HTML.
360 */
361 if ( ! function_exists( 'spel_kses_post' ) ) {
362 function spel_kses_post( $content ): string
363 {
364 $allowed_tag = array(
365 'strong' => [],
366 'br' => [],
367 'p' => [
368 'class' => [],
369 'style' => [],
370 ],
371 'i' => [
372 'class' => [],
373 'style' => [],
374 ],
375 'ul' => [
376 'class' => [],
377 'style' => [],
378 ],
379 'li' => [
380 'class' => [],
381 'style' => [],
382 ],
383 'span' => [
384 'class' => [],
385 'style' => [],
386 ],
387 'a' => [
388 'href' => [],
389 'class' => [],
390 'title' => []
391 ],
392 'div' => [
393 'class' => [],
394 'style' => [],
395 ],
396 'h1' => [
397 'class' => [],
398 'style' => []
399 ],
400 'h2' => [
401 'class' => [],
402 'style' => []
403 ],
404 'h3' => [
405 'class' => [],
406 'style' => []
407 ],
408 'h4' => [
409 'class' => [],
410 'style' => []
411 ],
412 'h5' => [
413 'class' => [],
414 'style' => []
415 ],
416 'h6' => [
417 'class' => [],
418 'style' => []
419 ],
420 'img' => [
421 'class' => [],
422 'style' => [],
423 'height' => [],
424 'width' => [],
425 'src' => [],
426 'srcset' => [],
427 'alt' => [],
428 ],
429
430 );
431
432 return wp_kses( $content, $allowed_tag );
433 }
434 }
435
436
437 /**
438 * Tab data
439 *
440 * @param $getCats
441 * @param $schedule_cats
442 *
443 * @return array
444 */
445 if ( ! function_exists( 'spel_get_tab_data' ) ) {
446 function spel_get_tab_data( $getCats, $schedule_cats ): array
447 {
448 $tab_data = [];
449
450 foreach ( $getCats as $val ) {
451 $matching_data = [];
452
453 foreach ( $schedule_cats as $data ) {
454 if ( $data['tab_title'] == $val ) {
455 $matching_data[] = $data;
456 }
457 }
458
459 $tab_data[ $val ] = $matching_data;
460 }
461
462 return $tab_data;
463 }
464 }
465
466
467 /**
468 * Get reading time
469 *
470 * @param string $term
471 *
472 * @return string
473 */
474 if ( ! function_exists( 'spel_get_reading_time' ) ) {
475 function spel_get_reading_time( $words_per_minute = 200 ): string
476 {
477 $content = get_post_field( 'post_content', get_the_ID() );
478 $word_count = str_word_count( wp_strip_all_tags( $content ) );
479 $reading_time = ceil( $word_count / $words_per_minute );
480 $timer = _n( 'minute', 'minutes', $reading_time, 'spider-elements' );
481
482 return sprintf( '%d %s', $reading_time, $timer );
483 }
484 }
485
486 /**
487 * Render Dynamic Image
488 * @param $key
489 * @param $class
490 * @return void
491 */
492 if ( ! function_exists( 'spel_dynamic_image' ) ) {
493 function spel_dynamic_image( $key, $size = 'full', $atts = [] ): void
494 {
495 $image = wp_get_attachment_image( $key['id'], $size, '', $atts );
496 echo wp_kses( $image, [
497 'img' => [
498 'class' => [],
499 'style' => [],
500 'height' => [],
501 'width' => [],
502 'src' => [],
503 'srcset' => [],
504 'alt' => [],
505 ],
506 ]);
507 }
508 }
509
510
511
512 /**
513 * Retrieve a list of posts based on specified parameters.
514 *
515 * @param string $post_type The post-type to query.
516 * @param int $limit The maximum number of posts to retrieve.
517 * @param string $search The search term for post-titles.
518 *
519 * @return array An associative array with post-IDs as keys and post-titles as values.
520 */
521 if ( ! function_exists( 'spel_get_query_post_list' ) ) {
522 function spel_get_query_post_list( $post_type = 'any', $limit = -1, $search = '' ): array
523 {
524 $args = [
525 'post_type' => $post_type,
526 'post_status' => 'publish',
527 'posts_per_page' => $limit,
528 's' => $search, // Search term
529 ];
530
531 $query = new WP_Query( $args );
532
533 $data = [];
534 if ( $query->have_posts() ) {
535 while ( $query->have_posts() ) {
536 $query->the_post();
537 $data[ get_the_ID() ] = get_the_title();
538 }
539 }
540
541 wp_reset_postdata(); // Reset post data after custom query
542
543 return $data;
544 }
545 }
546
547
548 /**
549 * Get all elementor page templates
550 *
551 * @param null $type
552 *
553 * @return array
554 */
555 if ( ! function_exists( 'spel_get_el_templates' ) ) {
556 function spel_get_el_templates( $type = null ): array
557 {
558 $options = [];
559
560 if ( $type ) {
561
562 $args = [
563 'post_type' => 'elementor_library',
564 'posts_per_page' => -1,
565 ];
566
567 $args['tax_query'] = [
568 [
569 'taxonomy' => 'elementor_library_type',
570 'field' => 'slug',
571 'terms' => $type,
572 ],
573 ];
574
575 $page_templates = get_posts( $args );
576
577 if ( ! empty( $page_templates ) && ! is_wp_error( $page_templates ) ) {
578 foreach ( $page_templates as $post ) {
579 $options[ $post->ID ] = $post->post_title;
580 }
581 }
582 } else {
583 $options = spel_get_query_post_list( 'elementor_library' );
584 }
585
586 return $options;
587 }
588 }
589
590
591 /**
592 * Get information about the server environment.
593 *
594 * @return array Server environment information.
595 */
596 if ( ! function_exists( 'spel_get_environment_info' ) ) {
597 function spel_get_environment_info(): array
598 {
599
600 // Figure out cURL version, if installed.
601 $curl_version = '';
602 if ( function_exists( 'curl_version' ) ) {
603 $curl_version = curl_version();
604 $curl_version = $curl_version['version'] . ', ' . $curl_version['ssl_version'];
605 }
606
607 // WP memory limit.
608 $wp_memory_limit = spel_readable_number(WP_MEMORY_LIMIT);
609 if ( function_exists( 'memory_get_usage' ) ) {
610 $wp_memory_limit = max( $wp_memory_limit, spel_readable_number( @ini_get( 'memory_limit' ) ) );
611 }
612
613 return array(
614 'home_url' => get_option( 'home' ),
615 'site_url' => get_option( 'siteurl' ),
616 'version' => SPEL_VERSION,
617 'wp_version' => get_bloginfo( 'version' ),
618 'wp_multisite' => is_multisite(),
619 'wp_memory_limit' => $wp_memory_limit,
620 'wp_debug_mode' => ( defined( 'WP_DEBUG' ) && WP_DEBUG ),
621 'wp_cron' => ! ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ),
622 'language' => get_locale(),
623 'external_object_cache' => wp_using_ext_object_cache(),
624 'server_info' => isset( $_SERVER['SERVER_SOFTWARE'] ) ? wp_unslash( $_SERVER['SERVER_SOFTWARE'] ) : '',
625 'php_version' => phpversion(),
626 'php_post_max_size' => spel_readable_number( ini_get( 'post_max_size' ) ),
627 'php_max_execution_time' => ini_get( 'max_execution_time' ),
628 'php_max_input_vars' => ini_get( 'max_input_vars' ),
629 'curl_version' => $curl_version,
630 'suhosin_installed' => extension_loaded( 'suhosin' ),
631 'max_upload_size' => wp_max_upload_size(),
632 'default_timezone' => date_default_timezone_get(),
633 'fsockopen_or_curl_enabled' => ( function_exists( 'fsockopen' ) || function_exists( 'curl_init' ) ),
634 'soapclient_enabled' => class_exists( 'SoapClient' ),
635 'domdocument_enabled' => class_exists( 'DOMDocument' ),
636 'gzip_enabled' => is_callable( 'gzopen' ),
637 'mbstring_enabled' => extension_loaded( 'mbstring' ),
638 );
639
640 }
641 }
642
643
644 /**
645 * Convert a human-readable file size into bytes.
646 *
647 * @param string $size The size string (e.g., "1M", "2G", "500 K").
648 * @return int The equivalent size in bytes.
649 */
650 if ( ! function_exists( 'spel_readable_number' ) ) {
651 function spel_readable_number($size): int
652 {
653
654 // Get the last character of the size string
655 $suffix = substr($size, -1);
656
657 // Remove the last character from the size string
658 $value = substr($size, 0, -1);
659
660 // Convert suffix to lowercase for case-insensitive comparison
661 $suffix = strtolower($suffix);
662
663 $multipliers = [
664 'p' => 1024,
665 't' => 1024,
666 'g' => 1024,
667 'm' => 1024,
668 'k' => 1024,
669 ];
670
671 // Check if the suffix is a valid multiplier
672 if (array_key_exists($suffix, $multipliers)) {
673 $value *= $multipliers[$suffix];
674 }
675
676 // Return the result
677 return (int)$value;
678
679 }
680 }
681
682
683 if ( !function_exists('spel_pagination') ) {
684 function spel_pagination($query, $class = 'spel-pagination', $prev = '', $next = ''): void
685 {
686
687 if ( $query->max_num_pages <= 1 ) {
688 return; // No pagination needed if only one page
689 }
690
691 $default_prev = '<img src="' . esc_url(SPEL_IMG . '/icons/prev.svg') . '" alt="' . esc_attr__('arrow-left', 'spider-elements') . '" class="me-2" />' . esc_html__('Prev', 'spider-elements');
692 $default_next = esc_html__('Next', 'spider-elements') . '<img src="' . esc_url(SPEL_IMG . '/icons/next.svg') . '" alt="' . esc_attr__('arrow-right', 'spider-elements') . '" class="ms-2" />';
693
694 $prev_text = !empty($prev) ? $prev : $default_prev;
695 $next_text = !empty($next) ? $next : $default_next;
696
697 echo '<ul class="' . esc_attr($class) . '">';
698
699 $big = 999999999; // need an unlikely integer
700 $current = max(1, get_query_var('paged') ? get_query_var('paged') : (get_query_var('page') ? get_query_var('page') : 1));
701
702 echo paginate_links(array(
703 'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
704 'format' => '?paged=%#%',
705 'current' => $current,
706 'total' => $query->max_num_pages,
707 'prev_text' => $prev_text,
708 'next_text' => $next_text,
709 ));
710
711 echo '</ul>';
712 }
713 }
714
715 /**
716 * Jobus pagination
717 */
718 if ( !function_exists('spel_archive_query') ) {
719 function spel_archive_query($query): void
720 {
721 if ( $query->is_main_query() && !is_admin() && !is_home() ) {
722 $query->set('posts_per_page', -1);
723 }
724 }
725 add_action('pre_get_posts', 'spel_archive_query');
726 }