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

1,055 lines 29.3 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 // Filter to override WordPress posts_per_page for Builder pages
515 add_action('pre_get_posts', 'ultimate_post_kit_override_posts_per_page_for_builder');
516
517 function ultimate_post_kit_override_posts_per_page_for_builder($query) {
518 // Only affect main query
519 if (!$query->is_main_query()) {
520 return;
521 }
522
523 // Check if we have pagination in URL
524 $paged = max(1, get_query_var('paged'), get_query_var('page'));
525
526 // Only apply override on paginated pages (page > 1)
527 if ($paged <= 1) {
528 return;
529 }
530
531 $post_id = get_queried_object_id();
532
533 if ($post_id && function_exists('get_post_meta')) {
534 // Set posts_per_page to -1 to show all posts and avoid pagination conflicts
535 $query->set('posts_per_page', -1);
536 $query->set('nopaging', true);
537 }
538 }
539
540 function ultimate_post_kit_iso_time( $time ) {
541 $current_offset = (float) get_option( 'gmt_offset' );
542 $timezone_string = get_option( 'timezone_string' );
543
544 // Create a UTC+- zone if no timezone string exists.
545 //if ( empty( $timezone_string ) ) {
546 if ( 0 === $current_offset ) {
547 $timezone_string = '+00:00';
548 } elseif ( $current_offset < 0 ) {
549 $timezone_string = $current_offset . ':00';
550 } else {
551 $timezone_string = '+0' . $current_offset . ':00';
552 }
553 //}
554
555 $sub_time = [];
556 $sub_time = explode( " ", $time );
557 $final_time = $sub_time[0] . 'T' . $sub_time[1] . ':00' . $timezone_string;
558
559 return $final_time;
560 }
561
562 /**
563 * @return array
564 */
565 function ultimate_post_kit_get_menu() {
566
567 $menus = wp_get_nav_menus();
568 $items = [ 0 => esc_html__( 'Select Menu', 'ultimate-post-kit' ) ];
569 foreach ( $menus as $menu ) {
570 $items[ $menu->slug ] = $menu->name;
571 }
572
573 return $items;
574 }
575
576 /**
577 * default get_option() default value check
578 *
579 * @param string $option settings field name
580 * @param string $section the section name this field belongs to
581 * @param string $default default text if it's not found
582 *
583 * @return mixed
584 */
585 function ultimate_post_kit_option( $option, $section, $default = '' ) {
586
587 $options = get_option( $section );
588
589 if ( isset( $options[ $option ] ) ) {
590 return $options[ $option ];
591 }
592
593 return $default;
594 }
595
596 /**
597 * @return array of elementor template
598 */
599 function ultimate_post_kit_et_options() {
600
601 $templates = Ultimate_Post_Kit_Loader::elementor()->templates_manager->get_source( 'local' )->get_items();
602 $types = [];
603
604 if ( empty( $templates ) ) {
605 $template_options = [ '0' => __( 'Template Not Found!', 'ultimate-post-kit' ) ];
606 } else {
607 $template_options = [ '0' => __( 'Select Template', 'ultimate-post-kit' ) ];
608
609 foreach ( $templates as $template ) {
610 $template_options[ $template['template_id'] ] = $template['title'] . ' (' . $template['type'] . ')';
611 $types[ $template['template_id'] ] = $template['type'];
612 }
613 }
614
615 return $template_options;
616 }
617
618 /**
619 * @return array of wp default sidebars
620 */
621 function ultimate_post_kit_sidebar_options() {
622
623 global $wp_registered_sidebars;
624 $sidebar_options = [];
625
626 if ( ! $wp_registered_sidebars ) {
627 $sidebar_options[0] = esc_html__( 'No sidebars were found', 'ultimate-post-kit' );
628 } else {
629 $sidebar_options[0] = esc_html__( 'Select Sidebar', 'ultimate-post-kit' );
630
631 foreach ( $wp_registered_sidebars as $sidebar_id => $sidebar ) {
632 $sidebar_options[ $sidebar_id ] = $sidebar['name'];
633 }
634 }
635
636 return $sidebar_options;
637 }
638
639 /**
640 * @param string category name
641 *
642 * @return array of category
643 */
644 function ultimate_post_kit_get_category( $taxonomy = 'category' ) {
645
646 $post_options = [];
647
648 $post_categories = get_terms(
649 [
650 'taxonomy' => $taxonomy,
651 'hide_empty' => false,
652 ]
653 );
654
655 if ( is_wp_error( $post_categories ) ) {
656 return $post_options;
657 }
658
659 if ( false !== $post_categories and is_array( $post_categories ) ) {
660 foreach ( $post_categories as $category ) {
661 // Ensure $category is an object, not an array
662 if ( is_object( $category ) && isset( $category->slug, $category->name ) ) {
663 $post_options[ $category->slug ] = $category->name;
664 }
665 }
666 }
667
668 return $post_options;
669 }
670
671 /**
672 * @param array all ajax posted array there
673 *
674 * @return array return all setting as array
675 */
676 function ultimate_post_kit_ajax_settings( $settings ) {
677
678 $required_settings = [
679 'show_date' => true,
680 'show_comment' => true,
681 'show_link' => true,
682 'show_meta' => true,
683 'show_title' => true,
684 'show_excerpt' => true,
685 'show_lightbox' => true,
686 'show_thumbnail' => true,
687 'show_category' => false,
688 'show_tags' => false,
689 ];
690
691 foreach ( $settings as $key => $value ) {
692 if ( in_array( $key, $required_settings ) ) {
693 $required_settings[ $key ] = $value;
694 }
695 }
696
697 return $required_settings;
698 }
699
700 // BDT Blend Type
701 function ultimate_post_kit_blend_options() {
702 $blend_options = [
703 'multiply' => esc_html__( 'Multiply', 'ultimate-post-kit' ),
704 'screen' => esc_html__( 'Screen', 'ultimate-post-kit' ),
705 'overlay' => esc_html__( 'Overlay', 'ultimate-post-kit' ),
706 'darken' => esc_html__( 'Darken', 'ultimate-post-kit' ),
707 'lighten' => esc_html__( 'Lighten', 'ultimate-post-kit' ),
708 'color-dodge' => esc_html__( 'Color-Dodge', 'ultimate-post-kit' ),
709 'color-burn' => esc_html__( 'Color-Burn', 'ultimate-post-kit' ),
710 'hard-light' => esc_html__( 'Hard-Light', 'ultimate-post-kit' ),
711 'soft-light' => esc_html__( 'Soft-Light', 'ultimate-post-kit' ),
712 'difference' => esc_html__( 'Difference', 'ultimate-post-kit' ),
713 'exclusion' => esc_html__( 'Exclusion', 'ultimate-post-kit' ),
714 'hue' => esc_html__( 'Hue', 'ultimate-post-kit' ),
715 'saturation' => esc_html__( 'Saturation', 'ultimate-post-kit' ),
716 'color' => esc_html__( 'Color', 'ultimate-post-kit' ),
717 'luminosity' => esc_html__( 'Luminosity', 'ultimate-post-kit' ),
718 ];
719
720 return $blend_options;
721 }
722
723 // BDT Position
724 function ultimate_post_kit_position() {
725 $position_options = [
726 '' => esc_html__( 'Default', 'ultimate-post-kit' ),
727 'top-left' => esc_html__( 'Top Left', 'ultimate-post-kit' ),
728 'top-center' => esc_html__( 'Top Center', 'ultimate-post-kit' ),
729 'top-right' => esc_html__( 'Top Right', 'ultimate-post-kit' ),
730 'center' => esc_html__( 'Center', 'ultimate-post-kit' ),
731 'center-left' => esc_html__( 'Center Left', 'ultimate-post-kit' ),
732 'center-right' => esc_html__( 'Center Right', 'ultimate-post-kit' ),
733 'bottom-left' => esc_html__( 'Bottom Left', 'ultimate-post-kit' ),
734 'bottom-center' => esc_html__( 'Bottom Center', 'ultimate-post-kit' ),
735 'bottom-right' => esc_html__( 'Bottom Right', 'ultimate-post-kit' ),
736 ];
737
738 return $position_options;
739 }
740
741 // BDT Thumbnavs Position
742 function ultimate_post_kit_thumbnavs_position() {
743 $position_options = [
744 'top-left' => esc_html__( 'Top Left', 'ultimate-post-kit' ),
745 'top-center' => esc_html__( 'Top Center', 'ultimate-post-kit' ),
746 'top-right' => esc_html__( 'Top Right', 'ultimate-post-kit' ),
747 'center-left' => esc_html__( 'Center Left', 'ultimate-post-kit' ),
748 'center-right' => esc_html__( 'Center Right', 'ultimate-post-kit' ),
749 'bottom-left' => esc_html__( 'Bottom Left', 'ultimate-post-kit' ),
750 'bottom-center' => esc_html__( 'Bottom Center', 'ultimate-post-kit' ),
751 'bottom-right' => esc_html__( 'Bottom Right', 'ultimate-post-kit' ),
752 ];
753
754 return $position_options;
755 }
756
757 function ultimate_post_kit_navigation_position() {
758 $position_options = [
759 'top-left' => esc_html__( 'Top Left', 'ultimate-post-kit' ),
760 'top-center' => esc_html__( 'Top Center', 'ultimate-post-kit' ),
761 'top-right' => esc_html__( 'Top Right', 'ultimate-post-kit' ),
762 'center' => esc_html__( 'Center', 'ultimate-post-kit' ),
763 'center-left' => esc_html__( 'Center Left', 'ultimate-post-kit' ),
764 'center-right' => esc_html__( 'Center Right', 'ultimate-post-kit' ),
765 'bottom-left' => esc_html__( 'Bottom Left', 'ultimate-post-kit' ),
766 'bottom-center' => esc_html__( 'Bottom Center', 'ultimate-post-kit' ),
767 'bottom-right' => esc_html__( 'Bottom Right', 'ultimate-post-kit' ),
768 ];
769
770 return $position_options;
771 }
772
773
774 function ultimate_post_kit_pagination_position() {
775 $position_options = [
776 'top-left' => esc_html__( 'Top Left', 'ultimate-post-kit' ),
777 'top-center' => esc_html__( 'Top Center', 'ultimate-post-kit' ),
778 'top-right' => esc_html__( 'Top Right', 'ultimate-post-kit' ),
779 'center-left' => esc_html__( 'Center Left', 'ultimate-post-kit' ),
780 'center-right' => esc_html__( 'Center Right', 'ultimate-post-kit' ),
781 'bottom-left' => esc_html__( 'Bottom Left', 'ultimate-post-kit' ),
782 'bottom-center' => esc_html__( 'Bottom Center', 'ultimate-post-kit' ),
783 'bottom-right' => esc_html__( 'Bottom Right', 'ultimate-post-kit' ),
784 ];
785
786 return $position_options;
787 }
788
789 // Title Tags
790 function ultimate_post_kit_title_tags() {
791 $title_tags = [
792 'h1' => 'H1',
793 'h2' => 'H2',
794 'h3' => 'H3',
795 'h4' => 'H4',
796 'h5' => 'H5',
797 'h6' => 'H6',
798 'div' => 'div',
799 'span' => 'span',
800 'p' => 'p',
801 ];
802
803 return $title_tags;
804 }
805 function ultimate_post_kit_hide_on_class( $selectors ) {
806 $element_hide_on = '';
807 if ( ! empty( $selectors ) ) {
808 foreach ( $selectors as $element ) {
809
810 if ( $element == 'desktop' ) {
811 $element_hide_on .= ' upk-desktop';
812 }
813 if ( $element == 'tablet' ) {
814 $element_hide_on .= ' upk-tablet';
815 }
816 if ( $element == 'mobile' ) {
817 $element_hide_on .= ' upk-mobile';
818 }
819 }
820 }
821 return $element_hide_on;
822 }
823 function ultimate_post_kit_mask_shapes() {
824 $path = BDTUPK_ASSETS_URL . 'images/mask/';
825 $shape_name = 'shape';
826 $extension = '.svg';
827 $list = [ 0 => esc_html__( 'Select Mask', 'ultimate-post-kit' ) ];
828
829 for ( $i = 1; $i <= 20; $i++ ) {
830 $list[ $path . $shape_name . '-' . $i . $extension ] = ucwords( $shape_name . ' ' . $i );
831 }
832
833 return $list;
834 }
835
836 /**
837 * String to ID maker for any title to relavent id
838 * @param [type] string any title or string
839 * @return [type] [description]
840 */
841 function ultimate_post_kit_string_id( $string ) {
842 //Lower case everything
843 $string = strtolower( $string );
844 //Make alphanumeric (removes all other characters)
845 $string = preg_replace( "/[^a-z0-9_\s-]/", "", $string );
846 //Clean up multiple dashes or whitespaces
847 $string = preg_replace( "/[\s-]+/", " ", $string );
848 //Convert whitespaces and underscore to dash
849 $string = preg_replace( "/[\s_]/", "-", $string );
850
851 //finally return here
852 return $string;
853 }
854
855
856 function ultimate_post_kit_dashboard_link( $suffix = '#welcome' ) {
857 return add_query_arg( [ 'page' => 'ultimate_post_kit_options' . $suffix ], admin_url( 'admin.php' ) );
858 }
859
860 /**
861 * @param int $limit default limit is 25 word
862 * @param bool $strip_shortcode if you want to strip shortcode from excert text
863 * @param string $trail trail string default is ...
864 *
865 * @return string return custom limited excerpt text
866 */
867 function ultimate_post_kit_custom_excerpt( $limit = 25, $strip_shortcode = false, $trail = '' ) {
868
869 $output = get_the_content();
870
871 if ( $limit ) {
872 $output = wp_trim_words( $output, $limit, $trail );
873 }
874
875 if ( $strip_shortcode ) {
876 $output = strip_shortcodes( $output );
877 }
878
879 return wpautop( $output );
880 }
881
882 function get_user_role( $id ) {
883
884 $user = new WP_User( $id );
885
886 return array_shift( $user->roles );
887 }
888
889
890 /**
891 * @param string $content return posts content
892 * @param int $avg_reading_speed average word reading speed per minute
893 * @param string $hide_seconds whether to hide seconds (yes/no)
894 * @param string $hide_minutes whether to hide minutes (yes/no)
895 *
896 * @return string return average reading time of specifiic posts.
897 */
898
899 if ( _is_upk_pro_activated() ) {
900 function ultimate_post_kit_reading_time( $content, $avg_reading_speed, $hide_seconds = 'no', $hide_minutes = 'no' ) {
901 $total_word = str_word_count( strip_tags( $content ) );
902 $reading_minute = floor( $total_word / $avg_reading_speed );
903 $reading_seconds = floor( $total_word % $avg_reading_speed / ( $avg_reading_speed / 60 ) );
904
905 $hide_seconds = ( $hide_seconds === 'yes' );
906 $hide_minutes = ( $hide_minutes === 'yes' );
907
908 // If hide_minutes is enabled, convert everything to seconds
909 if ( $hide_minutes ) {
910 $total_seconds = ( $reading_minute * 60 ) + $reading_seconds;
911 if ( $hide_seconds ) {
912 return '0 sec read';
913 }
914 return $total_seconds . ' sec read';
915 }
916
917 if ( $total_word >= $avg_reading_speed ) {
918 $parts = array();
919
920 if ( $reading_minute > 0 ) {
921 $parts[] = $reading_minute . ' min';
922 }
923
924 if ( ! $hide_seconds && $reading_seconds > 0 ) {
925 $parts[] = $reading_seconds . ' sec';
926 }
927
928 // If no parts and seconds are not hidden, show at least seconds
929 if ( empty( $parts ) ) {
930 if ( ! $hide_seconds ) {
931 $parts[] = $reading_seconds . ' sec';
932 } else {
933 $parts[] = $reading_minute . ' min';
934 }
935 }
936
937 return ! empty( $parts ) ? implode( ' ', $parts ) . ' read' : '0 sec read';
938 } else {
939 // For content less than reading speed, show seconds unless hidden
940 if ( $hide_seconds ) {
941 return '0 min read';
942 }
943 return $reading_seconds . ' sec read';
944 }
945 }
946 }
947
948
949 /**
950 * License Validation
951 */
952 if ( ! function_exists( 'upk_license_validation' ) ) {
953 function upk_license_validation() {
954
955 if ( function_exists( '_is_upk_pro_activated' ) && false === _is_upk_pro_activated() ) {
956 return false;
957 }
958
959 $license_key = trim( get_option( 'ultimate_post_kit_license_key' ) );
960
961 if ( isset( $license_key ) && ! empty( $license_key ) ) {
962 return true;
963 }
964
965 return false;
966 }
967 }
968
969 /**
970 * Inject custom CSS and JS into the header
971 */
972 if ( ! function_exists( 'upk_inject_header_custom_code' ) ) {
973 function upk_inject_header_custom_code() {
974 if ( upk_is_page_excluded() ) {
975 return;
976 }
977
978 $custom_css = get_option( 'upk_custom_css', '' );
979 $custom_js = get_option( 'upk_custom_js', '' );
980
981 if ( ! empty( $custom_css ) ) {
982 echo "\n<!-- Ultimate Post Kit Custom Header CSS -->\n";
983 echo '<style type="text/css">' . "\n";
984 echo $custom_css . "\n";
985 echo '</style>' . "\n";
986 }
987
988 if ( ! empty( $custom_js ) ) {
989 echo "\n<!-- Ultimate Post Kit Custom Header JS -->\n";
990 echo '<script type="text/javascript">' . "\n";
991 echo $custom_js . "\n";
992 echo '</script>' . "\n";
993 }
994 }
995 }
996
997 /**
998 * Inject custom CSS and JS into the footer
999 */
1000 if ( ! function_exists( 'upk_inject_footer_custom_code' ) ) {
1001 function upk_inject_footer_custom_code() {
1002 if ( upk_is_page_excluded() ) {
1003 return;
1004 }
1005
1006 $custom_css_2 = get_option( 'upk_custom_css_2', '' );
1007 $custom_js_2 = get_option( 'upk_custom_js_2', '' );
1008
1009 if ( ! empty( $custom_css_2 ) ) {
1010 echo "\n<!-- Ultimate Post Kit Custom Footer CSS -->\n";
1011 echo '<style type="text/css">' . "\n";
1012 echo $custom_css_2 . "\n";
1013 echo '</style>' . "\n";
1014 }
1015
1016 if ( ! empty( $custom_js_2 ) ) {
1017 echo "\n<!-- Ultimate Post Kit Custom Footer JS -->\n";
1018 echo '<script type="text/javascript">' . "\n";
1019 echo $custom_js_2 . "\n";
1020 echo '</script>' . "\n";
1021 }
1022 }
1023 }
1024
1025 /**
1026 * Check if current page should be excluded from custom code injection
1027 */
1028 if ( ! function_exists( 'upk_is_page_excluded' ) ) {
1029 function upk_is_page_excluded() {
1030 $excluded_pages = get_option( 'upk_excluded_pages', array() );
1031
1032 if ( empty( $excluded_pages ) || ! is_array( $excluded_pages ) ) {
1033 return false;
1034 }
1035
1036 $current_id = 0;
1037
1038 if ( is_home() && ! is_front_page() ) {
1039 $current_id = get_option( 'page_for_posts' );
1040 } elseif ( is_front_page() ) {
1041 $current_id = get_option( 'page_on_front' );
1042 } elseif ( is_singular() ) {
1043 $current_id = get_queried_object_id();
1044 } elseif ( is_category() || is_tag() || is_tax() ) {
1045 return false;
1046 } elseif ( is_author() ) {
1047 return false;
1048 } elseif ( is_archive() ) {
1049 return false;
1050 }
1051
1052 return in_array( $current_id, $excluded_pages );
1053 }
1054 }
1055