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

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