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