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

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