PluginProbe
Ultimate Post Kit – Elementor Post Grid, Post Carousel, Post Slider & Blog Layout Widgets / 4.1.9
Ultimate Post Kit – Elementor Post Grid, Post Carousel, Post Slider & Blog Layout Widgets v4.1.9
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.9, at includes/helper.php

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