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