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