PluginProbe
Ultimate Post Kit – Elementor Post Grid, Post Carousel, Post Slider & Blog Layout Widgets / 4.1.18
Ultimate Post Kit – Elementor Post Grid, Post Carousel, Post Slider & Blog Layout Widgets v4.1.18
4.5.4 4.2.1 4.2.2 4.2.3 4.5.0 4.5.2 4.5.3 4.2.0 4.1.18 4.1.17 4.1.16 4.1.15 4.1.14 4.1.13 4.1.12 4.1.11 4.1.10 4.1.9 4.1.8 4.0.9 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 All 146 releases
ultimate-post-kit / includes / helper.php

helper.php in Ultimate Post Kit – Elementor Post Grid, Post Carousel, Post Slider & Blog Layout Widgets 4.1.18, at includes/helper.php

1,044 lines 28.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 use UltimatePostKit\Ultimate_Post_Kit_Loader;
4 use Elementor\Plugin;
5
6 /**
7 * You can easily add white label branding for for extended license or multi site license.
8 * Don't try for regular license otherwise your license will be invalid.
9 * return white label
10 */
11
12 /**
13 * You can easily add white label branding for for extended license or multi site license.
14 * Don't try for regular license otherwise your license will be invalid.
15 * return white label
16 */
17 define( 'BDTUPK_PNAME', basename( dirname( BDTUPK__FILE__ ) ) );
18 define( 'BDTUPK_PBNAME', plugin_basename( BDTUPK__FILE__ ) );
19 define( 'BDTUPK_PATH', plugin_dir_path( BDTUPK__FILE__ ) );
20 define( 'BDTUPK_URL', plugins_url( '/', BDTUPK__FILE__ ) );
21 define( 'BDTUPK_ADMIN_PATH', BDTUPK_PATH . 'admin/' );
22 define( 'BDTUPK_ADMIN_URL', BDTUPK_URL . 'admin/' );
23 define( 'BDTUPK_ADMIN_ASSETS_PATH', BDTUPK_PATH . 'admin/assets/' );
24 define( 'BDTUPK_ADMIN_ASSETS_URL', BDTUPK_URL . 'admin/assets/' );
25 define( 'BDTUPK_MODULES_PATH', BDTUPK_PATH . 'modules/' );
26 define( 'BDTUPK_INC_PATH', BDTUPK_PATH . 'includes/' );
27 define( 'BDTUPK_ASSETS_URL', BDTUPK_URL . 'assets/' );
28 define( 'BDTUPK_ASSETS_PATH', BDTUPK_PATH . 'assets/' );
29 define( 'BDTUPK_MODULES_URL', BDTUPK_URL . 'modules/' );
30
31
32 if ( ! defined( 'BDTUPK' ) ) {
33 define( 'BDTUPK', '' );
34 } //Add prefix for all widgets <span class="upk-widget-badge"></span>
35 if ( ! defined( 'BDTUPK_CP' ) ) {
36 define( 'BDTUPK_CP', '<span class="upk-widget-badge"></span>' );
37 } //Add prefix for all widgets <span class="upk-widget-badge"></span>
38 if ( ! defined( 'BDTUPK_NC' ) ) {
39 define( 'BDTUPK_NC', '<span class="upk-new-control"></span>' );
40 } //Add prefix for all widgets <span class="upk-widget-badge"></span>
41 if ( ! defined( 'BDTUPK_UC' ) ) {
42 define( 'BDTUPK_UC', '<span class="upk-updated-control"></span>' );
43 } // if you have any custom style
44
45 if ( _is_upk_pro_activated() ) {
46 if ( ! defined( 'BDTUPK_PC' ) ) {
47 define( 'BDTUPK_PC', '' );
48 } // pro control badge
49 if ( ! defined( 'BDTUPK_SLUG' ) ) {
50 define( 'BDTUPK_SLUG', 'ultimate-post-kit' );
51 } // set your own alias
52 if ( ! defined( 'BDTUPK_TITLE' ) ) {
53 define( 'BDTUPK_TITLE', 'Ultimate Post Kit' );
54 } // Set your own name for plugin
55 define( 'BDTUPK_IS_PC', '' );
56 } else {
57 if ( ! defined( 'BDTUPK_PC' ) ) {
58 define( 'BDTUPK_PC', '<span class="upk-pro-control"></span>' );
59 } // pro control badge
60 if ( ! defined( 'BDTUPK_SLUG' ) ) {
61 define( 'BDTUPK_SLUG', 'ultimate-post-kit' );
62 } // set your own alias
63 if ( ! defined( 'BDTUPK_TITLE' ) ) {
64 define( 'BDTUPK_TITLE', 'Ultimate Post Kit' );
65 } // Set your own name for plugin
66 define( 'BDTUPK_IS_PC', 'upk-disabled-control' );
67 }
68
69 function ultimate_post_kit_is_edit() {
70 return Plugin::$instance->editor->is_edit_mode();
71 }
72
73 function ultimate_post_kit_is_preview() {
74 return Plugin::$instance->preview->is_preview_mode();
75 }
76
77 // add socials list meta in user profile
78 function ultimate_post_kit_user_contact_methods( $methods, $core = false ) {
79
80 if ( $core ) {
81 $methods['email'] = __( 'Email', 'ultimate-post-kit' );
82 $methods['url'] = __( 'Website', 'ultimate-post-kit' );
83 }
84
85 $methods['facebook'] = __( 'Facebook', 'ultimate-post-kit' );
86 $methods['twitter'] = __( 'Twitter', 'ultimate-post-kit' );
87 $methods['linkedin'] = __( 'LinkedIn', 'ultimate-post-kit' );
88 $methods['github'] = __( 'GitHub', 'ultimate-post-kit' );
89 $methods['wordpress'] = __( 'WordPress', 'ultimate-post-kit' );
90 $methods['dribbble'] = __( 'Dribbble', 'ultimate-post-kit' );
91
92 return $methods;
93 }
94
95 add_filter( 'user_contactmethods', 'ultimate_post_kit_user_contact_methods' );
96
97 /**
98 * Show any alert by this function
99 *
100 * @param mixed $message [description]
101 * @param class prefix $type [description]
102 * @param boolean $close [description]
103 *
104 * @return helper [description]
105 */
106 function ultimate_post_kit_alert( $message, $type = 'warning', $close = true ) {
107 ?>
108 <div class="upk-alert-<?php echo esc_attr( $type ); ?>" data-upk-alert>
109 <?php if ( $close ) : ?>
110 <a class="upk-alert-close" data-upk-close></a>
111 <?php endif; ?>
112 <?php echo wp_kses_post( $message ); ?>
113 </div>
114 <?php
115 }
116
117 function ultimate_post_kit_get_alert( $message, $type = 'warning', $close = true ) {
118
119 $output = '<div class="upk-alert-' . $type . '" upk-alert>';
120 if ( $close ) :
121 $output .= '<a class="upk-alert-close" data-upk-close></a>';
122 endif;
123 $output .= wp_kses_post( $message );
124 $output .= '</div>';
125
126 return $output;
127 }
128
129 /**
130 * all array css classes will output as proper space
131 *
132 * @param array $classes shortcode css class as array
133 *
134 * @return array string
135 */
136
137 function ultimate_post_kit_get_post_types( $args = [] ) {
138
139 $post_type_args = [
140 'show_in_nav_menus' => true,
141 ];
142
143 if ( ! empty( $args['post_type'] ) ) {
144 $post_type_args['name'] = $args['post_type'];
145 }
146
147 $_post_types = get_post_types( $post_type_args, 'objects' );
148
149 $post_types = [ '0' => esc_html__( 'Select Type', 'ultimate-post-kit' ) ];
150
151 foreach ( $_post_types as $post_type => $object ) {
152 $post_types[ $post_type ] = $object->label;
153 }
154
155 return $post_types;
156 }
157
158 function ultimate_post_kit_get_taxonomies() {
159 $args = array(
160 'public' => true,
161 //'_builtin' => false
162
163 );
164 $output = [ '0' => esc_html__( 'Select Type', 'ultimate-post-kit' ) ];
165 $tax_output = 'objects'; // or objects
166 $taxonomies = get_taxonomies( $args, $tax_output );
167 if ( $taxonomies ) {
168 foreach ( $taxonomies as $taxonomy ) {
169 $taxonomy_label = $taxonomy->label ? $taxonomy->label : $taxonomy->name;
170 $term_count = wp_count_terms(
171 [
172 'taxonomy' => $taxonomy->name,
173 'hide_empty' => false,
174 ]
175 );
176
177 if ( is_wp_error( $term_count ) ) {
178 $term_count = 0;
179 }
180
181 $output[ $taxonomy->name ] = sprintf(
182 '%s (%d)',
183 $taxonomy_label,
184 (int) $term_count
185 );
186 }
187 }
188
189 return $output;
190 }
191
192 function upk_get_category( $post_type ) {
193 switch ( $post_type ) {
194 case 'campaign':
195 $taxonomy = 'campaign_category';
196 break;
197 case 'lightbox_library':
198 $taxonomy = 'ngg_tag';
199 break;
200 case 'give_forms':
201 $taxonomy = 'give_forms_category';
202 break;
203 case 'tribe_events':
204 $taxonomy = 'tribe_events_cat';
205 break;
206 case 'product':
207 $taxonomy = 'product_cat';
208 break;
209 default:
210 $taxonomy = 'category';
211 break;
212 }
213
214 $categories = get_the_terms( get_the_ID(), $taxonomy );
215 $_categories = [];
216 if ( $categories && !is_wp_error( $categories ) ) {
217 foreach ( $categories as $category ) {
218 // Ensure $category is an object, not an array
219 if ( is_object( $category ) && isset( $category->term_id, $category->name, $category->slug ) ) {
220 $link = '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '"
221 aria-label="' . esc_attr( 'Category ' . $category->name ) . '">'
222 . esc_html( $category->name ) .
223 '</a>';
224
225 $_categories[ $category->slug ] = $link;
226 }
227 }
228 }
229 return implode( ' ', $_categories );
230 }
231
232
233 function ultimate_post_kit_allow_tags( ?string $tag = null ) {
234 $tag_allowed = wp_kses_allowed_html( 'post' );
235
236 $tag_allowed['input'] = [
237 'class' => [],
238 'id' => [],
239 'name' => [],
240 'value' => [],
241 'checked' => [],
242 'type' => [],
243 ];
244 $tag_allowed['select'] = [
245 'class' => [],
246 'id' => [],
247 'name' => [],
248 'value' => [],
249 'multiple' => [],
250 'type' => [],
251 ];
252 $tag_allowed['option'] = [
253 'value' => [],
254 'selected' => [],
255 ];
256
257 $tag_allowed['title'] = [
258 'a' => [
259 'href' => [],
260 'title' => [],
261 'class' => [],
262 ],
263 'br' => [],
264 'em' => [],
265 'strong' => [],
266 'hr' => [],
267 ];
268
269 $tag_allowed['text'] = [
270 'a' => [
271 'href' => [],
272 'title' => [],
273 'class' => [],
274 ],
275 'br' => [],
276 'em' => [],
277 'strong' => [],
278 'hr' => [],
279 'i' => [
280 'class' => [],
281 ],
282 'span' => [
283 'class' => [],
284 ],
285 ];
286
287 $tag_allowed['svg'] = [
288 'svg' => [
289 'version' => [],
290 'xmlns' => [],
291 'viewbox' => [],
292 'xml:space' => [],
293 'xmlns:xlink' => [],
294 'x' => [],
295 'y' => [],
296 'style' => [],
297 ],
298 'g' => [],
299 'path' => [
300 'class' => [],
301 'd' => [],
302 ],
303 'ellipse' => [
304 'class' => [],
305 'cx' => [],
306 'cy' => [],
307 'rx' => [],
308 'ry' => [],
309 ],
310 'circle' => [
311 'class' => [],
312 'cx' => [],
313 'cy' => [],
314 'r' => [],
315 ],
316 'rect' => [
317 'x' => [],
318 'y' => [],
319 'transform' => [],
320 'height' => [],
321 'width' => [],
322 'class' => [],
323 ],
324 'line' => [
325 'class' => [],
326 'x1' => [],
327 'x2' => [],
328 'y1' => [],
329 'y2' => [],
330 ],
331 'style' => [],
332
333
334 ];
335
336 if ( $tag == null ) {
337 return $tag_allowed;
338 } elseif ( is_array( $tag ) ) {
339 $new_tag_allow = [];
340
341 foreach ( $tag as $_tag ) {
342 $new_tag_allow[ $_tag ] = $tag_allowed[ $_tag ];
343 }
344
345 return $new_tag_allow;
346 } else {
347 return isset( $tag_allowed[ $tag ] ) ? $tag_allowed[ $tag ] : [];
348 }
349 }
350
351 /**
352 * HexColor
353 */
354 function strToHex( $string, $steps = -10 ) {
355
356 if ( empty( $string ) ) {
357 return false;
358 }
359
360 $hex_output = sprintf( '%s', substr( md5( $string ), 0, 6 ) );
361
362 // Steps should be between -255 and 255. Negative = darker, positive = lighter
363 $steps = max( -255, min( 255, $steps ) );
364
365 // Split into three parts: R, G and B
366 $color_parts = str_split( $hex_output, 2 );
367 $output = '#';
368
369 foreach ( $color_parts as $color ) {
370 $color = hexdec( $color ); // Convert to decimal
371 $color = max( 0, min( 255, $color + $steps ) ); // Adjust color
372 $output .= str_pad( dechex( $color ), 2, '0', STR_PAD_LEFT ); // Make two char hex code
373 }
374
375 return strToUpper( $output );
376 }
377
378 function ultimate_post_kit_post_pagination( $wp_query, $widget_id = '' ) {
379
380 /** Stop execution if there's only 1 page */
381 if ( $wp_query->max_num_pages <= 1 ) {
382 return;
383 }
384
385 // Get current page from multiple sources for reliability
386 $paged_from_query = isset( $wp_query->query_vars['paged'] ) ? $wp_query->query_vars['paged'] : 0;
387 $page_from_query = isset( $wp_query->query_vars['page'] ) ? $wp_query->query_vars['page'] : 0;
388
389 if ( is_front_page() ) {
390 // On front page, WordPress can use either 'page' or 'paged' depending on permalink structure
391 $paged = max( get_query_var( 'page' ), get_query_var( 'paged' ), $paged_from_query, $page_from_query );
392 $paged = $paged ? $paged : 1;
393 $page_var = 'page';
394 } else {
395 $paged = max( get_query_var( 'paged' ), $paged_from_query );
396 $paged = $paged ? $paged : 1;
397 $page_var = 'paged';
398 }
399
400 $max = intval( $wp_query->max_num_pages );
401
402 /** Add current page to the array */
403 if ( $paged >= 1 ) {
404 $links[] = $paged;
405 }
406
407 /** Add the pages around the current page to the array */
408 if ( $paged >= 3 ) {
409 $links[] = $paged - 1;
410 $links[] = $paged - 2;
411 }
412
413 if ( ( $paged + 2 ) <= $max ) {
414 $links[] = $paged + 2;
415 $links[] = $paged + 1;
416 }
417
418 printf( '<ul class="upk-pagination" data-widget-id="%s">' . "\n", esc_attr($widget_id) );
419
420 /** Previous Post Link */
421 if ( $paged > 1 ) {
422 $prev_page = $paged - 1;
423 if ( is_front_page() && $prev_page == 1 ) {
424 $prev_link = home_url( '/' );
425 } else {
426 $prev_link = get_pagenum_link( $prev_page );
427 }
428 printf( '<li class="upk-pagination-previous"><a href="%s" aria-label="' . esc_attr__( 'Previous Page', 'ultimate-post-kit' ) . '"><span data-upk-pagination-previous><i class="upk-icon-arrow-left-5" aria-hidden="true"></i></span></a></li>' . "\n", esc_url( $prev_link ) );
429 }
430
431 /** Link to first page, plus ellipses if necessary */
432 if ( ! in_array( 1, $links ) ) {
433 $class = 1 == $paged ? ' class="current"' : '';
434
435 // For page 1, always use home URL on front page, otherwise use get_pagenum_link
436 if ( is_front_page() ) {
437 $page_link = home_url( '/' );
438 } else {
439 $page_link = get_pagenum_link( 1 );
440 }
441
442 printf( '<li%s><a href="%s">%s</a></li>' . "\n", wp_kses_post($class), esc_url( $page_link ), '1' );
443
444 if ( ! in_array( 2, $links ) ) {
445 echo '<li class="upk-pagination-dot-dot"><span>...</span></li>';
446 }
447 }
448
449 /** Link to current page, plus 2 pages in either direction if necessary */
450 sort( $links );
451 foreach ( (array) $links as $link ) {
452 $class = $paged == $link ? ' class="upk-active"' : '';
453
454 // Use appropriate page link for front page vs other pages
455 if ( is_front_page() && $link == 1 ) {
456 $page_link = home_url( '/' );
457 } else {
458 $page_link = get_pagenum_link( $link );
459 }
460
461 printf( '<li%s><a href="%s">%s</a></li>' . "\n", wp_kses_post($class), esc_url( $page_link ), wp_kses_post($link) );
462 }
463
464 /** Link to last page, plus ellipses if necessary */
465 if ( ! in_array( $max, $links ) ) {
466 if ( ! in_array( $max - 1, $links ) ) {
467 echo '<li class="upk-pagination-dot-dot"><span>...</span></li>' . "\n";
468 }
469
470 $class = $paged == $max ? ' class="upk-active"' : '';
471 $page_link = get_pagenum_link( $max );
472
473 printf( '<li%s><a href="%s">%s</a></li>' . "\n", wp_kses_post($class), esc_url( $page_link ), wp_kses_post($max) );
474 }
475
476 /** Next Post Link */
477 if ( $paged < $max ) {
478 $next_page = $paged + 1;
479 $next_link = get_pagenum_link( $next_page );
480 printf( '<li class="upk-pagination-next"><a href="%s" aria-label="' . esc_attr__( 'Next Page', 'ultimate-post-kit' ) . '"><span data-upk-pagination-next><i class="upk-icon-arrow-right-5" aria-hidden="true"></i></span></a></li>' . "\n", esc_url( $next_link ) );
481 }
482
483 echo '</ul>' . "\n";
484 }
485
486 function ultimate_post_kit_template_edit_link( $template_id ) {
487 if ( Ultimate_Post_Kit_Loader::elementor()->editor->is_edit_mode() ) {
488
489 $final_url = add_query_arg( [ 'elementor' => '' ], get_permalink( $template_id ) );
490
491 $output = sprintf( '<a class="upk-elementor-template-edit-link" href="%s" title="%s" target="_blank"><i class="eicon-edit"></i></a>', esc_url( $final_url ), esc_html__( 'Edit Template', 'ultimate-post-kit' ) );
492
493 return $output;
494 }
495 }
496
497 function ultimate_post_kit_time_diff( $from, $to = '' ) {
498 $diff = human_time_diff( $from, $to );
499 $replace = array(
500 ' hour' => 'h',
501 ' hours' => 'h',
502 ' day' => 'd',
503 ' days' => 'd',
504 ' minute' => 'm',
505 ' minutes' => 'm',
506 ' second' => 's',
507 ' seconds' => 's',
508 );
509
510 return strtr( $diff, $replace );
511 }
512
513 function ultimate_post_kit_post_time_diff( $format = '' ) {
514 $displayAgo = esc_html__( 'ago', 'ultimate-post-kit' );
515 $post_time = get_the_time( 'U' );
516 $current_time = current_time( 'timestamp' );
517
518 if ( $format == 'short' ) {
519 $output = ultimate_post_kit_time_diff( $post_time, $current_time );
520 } else {
521 $output = human_time_diff( $post_time, $current_time );
522 }
523
524 $output = $output . ' ' . $displayAgo;
525
526 return $output;
527 }
528
529 function ultimate_post_kit_iso_time( $time ) {
530 $current_offset = (float) get_option( 'gmt_offset' );
531 $timezone_string = get_option( 'timezone_string' );
532
533 // Create a UTC+- zone if no timezone string exists.
534 //if ( empty( $timezone_string ) ) {
535 if ( 0 === $current_offset ) {
536 $timezone_string = '+00:00';
537 } elseif ( $current_offset < 0 ) {
538 $timezone_string = $current_offset . ':00';
539 } else {
540 $timezone_string = '+0' . $current_offset . ':00';
541 }
542 //}
543
544 $sub_time = [];
545 $sub_time = explode( " ", $time );
546 $final_time = $sub_time[0] . 'T' . $sub_time[1] . ':00' . $timezone_string;
547
548 return $final_time;
549 }
550
551 /**
552 * @return array
553 */
554 function ultimate_post_kit_get_menu() {
555
556 $menus = wp_get_nav_menus();
557 $items = [ 0 => esc_html__( 'Select Menu', 'ultimate-post-kit' ) ];
558 foreach ( $menus as $menu ) {
559 $items[ $menu->slug ] = $menu->name;
560 }
561
562 return $items;
563 }
564
565 /**
566 * default get_option() default value check
567 *
568 * @param string $option settings field name
569 * @param string $section the section name this field belongs to
570 * @param string $default default text if it's not found
571 *
572 * @return mixed
573 */
574 function ultimate_post_kit_option( $option, $section, $default = '' ) {
575
576 $options = get_option( $section );
577
578 if ( isset( $options[ $option ] ) ) {
579 return $options[ $option ];
580 }
581
582 return $default;
583 }
584
585 /**
586 * @return array of elementor template
587 */
588 function ultimate_post_kit_et_options() {
589
590 $templates = Ultimate_Post_Kit_Loader::elementor()->templates_manager->get_source( 'local' )->get_items();
591 $types = [];
592
593 if ( empty( $templates ) ) {
594 $template_options = [ '0' => __( 'Template Not Found!', 'ultimate-post-kit' ) ];
595 } else {
596 $template_options = [ '0' => __( 'Select Template', 'ultimate-post-kit' ) ];
597
598 foreach ( $templates as $template ) {
599 $template_options[ $template['template_id'] ] = $template['title'] . ' (' . $template['type'] . ')';
600 $types[ $template['template_id'] ] = $template['type'];
601 }
602 }
603
604 return $template_options;
605 }
606
607 /**
608 * @return array of wp default sidebars
609 */
610 function ultimate_post_kit_sidebar_options() {
611
612 global $wp_registered_sidebars;
613 $sidebar_options = [];
614
615 if ( ! $wp_registered_sidebars ) {
616 $sidebar_options[0] = esc_html__( 'No sidebars were found', 'ultimate-post-kit' );
617 } else {
618 $sidebar_options[0] = esc_html__( 'Select Sidebar', 'ultimate-post-kit' );
619
620 foreach ( $wp_registered_sidebars as $sidebar_id => $sidebar ) {
621 $sidebar_options[ $sidebar_id ] = $sidebar['name'];
622 }
623 }
624
625 return $sidebar_options;
626 }
627
628 /**
629 * @param string category name
630 *
631 * @return array of category
632 */
633 function ultimate_post_kit_get_category( $taxonomy = 'category' ) {
634
635 $post_options = [];
636
637 $post_categories = get_terms(
638 [
639 'taxonomy' => $taxonomy,
640 'hide_empty' => false,
641 ]
642 );
643
644 if ( is_wp_error( $post_categories ) ) {
645 return $post_options;
646 }
647
648 if ( false !== $post_categories and is_array( $post_categories ) ) {
649 foreach ( $post_categories as $category ) {
650 // Ensure $category is an object, not an array
651 if ( is_object( $category ) && isset( $category->slug, $category->name ) ) {
652 $post_options[ $category->slug ] = $category->name;
653 }
654 }
655 }
656
657 return $post_options;
658 }
659
660 /**
661 * @param array all ajax posted array there
662 *
663 * @return array return all setting as array
664 */
665 function ultimate_post_kit_ajax_settings( $settings ) {
666
667 $required_settings = [
668 'show_date' => true,
669 'show_comment' => true,
670 'show_link' => true,
671 'show_meta' => true,
672 'show_title' => true,
673 'show_excerpt' => true,
674 'show_lightbox' => true,
675 'show_thumbnail' => true,
676 'show_category' => false,
677 'show_tags' => false,
678 ];
679
680 foreach ( $settings as $key => $value ) {
681 if ( in_array( $key, $required_settings ) ) {
682 $required_settings[ $key ] = $value;
683 }
684 }
685
686 return $required_settings;
687 }
688
689 // BDT Blend Type
690 function ultimate_post_kit_blend_options() {
691 $blend_options = [
692 'multiply' => esc_html__( 'Multiply', 'ultimate-post-kit' ),
693 'screen' => esc_html__( 'Screen', 'ultimate-post-kit' ),
694 'overlay' => esc_html__( 'Overlay', 'ultimate-post-kit' ),
695 'darken' => esc_html__( 'Darken', 'ultimate-post-kit' ),
696 'lighten' => esc_html__( 'Lighten', 'ultimate-post-kit' ),
697 'color-dodge' => esc_html__( 'Color-Dodge', 'ultimate-post-kit' ),
698 'color-burn' => esc_html__( 'Color-Burn', 'ultimate-post-kit' ),
699 'hard-light' => esc_html__( 'Hard-Light', 'ultimate-post-kit' ),
700 'soft-light' => esc_html__( 'Soft-Light', 'ultimate-post-kit' ),
701 'difference' => esc_html__( 'Difference', 'ultimate-post-kit' ),
702 'exclusion' => esc_html__( 'Exclusion', 'ultimate-post-kit' ),
703 'hue' => esc_html__( 'Hue', 'ultimate-post-kit' ),
704 'saturation' => esc_html__( 'Saturation', 'ultimate-post-kit' ),
705 'color' => esc_html__( 'Color', 'ultimate-post-kit' ),
706 'luminosity' => esc_html__( 'Luminosity', 'ultimate-post-kit' ),
707 ];
708
709 return $blend_options;
710 }
711
712 // BDT Position
713 function ultimate_post_kit_position() {
714 $position_options = [
715 '' => esc_html__( 'Default', 'ultimate-post-kit' ),
716 'top-left' => esc_html__( 'Top Left', 'ultimate-post-kit' ),
717 'top-center' => esc_html__( 'Top Center', 'ultimate-post-kit' ),
718 'top-right' => esc_html__( 'Top Right', 'ultimate-post-kit' ),
719 'center' => esc_html__( 'Center', 'ultimate-post-kit' ),
720 'center-left' => esc_html__( 'Center Left', 'ultimate-post-kit' ),
721 'center-right' => esc_html__( 'Center Right', 'ultimate-post-kit' ),
722 'bottom-left' => esc_html__( 'Bottom Left', 'ultimate-post-kit' ),
723 'bottom-center' => esc_html__( 'Bottom Center', 'ultimate-post-kit' ),
724 'bottom-right' => esc_html__( 'Bottom Right', 'ultimate-post-kit' ),
725 ];
726
727 return $position_options;
728 }
729
730 // BDT Thumbnavs Position
731 function ultimate_post_kit_thumbnavs_position() {
732 $position_options = [
733 'top-left' => esc_html__( 'Top Left', 'ultimate-post-kit' ),
734 'top-center' => esc_html__( 'Top Center', 'ultimate-post-kit' ),
735 'top-right' => esc_html__( 'Top Right', 'ultimate-post-kit' ),
736 'center-left' => esc_html__( 'Center Left', 'ultimate-post-kit' ),
737 'center-right' => esc_html__( 'Center Right', 'ultimate-post-kit' ),
738 'bottom-left' => esc_html__( 'Bottom Left', 'ultimate-post-kit' ),
739 'bottom-center' => esc_html__( 'Bottom Center', 'ultimate-post-kit' ),
740 'bottom-right' => esc_html__( 'Bottom Right', 'ultimate-post-kit' ),
741 ];
742
743 return $position_options;
744 }
745
746 function ultimate_post_kit_navigation_position() {
747 $position_options = [
748 'top-left' => esc_html__( 'Top Left', 'ultimate-post-kit' ),
749 'top-center' => esc_html__( 'Top Center', 'ultimate-post-kit' ),
750 'top-right' => esc_html__( 'Top Right', 'ultimate-post-kit' ),
751 'center' => esc_html__( 'Center', 'ultimate-post-kit' ),
752 'center-left' => esc_html__( 'Center Left', 'ultimate-post-kit' ),
753 'center-right' => esc_html__( 'Center Right', 'ultimate-post-kit' ),
754 'bottom-left' => esc_html__( 'Bottom Left', 'ultimate-post-kit' ),
755 'bottom-center' => esc_html__( 'Bottom Center', 'ultimate-post-kit' ),
756 'bottom-right' => esc_html__( 'Bottom Right', 'ultimate-post-kit' ),
757 ];
758
759 return $position_options;
760 }
761
762
763 function ultimate_post_kit_pagination_position() {
764 $position_options = [
765 'top-left' => esc_html__( 'Top Left', 'ultimate-post-kit' ),
766 'top-center' => esc_html__( 'Top Center', 'ultimate-post-kit' ),
767 'top-right' => esc_html__( 'Top Right', 'ultimate-post-kit' ),
768 'center-left' => esc_html__( 'Center Left', 'ultimate-post-kit' ),
769 'center-right' => esc_html__( 'Center Right', 'ultimate-post-kit' ),
770 'bottom-left' => esc_html__( 'Bottom Left', 'ultimate-post-kit' ),
771 'bottom-center' => esc_html__( 'Bottom Center', 'ultimate-post-kit' ),
772 'bottom-right' => esc_html__( 'Bottom Right', 'ultimate-post-kit' ),
773 ];
774
775 return $position_options;
776 }
777
778 // Title Tags
779 function ultimate_post_kit_title_tags() {
780 $title_tags = [
781 'h1' => 'H1',
782 'h2' => 'H2',
783 'h3' => 'H3',
784 'h4' => 'H4',
785 'h5' => 'H5',
786 'h6' => 'H6',
787 'div' => 'div',
788 'span' => 'span',
789 'p' => 'p',
790 ];
791
792 return $title_tags;
793 }
794 function ultimate_post_kit_hide_on_class( $selectors ) {
795 $element_hide_on = '';
796 if ( ! empty( $selectors ) ) {
797 foreach ( $selectors as $element ) {
798
799 if ( $element == 'desktop' ) {
800 $element_hide_on .= ' upk-desktop';
801 }
802 if ( $element == 'tablet' ) {
803 $element_hide_on .= ' upk-tablet';
804 }
805 if ( $element == 'mobile' ) {
806 $element_hide_on .= ' upk-mobile';
807 }
808 }
809 }
810 return $element_hide_on;
811 }
812 function ultimate_post_kit_mask_shapes() {
813 $path = BDTUPK_ASSETS_URL . 'images/mask/';
814 $shape_name = 'shape';
815 $extension = '.svg';
816 $list = [ 0 => esc_html__( 'Select Mask', 'ultimate-post-kit' ) ];
817
818 for ( $i = 1; $i <= 20; $i++ ) {
819 $list[ $path . $shape_name . '-' . $i . $extension ] = ucwords( $shape_name . ' ' . $i );
820 }
821
822 return $list;
823 }
824
825 /**
826 * String to ID maker for any title to relavent id
827 * @param [type] string any title or string
828 * @return [type] [description]
829 */
830 function ultimate_post_kit_string_id( $string ) {
831 //Lower case everything
832 $string = strtolower( $string );
833 //Make alphanumeric (removes all other characters)
834 $string = preg_replace( "/[^a-z0-9_\s-]/", "", $string );
835 //Clean up multiple dashes or whitespaces
836 $string = preg_replace( "/[\s-]+/", " ", $string );
837 //Convert whitespaces and underscore to dash
838 $string = preg_replace( "/[\s_]/", "-", $string );
839
840 //finally return here
841 return $string;
842 }
843
844
845 function ultimate_post_kit_dashboard_link( $suffix = '#welcome' ) {
846 return add_query_arg( [ 'page' => 'ultimate_post_kit_options' . $suffix ], admin_url( 'admin.php' ) );
847 }
848
849 /**
850 * @param int $limit default limit is 25 word
851 * @param bool $strip_shortcode if you want to strip shortcode from excert text
852 * @param string $trail trail string default is ...
853 *
854 * @return string return custom limited excerpt text
855 */
856 function ultimate_post_kit_custom_excerpt( $limit = 25, $strip_shortcode = false, $trail = '' ) {
857
858 $output = get_the_content();
859
860 if ( $limit ) {
861 $output = wp_trim_words( $output, $limit, $trail );
862 }
863
864 if ( $strip_shortcode ) {
865 $output = strip_shortcodes( $output );
866 }
867
868 return wpautop( $output );
869 }
870
871 function get_user_role( $id ) {
872
873 $user = new WP_User( $id );
874
875 return array_shift( $user->roles );
876 }
877
878
879 /**
880 * @param string $content return posts content
881 * @param int $avg_reading_speed average word reading speed per minute
882 * @param string $hide_seconds whether to hide seconds (yes/no)
883 * @param string $hide_minutes whether to hide minutes (yes/no)
884 *
885 * @return string return average reading time of specifiic posts.
886 */
887
888 if ( _is_upk_pro_activated() ) {
889 function ultimate_post_kit_reading_time( $content, $avg_reading_speed, $hide_seconds = 'no', $hide_minutes = 'no' ) {
890 $total_word = str_word_count( strip_tags( $content ) );
891 $reading_minute = floor( $total_word / $avg_reading_speed );
892 $reading_seconds = floor( $total_word % $avg_reading_speed / ( $avg_reading_speed / 60 ) );
893
894 $hide_seconds = ( $hide_seconds === 'yes' );
895 $hide_minutes = ( $hide_minutes === 'yes' );
896
897 // If hide_minutes is enabled, convert everything to seconds
898 if ( $hide_minutes ) {
899 $total_seconds = ( $reading_minute * 60 ) + $reading_seconds;
900 if ( $hide_seconds ) {
901 return '0 sec read';
902 }
903 return $total_seconds . ' sec read';
904 }
905
906 if ( $total_word >= $avg_reading_speed ) {
907 $parts = array();
908
909 if ( $reading_minute > 0 ) {
910 $parts[] = $reading_minute . ' min';
911 }
912
913 if ( ! $hide_seconds && $reading_seconds > 0 ) {
914 $parts[] = $reading_seconds . ' sec';
915 }
916
917 // If no parts and seconds are not hidden, show at least seconds
918 if ( empty( $parts ) ) {
919 if ( ! $hide_seconds ) {
920 $parts[] = $reading_seconds . ' sec';
921 } else {
922 $parts[] = $reading_minute . ' min';
923 }
924 }
925
926 return ! empty( $parts ) ? implode( ' ', $parts ) . ' read' : '0 sec read';
927 } else {
928 // For content less than reading speed, show seconds unless hidden
929 if ( $hide_seconds ) {
930 return '0 min read';
931 }
932 return $reading_seconds . ' sec read';
933 }
934 }
935 }
936
937
938 /**
939 * License Validation
940 */
941 if ( ! function_exists( 'upk_license_validation' ) ) {
942 function upk_license_validation() {
943
944 if ( function_exists( '_is_upk_pro_activated' ) && false === _is_upk_pro_activated() ) {
945 return false;
946 }
947
948 $license_key = trim( get_option( 'ultimate_post_kit_license_key' ) );
949
950 if ( isset( $license_key ) && ! empty( $license_key ) ) {
951 return true;
952 }
953
954 return false;
955 }
956 }
957
958 /**
959 * Inject custom CSS and JS into the header
960 */
961 if ( ! function_exists( 'upk_inject_header_custom_code' ) ) {
962 function upk_inject_header_custom_code() {
963 if ( upk_is_page_excluded() ) {
964 return;
965 }
966
967 $custom_css = get_option( 'upk_custom_css', '' );
968 $custom_js = get_option( 'upk_custom_js', '' );
969
970 if ( ! empty( $custom_css ) ) {
971 echo "\n<!-- Ultimate Post Kit Custom Header CSS -->\n";
972 echo '<style type="text/css">' . "\n";
973 echo $custom_css . "\n";
974 echo '</style>' . "\n";
975 }
976
977 if ( ! empty( $custom_js ) ) {
978 echo "\n<!-- Ultimate Post Kit Custom Header JS -->\n";
979 echo '<script type="text/javascript">' . "\n";
980 echo $custom_js . "\n";
981 echo '</script>' . "\n";
982 }
983 }
984 }
985
986 /**
987 * Inject custom CSS and JS into the footer
988 */
989 if ( ! function_exists( 'upk_inject_footer_custom_code' ) ) {
990 function upk_inject_footer_custom_code() {
991 if ( upk_is_page_excluded() ) {
992 return;
993 }
994
995 $custom_css_2 = get_option( 'upk_custom_css_2', '' );
996 $custom_js_2 = get_option( 'upk_custom_js_2', '' );
997
998 if ( ! empty( $custom_css_2 ) ) {
999 echo "\n<!-- Ultimate Post Kit Custom Footer CSS -->\n";
1000 echo '<style type="text/css">' . "\n";
1001 echo $custom_css_2 . "\n";
1002 echo '</style>' . "\n";
1003 }
1004
1005 if ( ! empty( $custom_js_2 ) ) {
1006 echo "\n<!-- Ultimate Post Kit Custom Footer JS -->\n";
1007 echo '<script type="text/javascript">' . "\n";
1008 echo $custom_js_2 . "\n";
1009 echo '</script>' . "\n";
1010 }
1011 }
1012 }
1013
1014 /**
1015 * Check if current page should be excluded from custom code injection
1016 */
1017 if ( ! function_exists( 'upk_is_page_excluded' ) ) {
1018 function upk_is_page_excluded() {
1019 $excluded_pages = get_option( 'upk_excluded_pages', array() );
1020
1021 if ( empty( $excluded_pages ) || ! is_array( $excluded_pages ) ) {
1022 return false;
1023 }
1024
1025 $current_id = 0;
1026
1027 if ( is_home() && ! is_front_page() ) {
1028 $current_id = get_option( 'page_for_posts' );
1029 } elseif ( is_front_page() ) {
1030 $current_id = get_option( 'page_on_front' );
1031 } elseif ( is_singular() ) {
1032 $current_id = get_queried_object_id();
1033 } elseif ( is_category() || is_tag() || is_tax() ) {
1034 return false;
1035 } elseif ( is_author() ) {
1036 return false;
1037 } elseif ( is_archive() ) {
1038 return false;
1039 }
1040
1041 return in_array( $current_id, $excluded_pages );
1042 }
1043 }
1044