PluginProbe
Post Grid Gutenberg Blocks – PostX / 5.0.0
Post Grid Gutenberg Blocks – PostX v5.0.0
5.0.39 5.0.38 5.0.37 5.0.36 5.0.35 5.0.34 5.0.33 5.0.32 5.0.31 5.0.30 5.0.29 5.0.28 5.0.27 5.0.26 5.0.25 5.0.23 5.0.24 5.0.22 5.0.21 5.0.20 5.0.19 5.0.18 5.0.17 2.1.1 2.1.2 All 237 releases
ultimate-post / classes / Functions.php

Functions.php in Post Grid Gutenberg Blocks – PostX 5.0.0, at classes/Functions.php

2,942 lines 100.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Common Functions.
4 *
5 * @package ULTP\Functions
6 * @since v.1.0.0
7 */
8
9 namespace ULTP;
10
11 use ULTP\Includes\Durbin\Xpo;
12
13 defined( 'ABSPATH' ) || exit;
14
15 /**
16 * Functions class.
17 *
18 * Provides utility functions for Ultimate Post plugin.
19 *
20 * @package ULTP\Functions
21 * @since 4.0.0
22 */
23 class Functions {
24
25 /**
26 * Funtion
27 *
28 * @since v.3.2.4
29 *
30 * Instance of the class.
31 *
32 * @var Functions | null
33 */
34 private static $instance = null;
35
36 /**
37 * Setup class.
38 *
39 * @since v.1.0.0
40 */
41 public function __construct() {
42 }
43
44 /**
45 * Gets the instance of \ULTP\Functions class
46 *
47 * @return Functions
48 * @since v.3.2.4
49 */
50 public static function get_instance() {
51 if ( ! isset( $GLOBALS['ultp_settings'] ) ) {
52 $GLOBALS['ultp_settings'] = get_option( 'ultp_options' );
53 }
54
55 if ( is_null( self::$instance ) ) {
56 self::$instance = new self();
57 }
58
59 return self::$instance;
60 }
61
62 /**
63 * ID for the Builder Post or Normal Post
64 *
65 * @since v.2.3.1
66 * @return NUMBER | is Builder or not
67 */
68 public function get_ID() {
69 $id = $this->is_builder();
70 return $id ? $id : ( function_exists( 'is_shop' ) ? ( is_shop() ? wc_get_page_id( 'shop' ) : get_the_ID() ) : get_the_ID() );
71 }
72
73 /**
74 * Checking Statement of Dynamic Site Builder
75 *
76 * @since v.2.3.1
77 * @return BOOLEAN | is Builder or not
78 */
79 public function is_archive_builder() {
80 $id = get_the_ID();
81 return get_post_type( $id ) == 'ultp_builder' ? get_post_meta( $id, '__ultp_builder_type', true ) : false;
82 }
83
84 /**
85 * Set Link with the Parameters
86 *
87 * @since v.1.1.0
88 * @param string $url .
89 * @param string $tag .
90 * @return STRING | URL with Arg
91 */
92 public function get_premium_link( $url = null, $tag = '' ) {
93 return Xpo::generate_utm_link(
94 array(
95 'url' => $url,
96 'utmKey' => $tag,
97 )
98 );
99 }
100
101
102 /**
103 * Quick Query
104 *
105 * @since v.1.1.0
106 * @param ARRAY $prams Quick query parameters.
107 * @param ARRAY $args Query arguments to modify.
108 * @return ARRAY
109 */
110 public function get_quick_query( $prams, $args ) {
111 switch ( $prams['queryQuick'] ) {
112 case 'related_posts':
113 global $post;
114 $p_id = isset( $post->ID ) && $post->ID ? $post->ID : ( isset( $_POST['postId'] ) ? sanitize_text_field( $_POST['postId'] ) : '' ); //phpcs:disable WordPress.Security.NonceVerification.Missing
115 if ( $p_id ) {
116 $args['post__not_in'] = array( $p_id );
117 }
118 break;
119 case 'related_tag':
120 global $post;
121 $p_id = isset( $post->ID ) && $post->ID ? $post->ID : ( isset( $prams['current_post'] ) && $prams['current_post'] ? $prams['current_post'] : ( isset( $_POST['postId'] ) ? sanitize_text_field( $_POST['postId'] ) : '' ) ); //phpcs:disable ordPress.Security.NonceVerification.Missing
122 if ( $p_id ) {
123 $args['tax_query'] = array(
124 array(
125 'taxonomy' => 'post_tag',
126 'terms' => $this->get_terms_id( $p_id, 'post_tag' ),
127 'field' => 'term_id',
128 ),
129 );
130 $args['post__not_in'] = array( $p_id );
131 }
132 break;
133 case 'related_category':
134 global $post;
135 $p_id = isset( $post->ID ) && $post->ID ? $post->ID : ( isset( $prams['current_post'] ) && $prams['current_post'] ? $prams['current_post'] : ( isset( $_POST['postId'] ) ? sanitize_text_field( $_POST['postId'] ) : '' ) ); //phpcs:disable ordPress.Security.NonceVerification.Missing
136 if ( $p_id ) {
137 $args['tax_query'] = array(
138 array(
139 'taxonomy' => 'category',
140 'terms' => $this->get_terms_id( $p_id, 'category' ),
141 'field' => 'term_id',
142 ),
143 );
144 $args['post__not_in'] = array( $p_id );
145 }
146 break;
147 case 'related_cat_tag':
148 global $post;
149 $p_id = isset( $post->ID ) && $post->ID ? $post->ID : ( isset( $prams['current_post'] ) && $prams['current_post'] ? $prams['current_post'] : ( isset( $_POST['postId'] ) ? sanitize_text_field( $_POST['postId'] ) : '' ) ); //phpcs:disable ordPress.Security.NonceVerification.Missing
150 if ( $p_id ) {
151 $args['tax_query'] = array(
152 array(
153 'taxonomy' => 'post_tag',
154 'terms' => $this->get_terms_id( $p_id, 'post_tag' ),
155 'field' => 'term_id',
156 ),
157 array(
158 'taxonomy' => 'category',
159 'terms' => $this->get_terms_id( $p_id, 'category' ),
160 'field' => 'term_id',
161 ),
162 );
163 $args['post__not_in'] = array( $p_id );
164 }
165 break;
166 case 'sticky_posts':
167 $sticky = get_option( 'sticky_posts' );
168 if ( is_array( $sticky ) ) {
169 rsort( $sticky );
170 // $sticky = array_slice($sticky, 0, $args['posts_per_page']);
171 }
172 $args['ignore_sticky_posts'] = 1;
173 $args['post__in'] = $sticky;
174 break;
175 case 'latest_post_published':
176 $args['orderby'] = 'date';
177 $args['order'] = 'DESC';
178 $args['ignore_sticky_posts'] = 1;
179 break;
180 case 'latest_post_modified':
181 $args['orderby'] = 'modified';
182 $args['order'] = 'DESC';
183 $args['ignore_sticky_posts'] = 1;
184 break;
185 case 'oldest_post_published':
186 $args['orderby'] = 'date';
187 $args['order'] = 'ASC';
188 break;
189 case 'oldest_post_modified':
190 $args['orderby'] = 'modified';
191 $args['order'] = 'ASC';
192 break;
193 case 'alphabet_asc':
194 $args['orderby'] = 'title';
195 $args['order'] = 'ASC';
196 break;
197 case 'alphabet_desc':
198 $args['orderby'] = 'title';
199 $args['order'] = 'DESC';
200 break;
201 case 'random_post':
202 $args['orderby'] = 'rand';
203 $args['order'] = 'ASC';
204 break;
205 case 'random_post_7_days':
206 $args['orderby'] = 'rand';
207 $args['order'] = 'ASC';
208 $args['date_query'] = array( array( 'after' => '1 week ago' ) );
209 break;
210 case 'random_post_30_days':
211 $args['orderby'] = 'rand';
212 $args['order'] = 'ASC';
213 $args['date_query'] = array( array( 'after' => '1 month ago' ) );
214 break;
215 case 'most_comment':
216 $args['orderby'] = 'comment_count';
217 $args['order'] = 'DESC';
218 break;
219 case 'most_comment_1_day':
220 $args['orderby'] = 'comment_count';
221 $args['order'] = 'DESC';
222 $args['date_query'] = array( array( 'after' => '1 day ago' ) );
223 break;
224 case 'most_comment_7_days':
225 $args['orderby'] = 'comment_count';
226 $args['order'] = 'DESC';
227 $args['date_query'] = array( array( 'after' => '1 week ago' ) );
228 break;
229 case 'most_comment_30_days':
230 $args['orderby'] = 'comment_count';
231 $args['order'] = 'DESC';
232 $args['date_query'] = array( array( 'after' => '1 month ago' ) );
233 break;
234 case 'popular_post_1_day_view':
235 $args['meta_key'] = '__post_views_count';
236 $args['orderby'] = 'meta_value_num';
237 $args['order'] = 'DESC';
238 $args['date_query'] = array( array( 'after' => '1 day ago' ) );
239 break;
240 case 'popular_post_7_days_view':
241 $args['meta_key'] = '__post_views_count';
242 $args['orderby'] = 'meta_value_num';
243 $args['order'] = 'DESC';
244 $args['date_query'] = array( array( 'after' => '1 week ago' ) );
245 break;
246 case 'popular_post_30_days_view':
247 $args['meta_key'] = '__post_views_count';
248 $args['orderby'] = 'meta_value_num';
249 $args['order'] = 'DESC';
250 $args['date_query'] = array( array( 'after' => '1 month ago' ) );
251 break;
252 case 'popular_post_all_times_view':
253 $args['meta_key'] = '__post_views_count';
254 $args['orderby'] = 'meta_value_num';
255 $args['order'] = 'DESC';
256 break;
257 default:
258 // code...
259 break;
260 }
261 return $args;
262 }
263
264 /**
265 * Get All Term IDs for a Post in a Taxonomy
266 *
267 * @since v.2.4.12
268 * @param INT|STRING $id Post ID to get terms for.
269 * @param STRING $type Taxonomy name (e.g. 'category', 'post_tag').
270 * @return ARRAY
271 */
272 public function get_terms_id( $id, $type ) {
273 $data = array();
274 $arr = get_the_terms( $id, $type );
275 if ( is_array( $arr ) ) {
276 foreach ( $arr as $key => $val ) {
277 $data[] = $val->term_id;
278 }
279 }
280 return $data;
281 }
282
283 /**
284 * Get all reusable block IDs referenced in a post's content
285 *
286 * @since v.1.1.0
287 * @param INT|STRING $post_id .
288 * @return ARRAY
289 */
290 public function get_reusable_ids( $post_id ) {
291 $reusable_id = array();
292 if ( $post_id ) {
293 $post = get_post( $post_id );
294 if ( isset( $post->post_content ) ) {
295 if (
296 has_blocks( $post->post_content ) &&
297 strpos( $post->post_content, 'wp:block' ) &&
298 strpos( $post->post_content, '"ref"' ) !== false
299 ) {
300 $blocks = parse_blocks( $post->post_content );
301 foreach ( $blocks as $key => $value ) {
302 if ( isset( $value['attrs']['ref'] ) ) {
303 $reusable_id[] = $value['attrs']['ref'];
304 }
305 }
306 }
307 }
308 }
309 return $reusable_id;
310 }
311
312 /**
313 * Safely reads file contents using WordPress Filesystem API
314 *
315 * @since v.4.1.8
316 * @param STRING $path .
317 * @return STRING|ARRAY.
318 */
319 public function get_path_file_contents( $path ) {
320 global $wp_filesystem;
321 if ( ! $wp_filesystem ) {
322 require_once ABSPATH . 'wp-admin/includes/file.php';
323 $init_fs = WP_Filesystem();
324 if ( ! $init_fs ) {
325 return '';
326 }
327 }
328
329 if ( $wp_filesystem->exists( $path ) ) {
330 return $wp_filesystem->get_contents( $path );
331 } else {
332 return '';
333 }
334 }
335
336 /**
337 * Builds and returns inline CSS for a post and its reusable blocks
338 *
339 * @since v.4.1.8
340 * @param INT|STRING $post_id .
341 * @param BOOLEAN $call_common .
342 * @return STRING|ARRAY.
343 */
344 public function build_css_for_inline_print( $post_id, $call_common = true ) {
345 if ( $post_id ) {
346 $upload_dir_url = wp_get_upload_dir();
347 $upload_css_dir_url = trailingslashit( $upload_dir_url['basedir'] );
348
349 $css_dir_url = trailingslashit( $upload_dir_url['baseurl'] );
350 if ( is_ssl() ) {
351 $css_dir_url = str_replace( 'http://', 'https://', $css_dir_url );
352 }
353 $reusable_css = '';
354 $reusable_id = $this->get_reusable_ids( $post_id );
355 if ( ! empty( $reusable_id ) ) {
356 foreach ( $reusable_id as $id ) {
357 $reusable_dir_path = $upload_css_dir_url . "ultimate-post/ultp-css-{$id}.css";
358 if ( file_exists( $reusable_dir_path ) ) {
359 $reusable_css .= $this->get_path_file_contents( $reusable_dir_path );
360 } else {
361 $reusable_css .= get_post_meta( $reusable_id, '_ultp_css', true );
362 }
363 }
364 }
365
366 $css_dir_path = $upload_css_dir_url . "ultimate-post/ultp-css-{$post_id}.css";
367 $css = '';
368 if ( file_exists( $css_dir_path ) ) {
369 $css = $this->get_path_file_contents( $css_dir_path );
370 } else {
371 $css = get_post_meta( $post_id, '_ultp_css', true );
372 }
373 if ( $reusable_css . $css ) {
374 if ( $call_common ) {
375 $this->register_scripts_common();
376 }
377 return '<style id="ultp-post-' . $post_id . '" type="text/css">' . wp_strip_all_tags( $reusable_css . $css ) . '</style>';
378 }
379 }
380 return '';
381 }
382
383
384 /**
385 * Get Global Plugin Settings
386 *
387 * @since v.1.0.0
388 * @param STRING $key of the Option .
389 * @return ARRAY|STRING .
390 */
391 public function get_setting( $key = '' ) {
392 $data = $GLOBALS['ultp_settings'];
393 if ( $key != '' ) {
394 return isset( $data[ $key ] ) ? $data[ $key ] : '';
395 } else {
396 return $data;
397 }
398 }
399
400
401 /**
402 * Set Option Settings
403 *
404 * @since v.1.0.0
405 * @param STRING | $key of the Option (STRING) .
406 * @param STRING | $val Value (STRING) .
407 */
408 public function set_setting( $key = '', $val = '' ) {
409 if ( $key != '' ) {
410 $data = $GLOBALS['ultp_settings'];
411 $data[ $key ] = $val;
412 update_option( 'ultp_options', $data );
413 $GLOBALS['ultp_settings'] = $data;
414 do_action( 'ultp_settings_updated', $key, $val );
415 }
416 }
417
418
419 /**
420 * Get Image HTML
421 *
422 * @since v.1.0.0
423 * @param STRING | $url .
424 * @param STRING | $size .
425 * @param STRING | $class .
426 * @param STRING | $alt .
427 * @param STRING | $lazy .
428 * @param ARRAY | $darkImg .
429 * @param STRING | $srcset .
430 * @return STRING
431 */
432 public function get_image_html( $url = '', $size = 'full', $class = '', $alt = '', $lazy = '', $darkImg = array(), $srcset = '' ) {
433 $class = sanitize_html_class( $class );
434 $alt = preg_replace( '/[^A-Za-z0-9_ -]/', '', $alt );
435 $hasDarkImage = ( $darkImg['enable'] && $darkImg['url'] ) ? ' ultp-light-image-block ' : '';
436 $alt = $alt ? ' alt="' . $alt . '" ' : '';
437 $lazy_data = $lazy ? ' loading="lazy"' : '';
438
439 $dlMode = isset( $_COOKIE['ultplocalDLMode'] ) ? $_COOKIE['ultplocalDLMode'] : ultimate_post()->get_dl_mode();
440
441 $lightMode = $hasDarkImage ? ( $dlMode == 'ultplight' ? '' : 'inactive ' ) : '';
442 $darkMode = $hasDarkImage ? ( $hasDarkImage && $dlMode == 'ultpdark' ? '' : ' inactive ' ) : '';
443
444 $image = '<img ' . $lazy_data . $srcset . ' class="' . $class . $hasDarkImage . $lightMode . '" ' . $alt . ' src="' . esc_url( $url ) . '" />';
445 if ( $hasDarkImage ) {
446 $image .= '<img ' . $lazy_data . $darkImg['srcset'] . ' class="' . $class . $darkMode . ' ultp-dark-image-block " ' . $alt . ' src="' . esc_url( $darkImg['url'] ) . '" />';
447 }
448 return $image;
449 }
450
451
452 /**
453 * Get Image HTML
454 *
455 * @since v.1.0.0
456 * @param STRING | $attach_id .
457 * @param STRING | $size .
458 * @param STRING | $class .
459 * @param STRING | $alt .
460 * @param STRING | $srcset .
461 * @param STRING | $lazy .
462 * @return STRING
463 */
464 public function get_image( $attach_id, $size = 'full', $class = '', $alt = '', $srcset = '', $lazy = '' ) {
465 $img_alt = get_post_meta( $attach_id, '_wp_attachment_image_alt', true );
466 $alt = $img_alt ? $img_alt : $alt;
467 $alt = $alt ? ' alt="' . esc_html( $alt ) . '" ' : '';
468 $class = $class ? ' class="' . $class . '" ' : '';
469 $size = ( ultimate_post()->get_setting( 'disable_image_size' ) == 'yes' && strpos( $size, 'ultp_layout_' ) !== false ) ? 'full' : $size;
470 $lazy_data = $lazy ? ' loading="lazy"' : '';
471 $srcset_data = $srcset ? ' srcset="' . esc_attr( wp_get_attachment_image_srcset( $attach_id ) ) . '"' : '';
472 return '<img ' . $srcset_data . $lazy_data . $class . $alt . ' src="' . wp_get_attachment_image_url( $attach_id, $size ) . '" />';
473 }
474
475
476 /**
477 * Get Excerpt Text
478 *
479 * @since v.1.0.0
480 * @param STRING | $post_id .
481 * @param NUMBER | $limit .
482 * @return STRING
483 */
484 public function excerpt( $post_id, $limit = 55 ) {
485 $content = preg_replace( '/(\[postx_template[\s\w="]*)]/m', '', get_the_excerpt( $post_id ) ); // Remove postx_template shortcode form Content
486 return apply_filters( 'the_excerpt', wp_trim_words( $content, $limit ) );
487 }
488
489 /**
490 * Builder Attributes
491 *
492 * @since v.1.0.0
493 * @param STRING | $type .
494 * @return STRING
495 */
496 public function get_builder_attr( $type ) {
497 $builder_data = '';
498 if ( $type == 'archiveBuilder' ) {
499 if ( is_archive() ) {
500 if ( is_date() ) {
501 if ( is_year() ) {
502 $builder_data = 'date###' . get_the_date( 'Y' );
503 } elseif ( is_month() ) {
504 $builder_data = 'date###' . get_the_date( 'Y-n' );
505 } elseif ( is_day() ) {
506 $builder_data = 'date###' . get_the_date( 'Y-n-j' );
507 }
508 } elseif ( is_author() ) {
509 $builder_data = 'author###' . get_the_author_meta( 'ID' );
510 } else {
511 $obj = get_queried_object();
512 if ( isset( $obj->taxonomy ) ) {
513 $builder_data = 'taxonomy###' . $obj->taxonomy . '###' . $obj->slug;
514 }
515 }
516 } elseif ( is_search() ) {
517 $builder_data = 'search###' . get_search_query( true );
518 }
519 }
520 return $builder_data ? 'data-builder="' . $builder_data . '"' : '';
521 }
522
523
524 /**
525 * Determines if the builder is enabled based on the plugin settings.
526 *
527 * @param STRING $builder Optional. The builder name (currently unused).
528 * @return BOOL True if the builder is enabled, false otherwise.
529 */
530 public function is_builder( $builder = '' ) {
531 $id = '';
532 if ( ultimate_post()->get_setting( 'ultp_builder' ) != 'false' ) {
533 $page_id = ultimate_post()->builder_check_conditions( 'return_ib' );
534 if ( $page_id ) {
535 $id = $page_id;
536 }
537 }
538 return $id;
539 }
540
541
542 /**
543 * Get Post Number Depending On Device
544 *
545 * @since v.2.5.4
546 * @param MIXED | $preDef .
547 * @param MIXED | $prev .
548 * @param MIXED | $current .
549 * @return STRING
550 */
551 public function get_post_number( $preDef, $prev, $current ) {
552
553 $current = is_object( $current ) ? json_decode( wp_json_encode( $current ), true ) : $current;
554 if ( array(
555 'lg' => $preDef,
556 'sm' => $preDef,
557 'xs' => $preDef,
558 ) == $current ) {
559 if ( $preDef != $prev ) {
560 return $prev;
561 }
562 }
563
564 $lg = isset( $current['lg'] ) ? $current['lg'] : $prev;
565 $sm = isset( $current['sm'] ) ? $current['sm'] : $lg;
566 $xs = isset( $current['xs'] ) ? $current['xs'] : $lg;
567 if ( $lg == $sm && $sm == $xs ) {
568 return $lg;
569 } else {
570 global $ultpDevide;
571 $currentDevice = ! empty( $ultpDevide ) ? $ultpDevide : $this->isDevice();
572 if ( $currentDevice == 'mobile' ) {
573 return $xs;
574 } elseif ( $currentDevice == 'tablet' ) {
575 return $sm;
576 } else {
577 return $lg;
578 }
579 }
580 }
581
582
583 /**
584 * Get Post Number Depending On Device
585 *
586 * @since v.2.5.4
587 * @return STRING | Device Type
588 */
589 public function isDevice() {
590 $useragent = isset( $_SERVER['HTTP_USER_AGENT'] ) ? sanitize_key( $_SERVER['HTTP_USER_AGENT'] ) : '';
591 $device = 'desktop';
592 if ( $useragent ) {
593 if ( preg_match( '/(tablet|ipad|playbook)|(android(?!.*(mobi|opera mini)))/i', strtolower( $useragent ) ) ) {
594 $device = 'tablet';
595 } elseif ( preg_match( '/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i', $useragent ) || preg_match( '/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i', substr( $useragent, 0, 4 ) ) ) {
596 $device = 'mobile';
597 }
598 }
599 global $ultpDevide;
600 $ultpDevide = $device;
601 return $device;
602 }
603
604
605 /**
606 * Get Raw Value from Objects
607 *
608 * @since v.2.5.3
609 * @param ARRAY | $attr .
610 * @return STRING | Device Type
611 */
612 public function get_value( $attr ) {
613 $data = array();
614 if ( is_array( $attr ) ) {
615 foreach ( $attr as $val ) {
616 $data[] = $val->value;
617 }
618 }
619 return $data;
620 }
621
622 /**
623 * QueryArgs for Filter
624 *
625 * @since v.2.8.9
626 * @param ARRAY | $attr .
627 * @return ARRAY
628 */
629 public function getFilterQueryArgs( $attr ) {
630 $tax_value = ( strlen( $attr['queryTaxValue'] ) > 2 ) ? $attr['queryTaxValue'] : array();
631 $tax_value = is_array( $tax_value ) ? $tax_value : json_decode( $tax_value );
632
633 $tax_value = ( isset( $tax_value[0] ) && is_object( $tax_value[0] ) ) ? $this->get_value( $tax_value ) : $tax_value;
634
635 if ( is_array( $tax_value ) && count( $tax_value ) > 0 ) {
636 $relation = isset( $attr['queryRelation'] ) ? $attr['queryRelation'] : 'OR';
637
638 // Adv Filter Query Relation Override
639 if ( isset( $attr['advFilterEnable'] ) && $attr['advFilterEnable'] === true && isset( $attr['advRelation'] ) ) {
640 $relation = 'AND' === $attr['advRelation'] || 'OR' === $attr['advRelation'] ? $attr['advRelation'] : $relation;
641 }
642
643 $var = array( 'relation' => $relation );
644 foreach ( $tax_value as $val ) {
645 $tax_name = $attr['queryTax'];
646 // For Custom Terms
647 if ( $attr['queryTax'] == 'multiTaxonomy' ) {
648 $temp = explode( '###', $val );
649 if ( isset( $temp[1] ) ) {
650
651 if ( $temp[1] === '_all' ) {
652 continue;
653 }
654
655 $val = $temp[1];
656 $tax_name = $temp[0];
657 }
658 }
659 $var[] = array(
660 'taxonomy' => $tax_name,
661 'field' => 'slug',
662 'terms' => $val,
663 );
664 }
665 }
666 return isset( $var ) ? $var : array();
667 }
668
669 /**
670 * Query Builder
671 *
672 * @since v.1.0.0
673 * @param ARRAY | $attr .
674 * @return ARRAY
675 */
676 public function get_query( $attr ) {
677 $builder = isset( $attr['builder'] ) ? $attr['builder'] : '';
678 $post_type = isset( $attr['queryType'] ) ? $attr['queryType'] : 'post';
679 $get_post_type = isset($attr['queryPostType']) ? $attr['queryPostType'] : '';
680 if($post_type != 'archiveBuilder' && !empty($get_post_type) && $post_type == 'customPostType') {
681 $post_type = $get_post_type;
682 }
683
684 if ( $post_type == 'archiveBuilder' && ( $builder || $this->is_builder( $builder ) ) ) {
685 $archive_query = array();
686 if ( $builder ) {
687 $str = explode( '###', $builder );
688 if ( isset( $str[0] ) ) {
689 if ( $str[0] == 'taxonomy' ) {
690 if ( isset( $str[1] ) && isset( $str[2] ) ) {
691 $archive_query['tax_query'] = array(
692 array(
693 'taxonomy' => $str[1],
694 'field' => 'slug',
695 'terms' => $str[2],
696 ),
697 );
698 }
699 } elseif ( $str[0] == 'author' ) {
700 if ( isset( $str[1] ) ) {
701 $archive_query['author'] = $str[1];
702 }
703 } elseif ( $str[0] == 'search' ) {
704 if ( isset( $str[1] ) ) {
705 $archive_query['s'] = $str[1];
706 }
707 } elseif ( $str[0] == 'date' ) {
708 if ( isset( $str[1] ) ) {
709 $all_date = explode( '-', $str[1] );
710 if ( ! empty( $all_date ) ) {
711 $arg = array();
712 if ( isset( $all_date[0] ) ) {
713 $arg['year'] = $all_date[0];
714 }
715 if ( isset( $all_date[1] ) ) {
716 $arg['month'] = $all_date[1];
717 }
718 if ( isset( $all_date[2] ) ) {
719 $arg['day'] = $all_date[2];
720 }
721 $archive_query['date_query'][] = $arg;
722 }
723 }
724 }
725 }
726 } else {
727 global $wp_query;
728 $archive_query = $wp_query->query_vars;
729 }
730 $archive_query['posts_per_page'] = isset( $attr['queryNumber'] ) ? $attr['queryNumber'] : 1;
731 $archive_query['paged'] = isset( $attr['paged'] ) ? $attr['paged'] : 1;
732
733 $archive_query['paged'] = ! wp_doing_ajax() && isset( $_GET[ $attr['blockId'] . '_page' ] ) && is_numeric( $_GET[ $attr['blockId'] . '_page' ] ) ?
734 intval( $_GET[ $attr['blockId'] . '_page' ] ) :
735 $archive_query['paged'];
736
737 if ( isset( $attr['queryOffset'] ) && $attr['queryOffset'] ) {
738 $offset = $this->get_offset( $attr['queryOffset'], $archive_query );
739 $archive_query = array_merge( $archive_query, $offset );
740 }
741
742 // Include Remove from Version 2.5.4
743 if ( isset( $attr['queryInclude'] ) && $attr['queryInclude'] ) {
744 $_include = explode( ',', $attr['queryInclude'] );
745 if ( is_array( $_include ) && count( $_include ) ) {
746 $archive_query['post__in'] = isset( $archive_query['post__in'] ) ? array_merge( $archive_query['post__in'], $_include ) : $_include;
747 $archive_query['ignore_sticky_posts'] = 1;
748 $archive_query['orderby'] = 'post__in';
749 }
750 }
751
752 if ( isset( $attr['queryExclude'] ) && $attr['queryExclude'] ) {
753 $_exclude = ( substr( $attr['queryExclude'], 0, 1 ) === '[' ) ? $this->get_value( json_decode( $attr['queryExclude'] ) ) : explode( ',', $attr['queryExclude'] );
754 if ( is_array( $_exclude ) && count( $_exclude ) ) {
755 $archive_query['post__not_in'] = isset( $archive_query['post__not_in'] ) ? array_merge( $archive_query['post__not_in'], $_exclude ) : $_exclude;
756 }
757 }
758
759 if ( isset( $attr['querySticky'] ) && $attr['querySticky'] ) {
760 if ( filter_var( $attr['querySticky'], FILTER_VALIDATE_BOOLEAN ) ) {
761 $sticky = get_option( 'sticky_posts', array() );
762 $archive_query['post__not_in'] = isset( $archive_query['post__not_in'] ) ? array_merge( $archive_query['post__not_in'], $sticky ) : $sticky;
763 }
764 }
765 // ===============
766 if ( isset( $attr['queryUnique'] ) && $attr['queryUnique'] ) {
767 global $unique_ID;
768 if ( isset( $unique_ID[ $attr['queryUnique'] ] ) ) {
769 $archive_query['post__not_in'] = isset( $archive_query['post__not_in'] ) ? array_merge( $archive_query['post__not_in'], $unique_ID[ $attr['queryUnique'] ] ) : $unique_ID[ $attr['queryUnique'] ];
770 }
771 }
772 // ===============
773
774 $archive_query['post_status'] = 'publish';
775 if ( is_user_logged_in() ) {
776 if ( current_user_can( 'editor' ) || current_user_can( 'administrator' ) ) {
777 $archive_query['post_status'] = array( 'publish', 'private' );
778 }
779 }
780
781 if ( ! isset( $archive_query['orderby'] ) ) {
782 $archive_query['orderby'] = isset( $attr['queryOrderBy'] ) ? $attr['queryOrderBy'] : 'date';
783 }
784
785 // Quick Query Support for Builder
786 if ( isset( $attr['queryQuick'] ) ) {
787 if ( $attr['queryQuick'] != '' ) {
788 $archive_query = ultimate_post()->get_quick_query( $attr, $archive_query );
789 }
790 }
791
792 if ( ! isset( $attr['ajaxCall'] ) ) {
793 if ( isset( $attr['filterShow'] ) && $attr['filterShow'] && $attr['filterShow'] != 'false' ) {
794 if ( isset( $attr['filterType'] ) && isset( $attr['filterValue'] ) ) {
795 $filterValue = strlen( $attr['filterValue'] ) > 2 ? $attr['filterValue'] : array();
796 $filterValue = is_array( $filterValue ) ? $filterValue : json_decode( $filterValue );
797 if ( count( $filterValue ) > 0 && $attr['filterType'] ) {
798 $final = array( 'relation' => 'OR' );
799 foreach ( $filterValue as $key => $val ) {
800 $final[] = array(
801 'taxonomy' => $attr['filterType'],
802 'field' => 'slug',
803 'terms' => $val,
804 );
805 }
806 $archive_query['tax_query'] = $final;
807 }
808 }
809 }
810 }
811 // from v.3.0.7 - for search builder
812 if ( is_search() ) {
813 $archive_query['orderby'] = 'relevance';
814 if ( isset( $_GET['ultp_exclude'] ) ) { // Added support for search block exclude
815 $ultp_exclude = json_decode( stripslashes( $_GET['ultp_exclude'] ), true );
816 if ( is_array( $ultp_exclude ) ) {
817 $all_types = get_post_types( array( 'public' => true ), 'names' );
818 $post_type = array_diff( $all_types, $ultp_exclude );
819 $archive_query['post_type'] = $post_type;
820 }
821 }
822 }
823
824 return apply_filters( 'ultp_archive_query', $archive_query );
825 }
826
827 // When you use load more pagination block for a grid that did not have load more feature,
828 // the incoming posts would not align properly with the blocks design and looked bad.
829 // This fixes that.
830 if (
831 isset( $attr['paginationType'] ) &&
832 isset( $attr['queryNumber2'] ) &&
833 isset( $attr['notFirstLoad'] ) &&
834 $attr['paginationType'] === 'loadMore' &&
835 $attr['notFirstLoad']
836 ) {
837 $query_number = $attr['queryNumber2'];
838 // $query_number = isset($attr['queryNumber']) ? $attr['queryNumber'] : 3;
839 } else {
840 $query_number = isset( $attr['queryNumber'] ) ? $attr['queryNumber'] : 3;
841 }
842
843 $paged = isset( $attr['paged'] ) ? $attr['paged'] : 1;
844 $paged = ! wp_doing_ajax() &&
845 isset( $attr['blockId'] ) &&
846 isset( $_GET[ $attr['blockId'] . '_page' ] ) &&
847 is_numeric( $_GET[ $attr['blockId'] . '_page' ] ) ?
848 intval( $_GET[ $attr['blockId'] . '_page' ] ) :
849 $paged;
850
851 $query_args = array(
852 'posts_per_page' => $query_number,
853 'post_type' => is_array( $post_type ) && ! empty( $post_type ) ? $post_type : ( 'archiveBuilder' == $post_type ? 'post' : ( is_string( $post_type ) ? is_array(json_decode( $post_type )) ? json_decode( $post_type ) : $post_type : $post_type ) ),
854 'orderby' => isset( $attr['queryOrderBy'] ) ? $attr['queryOrderBy'] : 'date',
855 'order' => isset( $attr['queryOrder'] ) ? $attr['queryOrder'] : 'desc',
856 'paged' => $paged,
857 'post_status' => 'publish',
858 );
859
860 // For Private Post 'private'.
861 if ( is_user_logged_in() ) {
862 if ( current_user_can( 'editor' ) || current_user_can( 'administrator' ) ) {
863 $query_args['post_status'] = array( 'publish', 'private' );
864 }
865 }
866
867 if ( $attr['queryType'] == 'posts' ) {
868 if ( isset( $attr['queryPosts'] ) && $attr['queryPosts'] ) {
869 unset( $query_args['post_type'] );
870 $data = json_decode( isset( $attr['queryPosts'] ) ? $attr['queryPosts'] : '[]' );
871 $final = $this->get_value( $data );
872 if ( count( $final ) > 0 ) {
873 $query_args['post__in'] = $final;
874 // $query_args['posts_per_page'] = -1;
875 }
876 $query_args['ignore_sticky_posts'] = 1;
877 return $query_args;
878 }
879 } elseif ( $attr['queryType'] == 'customPosts' ) {
880 if ( isset( $attr['queryCustomPosts'] ) && $attr['queryCustomPosts'] ) {
881 $query_args['post_type'] = $this->get_post_type();
882 $data = json_decode( isset( $attr['queryCustomPosts'] ) ? $attr['queryCustomPosts'] : '[]' );
883 $final = $this->get_value( $data );
884 if ( count( $final ) > 0 ) {
885 $query_args['post__in'] = $final;
886 // $query_args['posts_per_page'] = -1;
887 }
888 $query_args['ignore_sticky_posts'] = 1;
889 return $query_args;
890 }
891 }
892
893 if ( isset( $attr['queryExcludeAuthor'] ) && $attr['queryExcludeAuthor'] ) {
894 $data = json_decode( isset( $attr['queryExcludeAuthor'] ) ? $attr['queryExcludeAuthor'] : '[]' );
895 $final = $this->get_value( $data );
896 if ( count( $final ) > 0 ) {
897 $query_args['author__not_in'] = $final;
898 }
899 }
900
901 if ( isset( $attr['queryOrderBy'] ) && isset( $attr['metaKey'] ) ) {
902 if ( $attr['queryOrderBy'] == 'meta_value_num' ) {
903 $query_args['meta_key'] = $attr['metaKey'];
904 }
905 }
906
907 // Include Remove from Version 2.5.4.
908 if ( isset( $attr['queryInclude'] ) && $attr['queryInclude'] ) {
909 $_include = explode( ',', $attr['queryInclude'] );
910 if ( is_array( $_include ) && count( $_include ) ) {
911 $query_args['post__in'] = isset( $query_args['post__in'] ) ? array_merge( $query_args['post__in'], $_include ) : $_include;
912 $query_args['ignore_sticky_posts'] = 1;
913 $query_args['orderby'] = 'post__in';
914 }
915 }
916
917 if ( isset( $attr['queryTax'] ) ) {
918 if ( isset( $attr['queryTaxValue'] ) ) {
919 $var = $this->getFilterQueryArgs( $attr );
920 if ( isset( $var ) && count( $var ) > 1 ) {
921 $query_args['tax_query'] = $var;
922 }
923 }
924 }
925
926 if ( isset( $attr['queryExcludeTerm'] ) && $attr['queryExcludeTerm'] ) {
927 $temp = json_decode( $attr['queryExcludeTerm'] );
928 $_term = array();
929 foreach ( $temp as $val ) {
930 $temp = explode( '###', $val->value );
931 if ( isset( $temp[1] ) ) {
932 if ( is_array( $_term ) && array_key_exists( $temp[0], $_term ) ) {
933 $_term[ $temp[0] ][] = $temp[1];
934 } else {
935 $_term[ $temp[0] ] = array( $temp[1] );
936 }
937 }
938 }
939 if ( count( $_term ) > 0 ) {
940 $final = array( 'relation' => 'AND' );
941 foreach ( $_term as $key => $val ) {
942 $final[] = array(
943 'taxonomy' => $key,
944 'field' => 'slug',
945 'terms' => $val,
946 'operator' => 'NOT IN',
947 );
948 }
949
950 if ( is_array( $query_args ) && array_key_exists( 'tax_query', $query_args ) ) {
951 $query_args['tax_query'] = array(
952 'relation' => 'AND',
953 $query_args['tax_query'],
954 );
955 $query_args['tax_query'][] = $final;
956 } else {
957 $query_args['tax_query'] = $final;
958 }
959 }
960 }
961
962 if ( isset( $attr['queryExclude'] ) && $attr['queryExclude'] ) {
963 $_exclude = ( substr( $attr['queryExclude'], 0, 1 ) === '[' ) ? $this->get_value( json_decode( $attr['queryExclude'] ) ) : explode( ',', $attr['queryExclude'] );
964 if ( is_array( $_exclude ) && count( $_exclude ) ) {
965 $query_args['post__not_in'] = isset( $query_args['post__not_in'] ) ? array_merge( $query_args['post__not_in'], $_exclude ) : $_exclude;
966 }
967 }
968
969 if ( isset( $attr['queryUnique'] ) && $attr['queryUnique'] ) {
970 global $unique_ID;
971 if ( isset( $unique_ID[ $attr['queryUnique'] ] ) ) {
972 $query_args['post__not_in'] = isset( $query_args['post__not_in'] ) ? array_merge( $query_args['post__not_in'], $unique_ID[ $attr['queryUnique'] ] ) : $unique_ID[ $attr['queryUnique'] ];
973 }
974 }
975 // exclude current post from Post blocks // v.2.9.6.
976 if ( is_single() && get_the_ID() ) {
977 $query_args['post__not_in'] = isset( $query_args['post__not_in'] ) ? array_merge( $query_args['post__not_in'], array( get_the_ID() ) ) : array( get_the_ID() );
978 }
979
980 if ( isset( $attr['queryQuick'] ) ) {
981 if ( $attr['queryQuick'] != '' && $post_type != 'archiveBuilder' ) {
982 $query_args = ultimate_post()->get_quick_query( $attr, $query_args );
983 }
984 }
985
986 if ( isset( $attr['queryOffset'] ) && $attr['queryOffset'] ) {
987 $offset = $this->get_offset( $attr['queryOffset'], $query_args );
988 $query_args = array_merge( $query_args, $offset );
989 }
990
991 if ( isset( $attr['queryAuthor'] ) && $attr['queryAuthor'] ) {
992 $_include = ( substr( $attr['queryAuthor'], 0, 1 ) === '[' ) ? $this->get_value( json_decode( $attr['queryAuthor'] ) ) : explode( ',', $attr['queryAuthor'] );
993 if ( is_array( $_include ) && count( $_include ) ) {
994 $query_args['author__in'] = $_include;
995 }
996 }
997
998 if ( isset( $attr['querySearch'] ) && $attr['querySearch'] ) {
999 $query_args['s'] = $attr['querySearch'];
1000 }
1001
1002 if ( isset( $attr['querySticky'] ) && $attr['querySticky'] ) {
1003 if ( filter_var( $attr['querySticky'], FILTER_VALIDATE_BOOLEAN ) ) {
1004 $sticky = get_option( 'sticky_posts', array() );
1005 $query_args['post__not_in'] = isset( $query_args['post__not_in'] ) ? array_merge( $query_args['post__not_in'], $sticky ) : $sticky;
1006 }
1007 }
1008
1009 if ( ! isset( $attr['ajaxCall'] ) ) {
1010 if ( isset( $attr['filterShow'] ) && $attr['filterShow'] && $attr['filterShow'] != 'false' ) {
1011 if ( isset( $attr['checkFilter'] ) && isset( $attr['queryTax'] ) && isset( $attr['queryTaxValue'] ) ) {
1012 $var = $this->getFilterQueryArgs( $attr );
1013 if ( isset( $var ) && count( $var ) > 1 ) {
1014 $query_args['tax_query'] = $var;
1015 }
1016 } elseif ( isset( $attr['filterType'] ) && isset( $attr['filterValue'] ) ) {
1017 $filterValue = strlen( $attr['filterValue'] ) > 2 ? $attr['filterValue'] : array();
1018 $filterValue = is_array( $filterValue ) ? $filterValue : json_decode( $filterValue );
1019 if ( is_array( $filterValue ) && count( $filterValue ) > 0 && $attr['filterType'] ) {
1020 $final = array( 'relation' => 'OR' );
1021 foreach ( $filterValue as $key => $val ) {
1022 $final[] = array(
1023 'taxonomy' => $attr['filterType'],
1024 'field' => 'slug',
1025 'terms' => $val,
1026 // 'operator' => '=',
1027 );
1028 }
1029 $query_args['tax_query'] = $final;
1030 }
1031 }
1032 }
1033 }
1034
1035 // Advanced Filter Select Dropdown Default value.
1036 // only on initial page load.
1037 if (
1038 ! wp_doing_ajax() &&
1039 isset( $attr['advFilterEnable'] ) &&
1040 $attr['advFilterEnable'] === true &&
1041 isset( $attr['defQueryTax'] ) &&
1042 count( $attr['defQueryTax'] ) > 0
1043 ) {
1044 $tax_query = array(
1045 'relation' =>
1046 isset( $attr['advRelation'] ) &&
1047 ( 'AND' === $attr['advRelation'] || 'OR' === $attr['advRelation'] )
1048 ? $attr['advRelation'] : 'AND',
1049 );
1050 $is_valid = false;
1051
1052 foreach ( $attr['defQueryTax'] as $_ => $defQueryTaxValue ) {
1053 $term = explode( '###', $defQueryTaxValue );
1054
1055 // Validation
1056 if (
1057 ! in_array( $term[0], array( 'category', 'tags', 'author', 'custom_tax' ), true ) ||
1058 '_all' === $term[1] ||
1059 empty( $term[1] )
1060 ) {
1061 continue;
1062 }
1063
1064 if ( 'author' === $term[0] ) {
1065
1066 if ( ! is_numeric( $term[1] ) ) {
1067 continue;
1068 }
1069
1070 $query_args['author__in'] = $term[1];
1071 } elseif ( 'custom_tax' === $term[0] && isset( $attr['queryType'] ) ) {
1072 $post_type = sanitize_key( $attr['queryType'] );
1073 $slug = sanitize_key( $term[1] );
1074
1075 // These are not custom post type.
1076 if ( in_array( $post_type, array( 'posts', 'customPosts' ), true ) ) {
1077 continue;
1078 }
1079
1080 $taxonomy = $this->get_taxonomy_by_term_slug( $post_type, $slug );
1081
1082 if ( ! empty( $taxonomy ) ) {
1083 $q = array(
1084 'field' => 'slug',
1085 'taxonomy' => $taxonomy,
1086 'terms' => $slug,
1087 );
1088
1089 $tax_query[] = $q;
1090 $is_valid = true;
1091 }
1092 } else {
1093 if ( ! is_numeric( $term[1] ) ) {
1094 continue;
1095 }
1096
1097 $q = array(
1098 'field' => 'term_id',
1099 'taxonomy' => 'tags' === $term[0] ? 'post_tag' : 'category',
1100 'terms' => $term[1],
1101 );
1102
1103 $tax_query[] = $q;
1104 $is_valid = true;
1105 }
1106 }
1107
1108 if ( $is_valid ) {
1109 $query_args['tax_query'] = $tax_query;
1110 }
1111 }
1112 // $query_args['test'] = is_array( $post_type ) && ! empty( $post_type ) ? $post_type : ( 'archiveBuilder' === $post_type ? 'post' : ( is_string( $post_type ) ? json_decode( $post_type ) : $post_type ) );
1113 $query_args['wpnonce'] = wp_create_nonce( 'ultp-nonce' );
1114
1115 return apply_filters( 'ultp_frontend_query', $query_args );
1116 }
1117
1118 /**
1119 * Get Page Offset
1120 *
1121 * @since v.1.0.0
1122 * @param NUMBER | $queryOffset Offset .
1123 * @param ARRAY | $query_args Query .
1124 * @return ARRAY
1125 */
1126 function get_offset( $queryOffset, $query_args ) {
1127 $query = array();
1128 if ( $query_args['paged'] > 1 ) {
1129 $offset_post = wp_get_recent_posts( $query_args, OBJECT );
1130 if ( count( $offset_post ) > 0 ) {
1131 $offset = array();
1132 for ( $x = count( $offset_post ); $x > count( $offset_post ) - $queryOffset; $x-- ) {
1133 $offset[] = $offset_post[ $x - 1 ]->ID;
1134 }
1135 $query['post__not_in'] = $offset;
1136 }
1137 } else {
1138 $query['offset'] = isset( $queryOffset ) ? $queryOffset : 0;
1139 }
1140 return $query;
1141 }
1142
1143
1144 /**
1145 * Get Page Number
1146 *
1147 * @since v.1.0.0
1148 * @param array $attr Attribute of the Query.
1149 * @param int $post_number Post Number.
1150 * @return ARRAY
1151 */
1152 public function get_page_number( $attr, $post_number ) {
1153 if ( $post_number > 0 ) {
1154 if ( isset( $attr['queryOffset'] ) && $attr['queryOffset'] ) {
1155 $post_number = $post_number - (int) $attr['queryOffset'];
1156 }
1157 $post_per_page = isset( $attr['queryNumber'] ) ? ( $attr['queryNumber'] ? $attr['queryNumber'] : 1 ) : 3;
1158 $pages = ceil( $post_number / $post_per_page );
1159 return $pages ? $pages : 1;
1160 } else {
1161 return 1;
1162 }
1163 }
1164
1165
1166 /**
1167 * Get Image Size
1168 *
1169 * @since v.1.0.0
1170 * @return ARRAY
1171 */
1172 public function get_image_size() {
1173 $sizes = get_intermediate_image_sizes();
1174 $filter = array( 'full' => 'Full' );
1175 foreach ( $sizes as $value ) {
1176 $title = ucwords( str_replace( array( '_', '-', 'ultp' ), array( ' ', ' ', 'PostX' ), $value ) );
1177 switch ( $value ) {
1178 case 'thumbnail':
1179 $title = $title . ' [150x150]';
1180 break;
1181 case 'medium':
1182 $title = $title . ' [300x300]';
1183 break;
1184 case 'large':
1185 $title = $title . ' [1024x1024]';
1186 break;
1187 case 'ultp_layout_landscape_large':
1188 $title = $title . ' [1200x800]';
1189 break;
1190 case 'ultp_layout_landscape':
1191 $title = $title . ' [870x570]';
1192 break;
1193 case 'ultp_layout_portrait':
1194 $title = $title . ' [600x900]';
1195 break;
1196 case 'ultp_layout_square':
1197 $title = $title . ' [600x600]';
1198 break;
1199 default:
1200 break;
1201 }
1202 $filter[ $value ] = $title;
1203 }
1204 return $filter;
1205 }
1206
1207
1208 /**
1209 * Get All PostType Registered
1210 *
1211 * @since v.1.0.0
1212 * @return ARRAY
1213 */
1214 public function get_post_type() {
1215 $filter = apply_filters( 'ultp_public_post_type', true );
1216 $post_type = get_post_types( ( $filter ? array( 'public' => true ) : '' ), 'names' );
1217 return array_diff( $post_type, array( 'attachment' ) );
1218 }
1219
1220 /**
1221 * Get Pagination Url
1222 *
1223 * @since v.2.8.9
1224 *
1225 * @param NUMBER $pageNo The page number for pagination.
1226 * @param STRING $baseUrl The base URL to append the pagination parameter to.
1227 *
1228 * @return STRING The generated pagination URL.
1229 */
1230 public function generatePaginationUrl( $pageNo, $baseUrl ) {
1231 if ( $baseUrl ) {
1232 $url = $baseUrl . ( $pageNo == 1 ? '' : 'page/' . $pageNo );
1233 } else {
1234 $url = get_pagenum_link( $pageNo );
1235 }
1236 return $url;
1237 }
1238 /**
1239 * Get Pagination HTML
1240 *
1241 * @since v.1.0.0
1242 * @param INT $pages Number of pages.
1243 * @param STRING $paginationNav Pagination navigation type.
1244 * @param STRING $paginationText Pagination text.
1245 * @param BOOL $paginationAjax Whether to use AJAX pagination.
1246 * @param STRING $baseUrl Base URL for pagination links.
1247 * @param STRING $blockId Block ID for pagination.
1248 * @return STRING
1249 */
1250 public function pagination( $pages = '', $paginationNav = '', $paginationText = '', $paginationAjax = true, $baseUrl = '', $blockId = '' ) {
1251 $html = '';
1252 $showitems = 3;
1253 $paged = is_front_page() ? get_query_var( 'page' ) : get_query_var( 'paged' );
1254 $paged = $paged ? $paged : 1;
1255
1256 $paged = ! wp_doing_ajax() &&
1257 isset( $_GET[ $blockId . '_page' ] ) &&
1258 is_numeric( $_GET[ $blockId . '_page' ] ) ?
1259 intval( $_GET[ $blockId . '_page' ] ) : $paged;
1260
1261 if ( $pages == '' ) {
1262 global $wp_query;
1263 $pages = $wp_query->max_num_pages;
1264 if ( ! $pages ) {
1265 $pages = 1;
1266 }
1267 }
1268
1269 $data = ( $paged >= 3 ? array( ( $paged - 1 ), $paged, $paged + 1 ) : array( 1, 2, 3 ) );
1270
1271 $paginationText = explode( '|', $paginationText );
1272
1273 $prev_text = isset( $paginationText[0] ) ? esc_html( $paginationText[0] ) : __( 'Previous', 'ultimate-post' );
1274 $next_text = isset( $paginationText[1] ) ? esc_html( $paginationText[1] ) : __( 'Next', 'ultimate-post' );
1275
1276 if ( 1 != $pages ) {
1277 $html .= '<ul class="ultp-pagination">';
1278 $display_none = 'style="display:none"';
1279 if ( $paged > 1 || $paginationAjax && $pages > 1 ) {
1280 $html .= '<li class="ultp-prev-page-numbers" ' . ( $paged == 1 ? $display_none : '' ) . '><a href="' . $this->generatePaginationUrl( $paged - 1, $baseUrl ) . '">' . ultimate_post()->get_svg_icon( 'leftAngle2' ) . ' ' . ( $paginationNav == 'textArrow' ? $prev_text : '' ) . '</a></li>';
1281 }
1282 if ( $pages > 3 ) {
1283 $html .= '<li class="ultp-first-pages" ' . ( $paged < 2 ? $display_none : '' ) . ' data-current="1"><a href="' . $this->generatePaginationUrl( 1, $baseUrl ) . '">1</a></li>';
1284 }
1285 if ( $paged > 3 || $paginationAjax && $pages > 4 ) {
1286 $html .= '<li class="ultp-first-dot"' . ( $paged == 1 ? $display_none : '' ) . '><a href="#">...</a></li>';
1287 }
1288 foreach ( $data as $i ) {
1289 if ( $pages > 3 && $pages == $i ) {
1290 continue;
1291 }
1292 if ( $pages >= $i ) {
1293 $html .= ( $paged == $i ) ? '<li class="ultp-center-item pagination-active" data-current="' . $i . '"><a href="' . $this->generatePaginationUrl( $i, $baseUrl ) . '">' . $i . '</a></li>' : '<li class="ultp-center-item" data-current="' . $i . '" ' . ( ( $pages > 4 && $paged == 2 && $i == 1 && ! $paginationAjax ) ? $display_none : '' ) . '><a href="' . $this->generatePaginationUrl( $i, $baseUrl ) . '">' . $i . '</a></li>';
1294 }
1295 }
1296 if ( $pages != ( $paged + 2 ) || $paginationAjax && $pages > 4 ) {
1297 $html .= '<li class="ultp-last-dot" ' . ( $pages <= $paged + 1 ? $display_none : '' ) . '><a href="#">...</a></li>';
1298 }
1299 if ( $pages > 3 ) {
1300 $html .= '<li class="ultp-last-pages' . ( $paged == $pages ? ' pagination-active' : '' ) . '" data-current="' . $pages . '"><a href="' . $this->generatePaginationUrl( $pages, $baseUrl ) . '">' . $pages . '</a></li>';
1301 }
1302 if ( $paged != $pages ) {
1303 $html .= '<li class="ultp-next-page-numbers"><a href="' . $this->generatePaginationUrl( $paged + 1, $baseUrl ) . '">' . ( $paginationNav == 'textArrow' ? $next_text : '' ) . ultimate_post()->get_svg_icon( 'rightAngle2' ) . '</a></li>';
1304 }
1305 $html .= '</ul>';
1306 }
1307 return $html;
1308 }
1309
1310 /**
1311 * Svg Icon Source
1312 *
1313 * @since v.1.0.0
1314 * @param STRING $ultp_icons Name of the SVG icon file (without extension).
1315 * @return STRING
1316 */
1317 public function get_svg_icon( $ultp_icons = '' ) {
1318 $svg = '';
1319 if ( $ultp_icons ) {
1320 $icon = $this->svg_icon_compatibility($ultp_icons);
1321 $svg = $this->get_path_file_contents( ULTP_PATH . 'assets/img/iconpack/' . $icon . '.svg' );
1322 }
1323 return $svg;
1324 }
1325
1326 /**
1327 * Get Taxonomy Lists
1328 *
1329 * @since v.1.0.0
1330 * @param STRING|ARRAY $prams Taxonomy slug or arguments array.
1331 * @return ARRAY
1332 */
1333 public function taxonomy( $prams = 'category' ) {
1334 $data = array();
1335
1336 $terms = get_terms(
1337 is_string( $prams ) ? array(
1338 'taxonomy' => $prams,
1339 'hide_empty' => false,
1340 ) : $prams
1341 );
1342 if ( ! is_wp_error( $terms ) ) {
1343 foreach ( $terms as $val ) {
1344 $data[ urldecode_deep( $val->slug ) ] = $val->name;
1345 }
1346 }
1347 return $data;
1348 }
1349
1350
1351 /**
1352 * Get Taxonomy Lists
1353 *
1354 * @since v.2.9.0
1355 * @param STRING $tax_slug Taxonomy slug.
1356 * @param INT $number Number of terms to retrieve.
1357 * @return ARRAY
1358 */
1359 public function builder_preview( $tax_slug, $number ) {
1360 $data = array();
1361 $term_data = get_terms(
1362 array(
1363 'taxonomy' => $tax_slug,
1364 'hide_empty' => true,
1365 'number' => $number,
1366 'parent' => 0,
1367 )
1368 );
1369 if ( ! empty( $term_data ) ) {
1370 foreach ( $term_data as $terms ) {
1371 $data[] = $this->get_tax_data( $terms );
1372 }
1373 }
1374 return $data;
1375 }
1376
1377 /**
1378 * Get Taxonomy Data Lists
1379 *
1380 * @since v.1.0.0
1381 * @param object $terms Taxonomy Object.
1382 * @return ARRAY
1383 */
1384 public function get_tax_data( $terms ) {
1385 $temp = array();
1386 $thumbnail_id = get_term_meta( $terms->term_id, 'ultp_category_image', true );
1387 $image_src = array();
1388 if ( $thumbnail_id ) {
1389 $image_sizes = ultimate_post()->get_image_size();
1390 foreach ( $image_sizes as $key => $value ) {
1391 $img_src = wp_get_attachment_image_src( $thumbnail_id, $key, false );
1392 if ( $img_src ) {
1393 $image_src[ $key ] = $img_src[0];
1394 }
1395 }
1396 }
1397 $temp['url'] = get_term_link( $terms );
1398 $temp['thumbnail_id'] = $thumbnail_id;
1399 $temp['name'] = $terms->name;
1400 $temp['desc'] = $terms->description;
1401 $temp['count'] = $terms->count;
1402 $temp['image'] = $image_src;
1403 $color = get_term_meta( $terms->term_id, 'ultp_category_color', true );
1404 $temp['color'] = $color ? $color : '#037fff';
1405 return $temp;
1406 }
1407
1408 public function get_category_data( $catSlug, $number = 40, $type = '', $tax_slug = 'category', $archiveBuilder = '' ) {
1409 $data = array();
1410 if ( $type == 'child' ) {
1411 if ( $archiveBuilder ) {
1412 $data = $this->builder_preview( $tax_slug, $number );
1413 } else {
1414 if ( is_category() ) {
1415 $catSlug = array( get_queried_object()->slug );
1416 }
1417 $image = '';
1418 if ( ! empty( $catSlug ) ) {
1419 foreach ( $catSlug as $cat ) {
1420 $parent_term = get_term_by( 'slug', $cat, $tax_slug );
1421 if ( ! empty( $parent_term ) ) {
1422 $term_data = get_terms(
1423 array(
1424 'taxonomy' => $tax_slug,
1425 'hide_empty' => true,
1426 'number' => $number,
1427 'parent' => $parent_term->term_id,
1428 )
1429 );
1430 if ( ! empty( $term_data ) ) {
1431 foreach ( $term_data as $terms ) {
1432 $data[] = $this->get_tax_data( $terms );
1433 }
1434 }
1435 }
1436 }
1437 }
1438 }
1439 } elseif ( $type == 'parent' ) {
1440 $term_data = is_category() ? array( get_term( get_queried_object()->parent, 'category' ) ) : get_terms(
1441 array(
1442 'taxonomy' => $tax_slug,
1443 'hide_empty' => true,
1444 'number' => $number,
1445 'parent' => 0,
1446 )
1447 );
1448 if ( $archiveBuilder && ! empty( $term_data ) ) {
1449 $term_data = array( $term_data[0] );
1450 }
1451 if ( ! empty( $term_data ) ) {
1452 foreach ( $term_data as $terms ) {
1453 if ( ! empty( $terms->term_id ) ) {
1454 $data[] = $this->get_tax_data( $terms );
1455 }
1456 }
1457 }
1458 } elseif ( $type == 'custom' ) {
1459 foreach ( $catSlug as $cat ) {
1460 $terms = get_term_by( 'slug', $cat, $tax_slug );
1461 if ( ! empty( $terms ) ) {
1462 $data[] = $this->get_tax_data( $terms );
1463 }
1464 }
1465 } elseif ( $type == 'immediate_child' ) {
1466 if ( $archiveBuilder ) {
1467 $data = $this->builder_preview( $tax_slug, $number );
1468 } else {
1469 $id_ = get_queried_object();
1470 if ( isset( $id_->term_id ) ) {
1471 $term_data = get_terms(
1472 array(
1473 'taxonomy' => $tax_slug,
1474 'hide_empty' => true,
1475 'number' => 100,
1476 'parent' => $id_->term_id,
1477 )
1478 );
1479 if ( ! empty( $term_data ) ) {
1480 foreach ( $term_data as $terms ) {
1481 $data[] = $this->get_tax_data( $terms );
1482 }
1483 }
1484 }
1485 }
1486 } elseif ( $type == 'allchild' ) {
1487 if ( $archiveBuilder ) {
1488 $data = $this->builder_preview( $tax_slug, $number );
1489 } else {
1490 $id_ = get_queried_object();
1491 if ( isset( $id_->term_taxonomy_id ) ) {
1492 $termchildren = get_term_children( $id_->term_taxonomy_id, $tax_slug );
1493 foreach ( $termchildren as $key => $value ) {
1494 $terms = get_term_by( 'id', $value, $tax_slug );
1495 $data[] = $this->get_tax_data( $terms );
1496 }
1497 }
1498 }
1499 } elseif ( $type == 'current_level' ) {
1500 if ( $archiveBuilder ) {
1501 $data = $this->builder_preview( $tax_slug, $number );
1502 } else {
1503 $id_ = get_queried_object();
1504 if ( isset( $id_->parent ) ) {
1505 $term_data = get_terms(
1506 array(
1507 'taxonomy' => $tax_slug,
1508 'hide_empty' => true,
1509 'number' => $number,
1510 'parent' => $id_->parent,
1511 )
1512 );
1513 if ( ! empty( $term_data ) ) {
1514 foreach ( $term_data as $terms ) {
1515 if ( $terms->term_id != $id_->term_id ) {
1516 $data[] = $this->get_tax_data( $terms );
1517 }
1518 }
1519 }
1520 }
1521 }
1522 } else {
1523 $term_data = get_terms(
1524 array(
1525 'taxonomy' => $tax_slug,
1526 'hide_empty' => true,
1527 'number' => $number,
1528 )
1529 );
1530 if ( ! empty( $term_data ) ) {
1531 foreach ( $term_data as $terms ) {
1532 $data[] = $this->get_tax_data( $terms );
1533 }
1534 }
1535 }
1536 return $data;
1537 }
1538
1539
1540 /**
1541 * Get Next Previous HTML.
1542 *
1543 * @since v.1.0.0
1544 * @return STRING
1545 */
1546 public function next_prev() {
1547 $html = '';
1548 $html .= '<ul>';
1549 $html .= '<li>';
1550 $html .= '<a class="ultp-prev-action ultp-disable" href="#">';
1551 $html .= ultimate_post()->get_svg_icon( 'leftAngle2' ) . '<span class="screen-reader-text">' . esc_html__( 'Previous', 'ultimate-post' ) . '</span>';
1552 $html .= '</a>';
1553 $html .= '</li>';
1554 $html .= '<li>';
1555 $html .= '<a class="ultp-next-action">';
1556 $html .= ultimate_post()->get_svg_icon( 'rightAngle2' ) . '<span class="screen-reader-text">' . esc_html__( 'Next', 'ultimate-post' ) . '</span>';
1557 $html .= '</a>';
1558 $html .= '</li>';
1559 $html .= '</ul>';
1560 return $html;
1561 }
1562
1563
1564 /**
1565 * Get Loading HTML
1566 *
1567 * @since v.1.0.0
1568 * @return STRING
1569 */
1570 public function postx_loading() {
1571 $html = '';
1572 $style = ultimate_post()->get_setting( 'preloader_style' );
1573 if ( $style == 'style2' ) {
1574 $html .= '<div class="ultp-loading-spinner" style="width:100%;height:100%"><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div></div>'; // ultp-block-items-wrap
1575 } else {
1576 $html .= '<div class="ultp-loading-blocks" style="width:100%;height:100%;"><div style="left: 0;top: 0;animation-delay:0s;"></div><div style="left: 21px;top: 0;animation-delay:0.125s;"></div><div style="left: 42px;top: 0;animation-delay:0.25s;"></div><div style="left: 0;top: 21px;animation-delay:0.875s;"></div><div style="left: 42px;top: 21px;animation-delay:0.375s;"></div><div style="left: 0;top: 42px;animation-delay:0.75s;"></div><div style="left: 42px;top: 42px;animation-delay:0.625s;"></div><div style="left: 21px;top: 42px;animation-delay:0.5s;"></div></div>';
1577 }
1578 return '<div class="ultp-loading">' . $html . '</div>';
1579 }
1580
1581
1582 /**
1583 * Get Filter HTML
1584 *
1585 * @since v.1.0.0
1586 * @param STRING $filterText Filter Text.
1587 * @param STRING $filterType Filter Type.
1588 * @param ARRAY|STRING $filterValue Filter Value.
1589 * @param STRING $filterMobileText Filter Mobile Text.
1590 * @param BOOL $filterMobile Enable Filter Mobile.
1591 * @return STRING
1592 */
1593 public function filter_html( $filterText = '', $filterType = '', $filterValue = '[]', $filterMobileText = '...', $filterMobile = true ) {
1594 $html = '';
1595 $html .= '<ul ' . ( $filterMobile ? 'class="ultp-flex-menu"' : '' ) . ' data-name="' . ( $filterMobileText ? $filterMobileText : '&nbsp;' ) . '">';
1596 $cat = $this->taxonomy( $filterType );
1597 if ( $filterText ) {
1598 $html .= '<li class="filter-item"><a class="filter-active" data-taxonomy="" href="#">' . $filterText . '</a></li>';
1599 }
1600 if ( $filterValue ) {
1601 $filterValue = strlen( $filterValue ) > 2 ? $filterValue : array();
1602 $filterValue = is_array( $filterValue ) ? $filterValue : json_decode( $filterValue );
1603 if ( is_array( $filterValue ) && count( $filterValue ) ) {
1604 foreach ( $filterValue as $val ) {
1605 $val = isset( $val->value ) ? $val->value : $val;
1606 $html .= '<li class="filter-item"><a data-taxonomy="' . $val . '" href="#">' . ( isset( $cat[ $val ] ) ? $cat[ $val ] : $val ) . '</a></li>';
1607 }
1608 }
1609 }
1610 $html .= '</ul>';
1611 return $html;
1612 }
1613
1614
1615 /**
1616 * Check License Status
1617 *
1618 * @since v.2.4.2
1619 * @return BOOLEAN | Is pro license active or not
1620 */
1621 public function is_lc_active() {
1622 return Xpo::is_lc_active();
1623 }
1624
1625
1626 /**
1627 * Check if a pro feature is visible based on license expiration date.
1628 *
1629 * @since v.2.4.2
1630 * @param STRING $date Date to compare with license expiration.
1631 * @return BOOL True if the pro feature is visible, false otherwise.
1632 */
1633 public function is_pro_feature_visible( $date ) {
1634 if ( function_exists( 'ultimate_post_pro' ) ) {
1635 $license_data = get_option( 'edd_ultp_license_data' );
1636 if ( isset( $license_data['expires'] ) ) {
1637 $expires = $license_data['expires'];
1638 if ( 'lifetime' === $expires ) {
1639 return true;
1640 }
1641 return strtotime( $date ) < strtotime( $expires );
1642 }
1643 return true;
1644 }
1645 return false;
1646 }
1647
1648 /**
1649 * Get SEO Meta
1650 *
1651 * @since v.2.4.3
1652 * @param INT $post_id Post ID.
1653 * @param INT $show_seo_meta Show SEO meta flag.
1654 * @param INT $show_full_excerpt Show full excerpt flag.
1655 * @param INT $excerpt_limit Excerpt word limit.
1656 * @return STRING SEO Meta Description or Excerpt.
1657 */
1658 public function get_excerpt( $post_id = 0, $show_seo_meta = 0, $show_full_excerpt = 0, $excerpt_limit = 55 ) {
1659 $html = '';
1660 if ( $show_seo_meta ) {
1661 $str = '';
1662 if ( function_exists( 'ultimate_post_pro' ) ) {
1663 if ( ultimate_post()->get_setting( 'ultp_yoast' ) == 'true' ) {
1664 $str = method_exists( ultimate_post_pro(), 'get_yoast_meta' ) ? ultimate_post_pro()->get_yoast_meta( $post_id ) : '';
1665 } elseif ( ultimate_post()->get_setting( 'ultp_rankmath' ) == 'true' ) {
1666 $str = method_exists( ultimate_post_pro(), 'get_rankmath_meta' ) ? ultimate_post_pro()->get_rankmath_meta( $post_id ) : '';
1667 } elseif ( ultimate_post()->get_setting( 'ultp_aioseo' ) == 'true' ) {
1668 $str = method_exists( ultimate_post_pro(), 'get_aioseo_meta' ) ? ultimate_post_pro()->get_aioseo_meta( $post_id ) : '';
1669 } elseif ( ultimate_post()->get_setting( 'ultp_seopress' ) == 'true' ) {
1670 $str = method_exists( ultimate_post_pro(), 'get_seopress_meta' ) ? ultimate_post_pro()->get_seopress_meta( $post_id ) : '';
1671 } elseif ( ultimate_post()->get_setting( 'ultp_squirrly' ) == 'true' ) {
1672 $str = method_exists( ultimate_post_pro(), 'get_squirrly_meta' ) ? ultimate_post_pro()->get_squirrly_meta( $post_id ) : '';
1673 }
1674 }
1675 $html = $str ? $str : ultimate_post()->excerpt( $post_id, $excerpt_limit );
1676 } elseif ( $show_full_excerpt == 0 ) {
1677 $html = ultimate_post()->excerpt( $post_id, $excerpt_limit );
1678 } else {
1679 $html = get_the_excerpt();
1680 }
1681 return $html;
1682 }
1683
1684 /**
1685 * Get embedded video HTML.
1686 *
1687 * @since v.1.0.0
1688 * @param STRING $url Video URL.
1689 * @param BOOL $autoPlay Whether to autoplay the video.
1690 * @param BOOL $loop Whether to loop the video.
1691 * @param BOOL $mute Whether to mute the video.
1692 * @param BOOL $playback Whether to show playback controls.
1693 * @param STRING $preload Preload attribute value.
1694 * @param ARRAY | string $poster Poster image for the video.
1695 * @param BOOL $inline Whether to play inline.
1696 * @param ARRAY | string $size Size for oEmbed.
1697 * @return STRING | false Video embed HTML or false on failure.
1698 */
1699 public function get_embeded_video( $url, $autoPlay, $loop, $mute, $playback, $preload, $poster, $inline, $size ) {
1700 $vidAutoPlay = $vidloop = $vidloop = $vidmute = $vidplayback = $vidPoster = $vidInline = '';
1701
1702 if ( $autoPlay ) {
1703 $vidAutoPlay = 'autoplay';
1704 }
1705 if ( $poster ) {
1706 $vidPoster = 'poster="' . $poster['url'] . '"';
1707 }
1708 if ( $loop ) {
1709 $vidloop = 'loop';
1710 }
1711 if ( $mute ) {
1712 $vidmute = 'muted';
1713 }
1714 if ( $playback ) {
1715 $vidplayback = 'controls';
1716 }
1717 if ( $inline ) {
1718 $vidInline = 'playsinline';
1719 }
1720 if ( ! empty( $url ) ) {
1721 $embeded = wp_oembed_get( $url, $size );
1722 if ( $embeded == false ) {
1723 $format = '';
1724 $url = strtolower( $url );
1725 if ( strpos( $url, '.mp4' ) ) {
1726 $format = 'mp4';
1727 } elseif ( strpos( $url, '.ogg' ) ) {
1728 $format = 'ogg';
1729 } elseif ( strpos( $url, '.webm' ) ) {
1730 $format = 'WebM';
1731 }
1732 $embeded = '<video
1733 ' . $vidloop . '
1734 ' . $vidmute . '
1735 ' . $vidplayback . '
1736 preload="' . $preload . '"
1737 ' . $vidAutoPlay . '
1738 ' . $vidPoster . '
1739 ' . $vidInline . '
1740 class="ultp-video-html"
1741 ><source src="' . $url . '" type="video/' . $format . '">' . __( 'Your browser does not support the video tag.', 'ultimate-post' ) . '</video>';
1742 return '<div class="ultp-video-wrapper">' . $embeded . '</div>';
1743 }
1744 return '<div class="ultp-video-wrapper ultp-embaded-video">' . $embeded . '</div>';
1745 } else {
1746 return false;
1747 }
1748 }
1749
1750 /**
1751 * Get Public taxonomy Lists
1752 *
1753 * @since v.2.7.0
1754 * @return ARRAY | Taxonomy Lists as array
1755 */
1756 public function get_taxonomy_list() {
1757 $taxonomy = get_taxonomies( array( 'public' => true ) );
1758 return empty( $taxonomy ) ? array() : array_keys( $taxonomy );
1759 }
1760
1761 /**
1762 * Content Print
1763 *
1764 * @since v.2.7.0
1765 * @param int $post_id Post ID.
1766 * @param string $builder_type Builder type.
1767 * @return void | Content of the Post
1768 */
1769 public function get_post_content( $post_id, $builder_type = '' ) {
1770 $content_post = get_post( $post_id );
1771 $content = $content_post->post_content;
1772 if ( $builder_type == 'divi' || $builder_type == 'elementor' ) {
1773 $content = apply_filters( 'the_content', $content );
1774 } else {
1775 global $wp_embed;
1776 $content = $wp_embed->autoembed( $content );
1777 $content = do_blocks( $content );
1778 $content = do_shortcode( $content );
1779 }
1780 $content = str_replace( ']]>', ']]&gt;', $content );
1781 $content = preg_replace( '%<p>&nbsp;\s*</p>%', '', $content );
1782 $content = preg_replace( '/^(?:<br\s*\/?>\s*)+/', '', $content );
1783 echo $content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1784 }
1785
1786 /**
1787 * String Part finder inside array.
1788 *
1789 * @since v.2.7.0 updated 4.1.12
1790 *
1791 * @param STRING $part The part of the string to search for.
1792 * @param ARRAY $data The array to search within.
1793 * @param STRING $toR Return type: 'bool', 'value', or default (array).
1794 * @return MIXED Returns true/false, value, or array depending on $toR.
1795 * @since v.2.7.0 updated 4.1.12
1796 */
1797 public function in_array_part( $part, $data, $toR = '' ) {
1798 $res = array();
1799 foreach ( $data as $key => $val ) {
1800 if ( strpos( $val, $part ) !== false ) {
1801 if ( $toR == 'bool' ) {
1802 return true;
1803 } elseif ( $toR == 'value' ) {
1804 return $val;
1805 }
1806 $res[ $key ] = $val;
1807 }
1808 }
1809 if ( $toR == 'bool' ) {
1810 return false;
1811 } elseif ( $toR == 'value' ) {
1812 return '';
1813 }
1814 return $res;
1815 }
1816
1817 /**
1818 * Builder Conditions
1819 *
1820 * @since v.2.7.0 updated 4.1.12
1821 * @param STRING $type Type of return value.
1822 * @param MIXED $cus_condition Custom conditions array or value.
1823 * @return MIXED ID or Path.
1824 */
1825 public function builder_check_conditions( $type = 'return', $cus_condition = '' ) {
1826 $page_id = '';
1827 $conditions = $cus_condition ? $cus_condition : get_option( 'ultp_builder_conditions', array() );
1828
1829 if ( $type == 'header' || $type == 'footer' ) {
1830 if ( ! empty( $conditions[ $type ] ) ) {
1831 foreach ( $conditions[ $type ] as $key => $val ) {
1832 if ( 'publish' == get_post_status( $key ) && ! empty( $val ) ) {
1833 if ( in_array( 'include/' . $type . '/entire_site', $val ) ) {
1834 $page_id = $key;
1835 } elseif ( in_array( 'exclude/' . $type . '/entire_site', $val ) ) {
1836 $page_id = '';
1837 }
1838
1839 $c_page = ( is_archive() || is_search() ) ? 'archive' : 'singular';
1840 $hf_archive = $this->in_array_part( $type . '/' . $c_page, $val, '' );
1841 if ( ! empty( $hf_archive ) ) {
1842 foreach ( $hf_archive as $k => $v ) {
1843 if ( strpos( $v, 'include/' . $type . '/' . $c_page ) !== false ) {
1844 $temp = $this->builder_check_conditions( 'return_' . $type, array( $c_page => array( $key => array( str_replace( $type . '/', '', $v ) ) ) ) );
1845 $page_id = $temp ? $temp : $page_id;
1846 } elseif ( strpos( $v, 'exclude/' . $type . '/' . $c_page ) !== false ) {
1847 $temp = $this->builder_check_conditions( 'return_' . $type, array( $c_page => array( $key => array( str_replace( 'exclude/' . $type, 'include', $v ) ) ) ) );
1848 $page_id = $temp ? '' : $page_id;
1849 }
1850 }
1851 }
1852 }
1853 }
1854 }
1855 } else {
1856 // 404 page .
1857 if ( ! empty( $conditions['404'] ) && is_404() ) {
1858 foreach ( $conditions['404'] as $key => $val ) {
1859 if ( 'publish' == get_post_status( $key ) ) {
1860 $page_id = $key;
1861 }
1862 }
1863 }
1864 // Singular or Front Page .
1865 elseif (
1866 (
1867 ! empty( $conditions['singular'] ) ||
1868 ! empty( $conditions['front_page'] )
1869 ) &&
1870 (
1871 is_singular() ||
1872 is_front_page() ||
1873 is_home()
1874 )
1875 ) {
1876 $obj = get_queried_object();
1877 $queried_is_obj = is_object( $obj );
1878 // front page only .
1879 if (
1880 ( is_front_page() && is_home() ) ||
1881 ( is_home() && ! $queried_is_obj ) ||
1882 ( is_singular() && is_front_page() && $queried_is_obj )
1883 ) {
1884 $f_conditions = array();
1885 if ( ! empty( $conditions['front_page'] ) ) {
1886 $f_conditions = $conditions['front_page'];
1887 } elseif ( ! empty( $conditions['singular'] ) ) {
1888 $f_conditions = $conditions['singular'];
1889 }
1890 if ( ! empty( $f_conditions ) ) {
1891 foreach ( $f_conditions as $key => $val ) {
1892 if ( ( is_array( $val ) && in_array( 'include/singular/front_page', $val ) ) ||
1893 ( is_array( $val ) && in_array( 'include/front_page', $val ) ) ||
1894 'include/front_page' == $val
1895 ) {
1896 if ( 'publish' == get_post_status( $key ) ) {
1897 $page_id = $key;
1898 }
1899 }
1900 // Default Front / Home page Header Footer Compatibility .
1901 elseif ( is_array( $val ) && 'publish' == get_post_status( $key ) && ( $type == 'return_header' || $type == 'return_footer' ) ) {
1902 $base_include = 'include/singular/' . $obj->post_type;
1903 $base_exclude = 'exclude/singular/' . $obj->post_type;
1904 $specific_include = $base_include . '/' . $obj->ID;
1905 $specific_exclude = $base_exclude . '/' . $obj->ID;
1906
1907 if ( in_array( $specific_include, $val ) ) {
1908 $page_id = $key;
1909 } elseif ( in_array( $specific_exclude, $val ) ) {
1910 $page_id = '';
1911 } elseif ( in_array( $base_include, $val ) ) {
1912 $page_id = $key;
1913 } elseif ( in_array( $base_exclude, $val ) ) {
1914 $page_id = '';
1915 }
1916 }
1917 }
1918 }
1919 }
1920 // Singular page .
1921 elseif ( ! empty( $conditions['singular'] ) ) {
1922 foreach ( $conditions['singular'] as $key => $val ) {
1923 if ( 'publish' == get_post_status( $key ) ) {
1924 // All Post Type. -----Prority 1 .
1925 if ( $queried_is_obj ) {
1926 if ( in_array( 'include/singular/' . $obj->post_type, $val ) ) {
1927 $page_id = $key;
1928 } elseif ( in_array( 'exclude/singular/' . $obj->post_type, $val ) ) {
1929 $page_id = '';
1930 }
1931 }
1932
1933 $singular_in_tax = $this->in_array_part( '/singular/in_', $val, '' );
1934 if ( ! empty( $singular_in_tax ) ) {
1935 $tax_list = $this->get_taxonomy_list();
1936 foreach ( $tax_list as $tax ) {
1937 if ( in_array( 'include/singular/in_' . $tax . '_children', $singular_in_tax ) ) {
1938 $page_id = $key;
1939 } elseif ( in_array( 'exclude/singular/in_' . $tax . '_children', $singular_in_tax ) ) {
1940 $page_id = '';
1941 }
1942
1943 if ( $queried_is_obj ) {
1944 $singular_in_tax_children = $this->in_array_part( '/singular/in_' . $tax . '_children/', $singular_in_tax, '' );
1945 foreach ( $singular_in_tax_children as $v ) {
1946 $data = explode( '/', $v );
1947 if ( isset( $data[3] ) && $data[3] ) {
1948 $childs = get_term_children( $data[3], $tax );
1949 if ( ! empty( $childs ) && has_term( $childs, $tax ) ) {
1950 $page_id = $data[0] == 'exclude' ? '' : $key;
1951 }
1952 }
1953 }
1954 }
1955
1956 if ( in_array( 'include/singular/in_' . $tax, $singular_in_tax ) ) {
1957 if ( $tax == 'post_tag' && $queried_is_obj ) {
1958 $cat = get_the_terms( $obj->ID, 'post_tag' );
1959 if ( ! empty( $cat ) ) {
1960 $page_id = $key;
1961 }
1962 } else {
1963 $page_id = $key;
1964 }
1965 } elseif ( in_array( 'exclude/singular/in_' . $tax, $singular_in_tax ) ) {
1966 $page_id = '';
1967 }
1968
1969 if ( $queried_is_obj ) {
1970 $singular_in_tax_only = $this->in_array_part( '/singular/in_' . $tax . '/', $singular_in_tax, '' );
1971 foreach ( $singular_in_tax_only as $v ) {
1972 $data = explode( '/', $v );
1973 if ( isset( $data[3] ) && $data[3] ) {
1974 if ( is_object_in_term( $obj->ID, $tax, $data[3] ) ) {
1975 $page_id = $data[0] == 'exclude' ? '' : $key;
1976 }
1977 }
1978 }
1979 }
1980 }
1981 }
1982
1983 // Posts by author -----Prority 9 .
1984 if ( in_array( 'include/singular/post_by_author', $val ) ) {
1985 $page_id = $key;
1986 } elseif ( in_array( 'exclude/singular/post_by_author', $val ) ) {
1987 $page_id = '';
1988 }
1989 if ( $queried_is_obj ) {
1990 if ( in_array( 'include/singular/post_by_author/' . $obj->post_author, $val ) ) {
1991 $page_id = $key;
1992 } elseif ( in_array( 'exclude/singular/post_by_author/' . $obj->post_author, $val ) ) {
1993 $page_id = '';
1994 }
1995 // Post Type with specific id -----Prority 10 .
1996 if ( in_array( 'include/singular/' . $obj->post_type . '/' . $obj->ID, $val ) ) {
1997 $page_id = $key;
1998 } elseif ( in_array( 'exclude/singular/' . $obj->post_type . '/' . $obj->ID, $val ) ) {
1999 $page_id = '';
2000 }
2001 }
2002 }
2003 }
2004 }
2005 }
2006
2007 // Archive and Search Page .
2008 elseif ( ! empty( $conditions['archive'] ) ) {
2009 // Search Page .
2010 if ( is_search() ) {
2011 foreach ( $conditions['archive'] as $key => $val ) {
2012 if ( 'publish' == get_post_status( $key ) ) {
2013 if ( in_array( 'include/archive/search', $val ) ) {
2014 $page_id = $key;
2015 } elseif ( in_array( 'exclude/archive/search', $val ) ) {
2016 $page_id = '';
2017 }
2018 }
2019 }
2020 }
2021 // Archive Page .
2022 elseif ( is_archive() ) {
2023 $is_cat = is_category();
2024 $is_tag = is_tag();
2025 $is_tax = is_tax();
2026 $is_date = is_date();
2027 $is_author = is_author();
2028 $taxonomy = ( $is_cat || $is_tag || $is_tax ) ? get_queried_object() : (object) array();
2029
2030 foreach ( $conditions['archive'] as $key => $val ) {
2031 if ( 'publish' == get_post_status( $key ) ) {
2032 // This section is for all archive page .
2033 if ( in_array( 'include/archive', $val ) ) {
2034 $page_id = $key;
2035 } elseif ( in_array( 'exclude/archive', $val ) ) {
2036 $page_id = '';
2037 }
2038 // For Category .
2039 if ( $is_cat ) {
2040 // all category .
2041 if ( in_array( 'include/archive/category', $val ) ) {
2042 $page_id = $key;
2043 } elseif ( in_array( 'exclude/archive/category', $val ) ) {
2044 $page_id = '';
2045 }
2046 // specific category .
2047 if ( in_array( 'include/archive/category/' . $taxonomy->term_id, $val ) ) {
2048 $page_id = $key;
2049 } elseif ( in_array( 'exclude/archive/category/' . $taxonomy->term_id, $val ) ) {
2050 $page_id = '';
2051 }
2052
2053 // any child of category .
2054 if ( in_array( 'include/archive/any_child_of_category', $val ) ) {
2055 $page_id = $key;
2056 } elseif ( in_array( 'exclude/archive/any_child_of_category', $val ) ) {
2057 $page_id = '';
2058 }
2059
2060 $any_child_of_cat = $this->in_array_part( 'archive/any_child_of_category/', $val, '' );
2061 if ( ! empty( $any_child_of_cat ) ) {
2062 foreach ( $any_child_of_cat as $v ) {
2063 $data = explode( '/', $v );
2064 if ( isset( $data[3] ) && $data[3] ) {
2065 if ( term_is_ancestor_of( $data[3], $taxonomy->term_id, 'category' ) ) {
2066 $page_id = $data[0] == 'exclude' ? '' : $key;
2067 }
2068 }
2069 }
2070 }
2071
2072 // all child of category .
2073 if ( in_array( 'include/archive/child_of_category', $val ) ) {
2074 $page_id = $key;
2075 } elseif ( in_array( 'exclude/archive/child_of_category', $val ) ) {
2076 $page_id = '';
2077 }
2078 // specific child of category .
2079 if ( in_array( 'include/archive/child_of_category/' . $taxonomy->parent, $val ) ) {
2080 $page_id = $key;
2081 } elseif ( in_array( 'exclude/archive/child_of_category/' . $taxonomy->parent, $val ) ) {
2082 $page_id = '';
2083 }
2084 }
2085 // For Tag .
2086 elseif ( $is_tag ) {
2087 if ( in_array( 'include/archive/post_tag', $val ) ) {
2088 $page_id = $key;
2089 } elseif ( in_array( 'exclude/archive/post_tag', $val ) ) {
2090 $page_id = '';
2091 }
2092 if ( in_array( 'include/archive/post_tag/' . $taxonomy->term_id, $val ) ) {
2093 $page_id = $key;
2094 } elseif ( in_array( 'exclude/archive/post_tag/' . $taxonomy->term_id, $val ) ) {
2095 $page_id = '';
2096 }
2097 }
2098 // Other taxonomy .
2099 elseif ( $is_tax ) {
2100 if ( in_array( 'include/archive/' . $taxonomy->taxonomy, $val ) ) {
2101 $page_id = $key;
2102 } elseif ( in_array( 'exclude/archive/' . $taxonomy->taxonomy, $val ) ) {
2103 $page_id = '';
2104 }
2105
2106 if ( in_array( 'include/archive/' . $taxonomy->taxonomy . '/' . $taxonomy->term_id, $val ) ) {
2107 $page_id = $key;
2108 } elseif ( in_array( 'exclude/archive/' . $taxonomy->taxonomy . '/' . $taxonomy->term_id, $val ) ) {
2109 $page_id = '';
2110 }
2111
2112 if ( in_array( 'include/archive/any_child_of_' . $taxonomy->taxonomy, $val ) ) {
2113 $page_id = $key;
2114 } elseif ( in_array( 'exclude/archive/any_child_of_' . $taxonomy->taxonomy, $val ) ) {
2115 $page_id = '';
2116 }
2117
2118 $any_child_of_tax = $this->in_array_part( 'archive/any_child_of_' . $taxonomy->taxonomy . '/', $val, '' );
2119 if ( ! empty( $any_child_of_tax ) ) {
2120 foreach ( $any_child_of_tax as $v ) {
2121 $data = explode( '/', $v );
2122 if ( isset( $data[3] ) && $data[3] ) {
2123 if ( term_is_ancestor_of( $data[3], $taxonomy->term_id, $taxonomy->taxonomy ) ) {
2124 $page_id = $data[0] == 'exclude' ? '' : $key;
2125 }
2126 }
2127 }
2128 }
2129
2130 if ( in_array( 'include/archive/child_of_' . $taxonomy->taxonomy, $val ) ) {
2131 $page_id = $key;
2132 } elseif ( in_array( 'exclude/archive/child_of_' . $taxonomy->taxonomy, $val ) ) {
2133 $page_id = '';
2134 }
2135
2136 if ( in_array( 'include/archive/child_of_' . $taxonomy->taxonomy . '/' . $taxonomy->parent, $val ) ) {
2137 $page_id = $key;
2138 } elseif ( in_array( 'exclude/archive/child_of_' . $taxonomy->taxonomy . '/' . $taxonomy->parent, $val ) ) {
2139 $page_id = '';
2140 }
2141 }
2142 // For Date.
2143 elseif ( $is_date ) {
2144 if ( in_array( 'include/archive/date', $val ) ) {
2145 $page_id = $key;
2146 } elseif ( in_array( 'exclude/archive/date', $val ) ) {
2147 $page_id = '';
2148 }
2149 }
2150 // For Author.
2151 elseif ( $is_author ) {
2152 if ( in_array( 'include/archive/author', $val ) ) {
2153 $page_id = $key;
2154 } elseif ( in_array( 'exclude/archive/author', $val ) ) {
2155 $page_id = '';
2156 }
2157 $author_id = get_the_author_meta( 'ID' );
2158 if ( in_array( 'include/archive/author/' . $author_id, $val ) ) {
2159 $page_id = $key;
2160 } elseif ( in_array( 'exclude/archive/author/' . $author_id, $val ) ) {
2161 $page_id = '';
2162 }
2163 }
2164 }
2165 }
2166 }
2167 }
2168 }
2169 return $page_id;
2170 }
2171
2172 /**
2173 * Get Date Default Format
2174 *
2175 * @since v.2.7.2
2176 * @param STRING $format Format type.
2177 * @return ARRAY | Default Data
2178 */
2179 public function get_format( $format ) {
2180 if ( $format == 'default_date' ) {
2181 return get_option( 'date_format' );
2182 } elseif ( $format == 'default_date_time' ) {
2183 return get_option( 'date_format' ) . ' ' . get_option( 'time_format' );
2184 } else {
2185 return $format;
2186 }
2187 }
2188
2189 /**
2190 * Common Frontend and Backend CSS and JS Scripts
2191 *
2192 * @since v.1.0.0
2193 */
2194 public function register_scripts_common() {
2195 if ( ! ( isset( $GLOBALS['wp_scripts'] ) && isset( $GLOBALS['wp_scripts']->registered ) && isset( $GLOBALS['wp_scripts']->registered['ultp-script'] ) ) ) {
2196 wp_enqueue_style( 'ultp-style', ULTP_URL . 'assets/css/style.min.css', array(), ULTP_VER );
2197 wp_enqueue_script( 'ultp-script', ULTP_URL . 'assets/js/ultp.min.js', array( 'jquery', 'wp-api-fetch' ), ULTP_VER, true );
2198 wp_localize_script(
2199 'ultp-script',
2200 'ultp_data_frontend',
2201 array(
2202 'url' => ULTP_URL,
2203 'active' => ultimate_post()->is_lc_active(),
2204 'ultpSavedDLMode' => ultimate_post()->get_dl_mode(),
2205 'ajax' => admin_url( 'admin-ajax.php' ),
2206 'security' => wp_create_nonce( 'ultp-nonce' ),
2207 'home_url' => home_url(),
2208 'dark_logo' => get_option( 'ultp_site_dark_logo', false ),
2209 )
2210 );
2211 }
2212 }
2213
2214 /**
2215 * Get Dark Light Mode
2216 *
2217 * @since 4.0.0
2218 * @return STRING | Dark Light Mode .
2219 */
2220 public function get_dl_mode() {
2221 $data = get_option( 'postx_global', array() );
2222 $mode = 'ultplight';
2223 if ( ! empty( $data ) ) {
2224 $mode = isset( $data['enableDark'] ) && $data['enableDark'] ? 'ultpdark' : 'ultplight';
2225 }
2226 return $mode;
2227 }
2228
2229 /**
2230 * Get Page Post Id ( Kadence element )
2231 *
2232 * @since v.2.8.9
2233 * @param STRING|INT $blockId Block ID to search for.
2234 * @return NULL
2235 */
2236 public function get_page_post_id( $blockId ) {
2237 global $wpdb;
2238 $post_meta = $wpdb->get_row( $wpdb->prepare( 'SELECT post_id FROM ' . $wpdb->prefix . 'postmeta WHERE meta_key=%s AND meta_value LIKE %s', '_ultp_css', '%.ultp-block-' . $blockId . '%' ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching
2239 // For FSE theme
2240 if ( ! $post_meta ) {
2241 if ( wp_is_block_theme() ) {
2242 $template = $wpdb->get_row( $wpdb->prepare( 'SELECT ID FROM ' . $wpdb->prefix . 'posts WHERE post_content LIKE %s', '%"blockId":"' . $blockId . '"%' ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching
2243 if ( isset( $template->ID ) ) {
2244 return $template->ID;
2245 }
2246 }
2247 }
2248 if ( $post_meta && isset( $post_meta->post_id ) ) {
2249 return $post_meta->post_id;
2250 }
2251 return ultimate_post()->get_ID();
2252 }
2253
2254
2255 /**
2256 * Get no Result found html
2257 *
2258 * @since v.2.9.0
2259 * @param STRING $text No result found text.
2260 * @return STRING | Taxonomy Lists as array
2261 */
2262 public function get_no_result_found_html( $text ) {
2263 return $text ? '<div class="ultp-not-found-message" role="alert">' . wp_kses( $text, ultimate_post()->ultp_allowed_html_tags() ) . '</div>' : '';
2264 }
2265
2266 /**
2267 * Get all Saved Templates Lists
2268 *
2269 * @since v.2.9.9
2270 * @param STRING $post_type Post type to retrieve.
2271 * @param STRING $empty Empty value for the select field.
2272 * @return STRING | Taxonomy Lists as array
2273 */
2274 public function get_all_lists( $post_type = 'post', $empty = '' ) {
2275 $args = array(
2276 'post_type' => $post_type,
2277 'post_status' => 'publish',
2278 'posts_per_page' => -1,
2279 );
2280 $loop = new \WP_Query( $args );
2281 $data[ $empty ? $empty : '' ] = __( '- Select Template -', 'ultimate-post' );
2282 if ( $loop->have_posts() ) {
2283 foreach ( $loop->posts as $post ) {
2284 $data[ $post->ID ] = $post->post_title;
2285 }
2286 }
2287 wp_reset_postdata();
2288 return $data;
2289 }
2290
2291 /**
2292 * Get ID from the Youtube URL
2293 *
2294 * @since v.3.1.7
2295 * @param STRING $url The Youtube URL .
2296 * @return STRING | Taxonomy Lists as array
2297 */
2298 public function get_youtube_id( $url = '' ) {
2299 if ( strpos( $url, 'youtu' ) !== false ) {
2300 $reg = '/youtu(?:.*\/v\/|.*v\=|\.be\/)([A-Za-z0-9_\-]{11})/m';
2301 preg_match( $reg, $url, $matches );
2302 if ( isset( $matches[1] ) ) {
2303 return $matches[1];
2304 }
2305 }
2306 return false;
2307 }
2308
2309 /**
2310 * Get Option Value bypassing cache
2311 * Inspired By WordPress Core get_option
2312 *
2313 * @since v.3.1.6
2314 * @param STRING $option Option Name.
2315 * @param BOOLEAN $default_value option default value.
2316 * @return mixed
2317 */
2318 public function get_option_without_cache( $option, $default_value = false ) {
2319 global $wpdb;
2320
2321 if ( is_scalar( $option ) ) {
2322 $option = trim( $option );
2323 }
2324
2325 if ( empty( $option ) ) {
2326 return false;
2327 }
2328
2329 $value = $default_value;
2330
2331 $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching
2332
2333 if ( is_object( $row ) ) {
2334 $value = $row->option_value;
2335 } else {
2336 return apply_filters( "ultp_default_option_{$option}", $default_value, $option );
2337 }
2338
2339 return apply_filters( "ultp_option_{$option}", maybe_unserialize( $value ), $option );
2340 }
2341
2342 /**
2343 * Get Transient Value bypassing cache
2344 * Inspired By WordPress Core get_transient
2345 *
2346 * @since v.3.1.6
2347 * @param STRING $transient Transient Name.
2348 * @return MIXED
2349 */
2350 public function get_transient_without_cache( $transient ) {
2351 $transient_option = '_transient_' . $transient;
2352 $transient_timeout = '_transient_timeout_' . $transient;
2353 $timeout = $this->get_option_without_cache( $transient_timeout );
2354
2355 if ( false !== $timeout && $timeout < time() ) {
2356 delete_option( $transient_option );
2357 delete_option( $transient_timeout );
2358 $value = false;
2359 }
2360
2361 if ( ! isset( $value ) ) {
2362 $value = $this->get_option_without_cache( $transient_option );
2363 }
2364
2365 return apply_filters( "ultp_transient_{$transient}", $value, $transient );
2366 }
2367
2368 /**
2369 * Set transient without adding to the cache
2370 * Inspired By WordPress Core set_transient
2371 *
2372 * @since v.3.1.6
2373 * @param STRING $transient Transient Name.
2374 * @param MIXED $value Transient Value.
2375 * @param INTEGER $expiration Time until expiration in seconds.
2376 * @return BOOL
2377 */
2378 public function set_transient_without_cache( $transient, $value, $expiration = 0 ) {
2379 $expiration = (int) $expiration;
2380
2381 $transient_timeout = '_transient_timeout_' . $transient;
2382 $transient_option = '_transient_' . $transient;
2383
2384 $result = false;
2385
2386 if ( false === $this->get_option_without_cache( $transient_option ) ) {
2387 $autoload = 'yes';
2388 if ( $expiration ) {
2389 $autoload = 'no';
2390 $this->add_option_without_cache( $transient_timeout, time() + $expiration, 'no' );
2391 }
2392 $result = $this->add_option_without_cache( $transient_option, $value, $autoload );
2393 } else {
2394 /*
2395 * If expiration is requested, but the transient has no timeout option,
2396 * delete, then re-create transient rather than update.
2397 */
2398 $update = true;
2399
2400 if ( $expiration ) {
2401 if ( false === $this->get_option_without_cache( $transient_timeout ) ) {
2402 delete_option( $transient_option );
2403 $this->add_option_without_cache( $transient_timeout, time() + $expiration, 'no' );
2404 $result = $this->add_option_without_cache( $transient_option, $value, 'no' );
2405 $update = false;
2406 } else {
2407 update_option( $transient_timeout, time() + $expiration );
2408 }
2409 }
2410
2411 if ( $update ) {
2412 $result = update_option( $transient_option, $value );
2413 }
2414 }
2415
2416 return $result;
2417 }
2418
2419 /**
2420 * Add option without adding to the cache
2421 * Inspired By WordPress Core set_transient
2422 *
2423 * @since v.3.1.6
2424 * @param STRING $option option name.
2425 * @param STRING $value option value.
2426 * @param STRING $autoload whether to load WordPress startup.
2427 * @return BOOL
2428 */
2429 public function add_option_without_cache( $option, $value = '', $autoload = 'yes' ) {
2430 global $wpdb;
2431
2432 if ( is_scalar( $option ) ) {
2433 $option = trim( $option );
2434 }
2435
2436 if ( empty( $option ) ) {
2437 return false;
2438 }
2439
2440 wp_protect_special_option( $option );
2441
2442 if ( is_object( $value ) ) {
2443 $value = clone $value;
2444 }
2445
2446 $value = sanitize_option( $option, $value );
2447
2448 /*
2449 * Make sure the option doesn't already exist.
2450 */
2451
2452 if ( apply_filters( "ultp_default_option_{$option}", false, $option, false ) !== $this->get_option_without_cache( $option ) ) {
2453 return false;
2454 }
2455
2456 $serialized_value = maybe_serialize( $value );
2457 $autoload = ( 'no' === $autoload || false === $autoload ) ? 'no' : 'yes';
2458
2459 $result = $wpdb->query( $wpdb->prepare( "INSERT INTO `$wpdb->options` (`option_name`, `option_value`, `autoload`) VALUES (%s, %s, %s) ON DUPLICATE KEY UPDATE `option_name` = VALUES(`option_name`), `option_value` = VALUES(`option_value`), `autoload` = VALUES(`autoload`)", $option, $serialized_value, $autoload ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching
2460 if ( ! $result ) {
2461 return false;
2462 }
2463
2464 return true;
2465 }
2466
2467 /**
2468 * Permission_check_for_restapi
2469 *
2470 * @since v.3.2.4
2471 * @param STRING/Bool $post_id .
2472 * @param STRING $cap STRING .
2473 * @return BOOL
2474 */
2475 public function permission_check_for_restapi( $post_id = false, $cap = '' ) {
2476 $cap = $cap ? $cap : 'edit_others_posts';
2477 $is_passed = false;
2478 if ( $post_id ) {
2479 $post_author = (int) get_post_field( 'post_author', $post_id );
2480 $is_passed = (int) get_current_user_id() === $post_author;
2481 }
2482 return $is_passed || current_user_can( $cap );
2483 }
2484
2485 /**
2486 * Sanitize params
2487 *
2488 * @param MIXED $params Parameters to sanitize.
2489 * @return array|bool|mixed|string
2490 * @since v.4.0.0
2491 */
2492 public function ultp_rest_sanitize_params( $params ) {
2493 if ( is_array( $params ) ) {
2494 return array_map( array( $this, 'ultp_rest_sanitize_params' ), $params );
2495 } elseif ( is_bool( $params ) ) {
2496 return rest_sanitize_boolean( $params );
2497 } elseif ( is_object( $params ) ) {
2498 return $params;
2499 } else {
2500 return sanitize_text_field( $params );
2501 }
2502 }
2503
2504 /**
2505 * Get Adv Filter Data Attributes
2506 *
2507 * @param ARRAY|NULL $attr .
2508 * @param ARRAY|NULL $filter_attributes .
2509 * @return string
2510 * @since v.3.2.5
2511 */
2512 public function get_adv_data_attrs( $attr, $filter_attributes = null ) {
2513 // Adv Filter Integration.
2514 $adv_filter_dataset = array();
2515
2516 if ( $filter_attributes ) {
2517 $adv_filter_dataset[] = 'data-filter-value="' . htmlspecialchars( $filter_attributes['queryTaxValue'] ) . '"';
2518 $adv_filter_dataset[] = 'data-filter-type="' . htmlspecialchars( $filter_attributes['queryTax'] ) . '"';
2519
2520 $is_adv = isset( $filter_attributes['isAdv'] ) ? $filter_attributes['isAdv'] : 0;
2521 $adv_filter_dataset[] = 'data-filter-is-adv="' . $is_adv . '"';
2522
2523 if ( $is_adv ) {
2524 if ( isset( $filter_attributes['queryAuthor'] ) ) {
2525 $adv_filter_dataset[] = "data-filter-author='" . $filter_attributes['queryAuthor'] . "'";
2526 }
2527
2528 if ( isset( $filter_attributes['queryOrder'] ) ) {
2529 $adv_filter_dataset[] = "data-filter-order='" . $filter_attributes['queryOrder'] . "'";
2530 }
2531
2532 if ( isset( $filter_attributes['queryOrderBy'] ) ) {
2533 $adv_filter_dataset[] = "data-filter-orderby='" . $filter_attributes['queryOrderBy'] . "'";
2534 }
2535
2536 if ( isset( $filter_attributes['search'] ) ) {
2537 $adv_filter_dataset[] = 'data-filter-search="' . $filter_attributes['search'] . '"';
2538 }
2539
2540 if ( isset( $filter_attributes['queryQuick'] ) && $filter_attributes['queryQuick'] ) {
2541 $adv_filter_dataset[] = 'data-filter-adv-sort="' . $filter_attributes['queryQuick'] . '"';
2542 }
2543 }
2544 }
2545
2546 if ( $attr && isset( $attr['advFilterEnable'] ) && $attr['advFilterEnable'] ) {
2547 $adv_filter_dataset[] = 'data-filter-is-adv="1"';
2548 $adv_filter_dataset[] = 'data-filter-type="multiTaxonomy"';
2549
2550 $data_filter_value = isset( $attr['filterValue'] ) && $attr['filterValue'] ? $attr['filterValue'] : '[]';
2551 $adv_filter_dataset[] = 'data-filter-value="' . htmlspecialchars( $data_filter_value ) . '"';
2552
2553 $data_author = isset( $attr['queryAuthor'] ) && $attr['queryAuthor'] ? $attr['queryAuthor'] : '[]';
2554 $adv_filter_dataset[] = 'data-filter-author="' . $data_author . '"';
2555
2556 $data_order = isset( $attr['queryOrder'] ) && $attr['queryOrder'] ? $attr['queryOrder'] : 'DESC';
2557 $adv_filter_dataset[] = 'data-filter-order="' . $data_order . '"';
2558
2559 $data_orderby = isset( $attr['queryOrderBy'] ) && $attr['queryOrderBy'] ? $attr['queryOrderBy'] : 'date';
2560 $adv_filter_dataset[] = 'data-filter-orderby="' . $data_orderby . '"';
2561
2562 $adv_filter_dataset[] = 'data-filter-search="' . ( isset( $attr['querySearch'] ) ? $attr['querySearch'] : '' ) . '"';
2563
2564 $adv_filter_dataset[] = 'data-filter-adv-sort="' . ( isset( $attr['queryQuick'] ) ? $attr['queryQuick'] : '' ) . '"';
2565 }
2566
2567 $adv_filter_dataset = implode( ' ', $adv_filter_dataset );
2568 return $adv_filter_dataset;
2569 }
2570
2571 /**
2572 * Custom Text kses
2573 *
2574 * @since v.4.0.2
2575 * @param MIXED $extras .
2576 * @return ARRAY|BOOL|MIXED|STRING
2577 */
2578 public function ultp_allowed_html_tags( $extras = array() ) {
2579 $allowed = array(
2580 'a' => array(
2581 'href' => true,
2582 'title' => true,
2583 ),
2584 'abbr' => array(
2585 'title' => true,
2586 ),
2587 'b' => array(),
2588 'br' => array(),
2589 'blockquote' => array(
2590 'cite' => true,
2591 ),
2592 'em' => array(),
2593 'i' => array(),
2594 'q' => array(
2595 'cite' => true,
2596 ),
2597 'strong' => array(
2598 'class' => true,
2599 'style' => true,
2600 ),
2601 'mark' => array(
2602 'class' => true,
2603 'style' => true,
2604 ),
2605 );
2606
2607 return array_merge( $allowed, $extras );
2608 }
2609
2610 /**
2611 * Allowed Block Tags
2612 *
2613 * @since v.4.0.2
2614 * @param STRING $search Optional. Tag name to check.
2615 * @return ARRAY|BOOL Returns array of allowed tags or bool if $search is provided.
2616 */
2617 public function ultp_allowed_block_tags( $search = '' ) {
2618 $array_lists = array( 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'span', 'p', 'div', 'section', 'article' );
2619 return $search ? in_array( $search, $array_lists ) : $array_lists;
2620 }
2621
2622 /**
2623 * Formats datasets for html
2624 *
2625 * @since v.4.0.2
2626 *
2627 * @param ARRAY $datasets .
2628 * @return STRING
2629 */
2630 public function get_formatted_datasets( &$datasets ) {
2631 $res = '';
2632 foreach ( $datasets as $key => $value ) {
2633 $res .= ' data-' . $key . '="' . $value . '" ';
2634 }
2635 return $res;
2636 }
2637
2638 /**
2639 * Sanitizes attributes after running necessary checks
2640 *
2641 * @since v.4.1.0
2642 *
2643 * @param ARRAY $attr The attributes array to sanitize.
2644 * @param STRING $key The key to check in the attributes array.
2645 * @param callable|null $sanitize_callback Callback function to sanitize the value.
2646 * @param MIXED $def_value Default value to return if key is not set.
2647 * @return MIXED Sanitized value or default value.
2648 */
2649 public function sanitize_attr( &$attr, $key, $sanitize_callback = null, $def_value = '' ) {
2650 return isset( $attr[ $key ] ) && $attr[ $key ] ?
2651 (
2652 $sanitize_callback ?
2653 $sanitize_callback( $attr[ $key ] ) :
2654 $attr[ $key ]
2655 )
2656 : $def_value;
2657 }
2658
2659 /**
2660 * Checks if dynamic content is active
2661 *
2662 * @since v.4.1.1
2663 *
2664 * @param ARRAY $attr The attributes to check for dynamic content.
2665 * @return BOOLEAN
2666 */
2667 public function is_dc_active( &$attr ) {
2668 if ( class_exists( '\ULTP\DCService' ) ) {
2669 return \ULTP\DCService::is_dc_active( $attr );
2670 }
2671 return false;
2672 }
2673
2674
2675 /**
2676 * Checks all the taxonomy of a post type for a given slug. Returns the taxonomy
2677 * if it exists.
2678 *
2679 * @since v.4.1.16
2680 *
2681 * @param STRING $post_type The post type.
2682 * @param STRING $slug The slug.
2683 * @return STRING|NULL The taxonomy name or null if not found.
2684 */
2685 public function get_taxonomy_by_term_slug( $post_type, $slug ) {
2686 $taxonomies = get_object_taxonomies( $post_type );
2687 foreach ( $taxonomies as $taxonomy ) {
2688 $res = get_term_by( 'slug', $slug, $taxonomy );
2689
2690 if ( ! empty( $res ) ) {
2691 return $taxonomy;
2692 }
2693 }
2694
2695 return null;
2696 }
2697 /**
2698 * Resolve Icon Alias
2699 *
2700 * @since v.4.0.0
2701 * @param STRING $icon_name The icon name or alias to resolve.
2702 * @return STRING|FALSE Returns the resolved icon name or false if no alias found.
2703 */
2704 public function svg_icon_compatibility( $icon_name = '' ) {
2705 if ( empty( $icon_name ) ) {
2706 return 'warning_triangle_solid';
2707 }
2708 // Get icon aliases mapping
2709 $icon_aliases = array(
2710 // Arrow aliases
2711 'angle_bottom_left_line' => 'arrow_down_bottom_left_solid',
2712 'angle_bottom_right_line' => 'arrow_down_bottom_right_solid',
2713 'angle_top_left_line' => 'arrow_up_top_left_solid',
2714 'angle_top_right_line' => 'arrow_up_top_right_solid',
2715 'rightFillAngle' => 'right_triangle_angle_play_arrow_forward_solid',
2716 'leftAngle2' => 'arrow_left_previous_backward_chevron_line',
2717 'rightAngle2' => 'arrow_right_next_forward_chevron_line',
2718 'collapse_bottom_line' => 'arrow_down_dropdown_maximize_chevron_line',
2719 'arrowUp2' => 'arrow_up_dropdown_minimize_chevron_line',
2720 'longArrowUp2' => 'long_arrow_up_top_increase_solid',
2721
2722 // Circle arrow aliases
2723 'arrow_left_circle_line' => 'arrow_left_backward_circle_line',
2724 'arrow_bottom_circle_line' => 'arrow_down_bottom_downward_circle_line',
2725 'arrow_right_circle_line' => 'arrow_right_forward_circle_line',
2726 'arrow_top_circle_line' => 'arrow_up_top_upward_circle_line',
2727
2728 // Close/Cross aliases
2729 'close_circle_line' => 'cross_close_x_minimize_circle_line',
2730 'close_line' => 'cross_x_close_minimize_line',
2731
2732 // Direction aliases
2733 'arrow_down_line' => 'arrow_down_bottom_downward_line',
2734 'leftArrowLg' => 'arrow_left_backward_line',
2735 'rightArrowLg' => 'arrow_left_forward_line',
2736 'arrow_up_line' => 'long_arrow_up_top_increase_line',
2737
2738 // Solid direction aliases
2739 'down_solid' => 'arrow_down_bottom_downward_circle_solid',
2740 'right_solid' => 'arrow_right_forward_circle_solid',
2741 'left_solid' => 'arrow_left_backward_circle_solid',
2742 'up_solid' => 'arrow_up_top_upward_circle_solid',
2743
2744 // Move aliases
2745 'bottom_right_line' => 'arrow_move_up_right_line',
2746 'bottom_left_line' => 'arrow_move_up_left_line',
2747 'top_left_angle_line' => 'arrow_move_down_left_line',
2748 'top_right_line' => 'arrow_move_down_right_line',
2749
2750 // Utility aliases
2751 'at_line' => 'at_a_mail_line',
2752 'refresh' => 'refresh_reset_cycle_loop_infinity_line',
2753 'cart_line' => 'shopping_cart_line',
2754 'cart_solid' => 'add_plus_shopping_cart_solid',
2755 'cog_line' => 'settings_tool_function_line',
2756 'cog_solid' => 'settings_tool_function_solid',
2757 'clock' => 'clock_reading_time_1_line',
2758 'book' => 'book_line',
2759 'download_line' => 'download_1_line',
2760 'download_solid' => 'download_1_solid',
2761 'downlod_bottom_solid' => 'download_1_solid',
2762
2763 // Visibility aliases
2764 'eye' => 'view_count_show_visible_eye_open_2_line',
2765 'hidden_line' => 'hidden_hide_invisible_line',
2766
2767 // Location aliases
2768 'home_line' => 'home_house_line',
2769 'home_solid' => 'home_house_solid',
2770 'location_line' => 'location_gps_map_line',
2771 'location_solid' => 'location_gps_map_solid',
2772
2773 // Emotion aliases
2774 'love_line' => 'heart_love_wishlist_favourite_line',
2775 'love_solid' => 'heart_love_wishlist_favourite_solid',
2776
2777 // Media aliases
2778 'play_line' => 'play_media_video_circle_line',
2779 'videoplay' => 'right_triangle_angle_play_arrow_forward_solid',
2780 'left_angle_solid' => 'left_triangle_angle_arrow_backward_solid',
2781
2782 // Shape aliases
2783 'caretArrow' => 'caret_up_top_triangle_angle_arrow_upward_solid',
2784 'rectangle_solid' => 'square_rounded_solid',
2785 'triangle_solid' => 'triangle_shape_solid',
2786
2787 // Status aliases
2788 'restriction_line' => 'restriction_no_stop_line',
2789 'right_circle_line' => 'correct_save_check_circle_line',
2790 'save_line' => 'correct_save_check_line',
2791 'search_line' => 'search_magnify_line',
2792 'search_solid' => 'search_magnify_solid',
2793
2794 // Warning aliases
2795 'notice_circle_solid' => 'warning_circle_solid',
2796 'notice_solid' => 'warning_triangle_solid',
2797 'warning_circle_line' => 'warning_circle_line',
2798 'warning_triangle_line' => 'warning_triangle_line',
2799
2800 // Category aliases
2801 'cat1' => 'category_file_documents_1_solid',
2802 'cat2' => 'category_book_line',
2803 'cat3' => 'category_file_documents_2_line',
2804 'cat4' => 'category_file_documents_3_line',
2805 'cat5' => 'category_file_documents_3_solid',
2806 'cat6' => 'category_file_documents_4_line',
2807 'cat7' => 'category_book_line',
2808
2809 // Comment aliases
2810 'commentCount1' => 'messege_comment_1_line',
2811 'commentCount2' => 'messege_comment_3_solid',
2812 'commentCount3' => 'messege_comment_3_line',
2813 'commentCount4' => 'messege_comment_6_line',
2814 'commentCount5' => 'messege_comment_7_line',
2815 'commentCount6' => 'messege_comment_8_line',
2816 'comment' => 'messege_comment_4_line',
2817
2818 // Date aliases
2819 'date1' => 'calendar_date_4_line',
2820 'date2' => 'calendar_date_1_solid',
2821 'date3' => 'calendar_date_2_line',
2822 'date4' => 'calendar_date_4_solid',
2823 'date5' => 'calendar_date_3_line',
2824 'calendar' => 'calendar_date_3_line',
2825
2826 // Reading time aliases
2827 'readingTime1' => 'clock_reading_time_3_line',
2828 'readingTime2' => 'clock_reading_time_2_line',
2829 'readingTime3' => 'book_reading_time_line',
2830 'readingTime4' => 'clock_reading_time_1_line',
2831 'readingTime5' => 'hourglass_timer_time_line',
2832
2833 // Tag aliases
2834 'tag1' => 'tag_bookmark_save_favourite_mark_discount_sale_line',
2835 'tag2' => 'price_tag_label_category_sale_discount_solid',
2836 'tag3' => 'price_tag_label_category_sale_discount_line',
2837 'tag4' => 'price_tag_offer_sale_coupon_solid',
2838 'tag5' => 'price_tag_label_category_sale_discount_line',
2839 'tag6' => 'growth_increase_up_solid',
2840
2841 // View count aliases
2842 'viewCount1' => 'view_count_show_visible_eye_open_1_line',
2843 'viewCount2' => 'view_count_show_visible_eye_open_2_line',
2844 'viewCount3' => 'view_count_show_visible_eye_open_3_line',
2845 'viewCount4' => 'view_count_show_visible_eye_open_4_solid',
2846 'viewCount5' => 'view_count_show_visible_eye_open_5_solid',
2847 'viewCount6' => 'view_count_show_visible_eye_open_5_solid',
2848
2849 // Author aliases
2850 'author1' => 'author_user_human_1_line',
2851 'author2' => 'author_user_human_4_line',
2852 'author3' => 'author_user_human_4_solid',
2853 'author4' => 'author_user_human_4_line',
2854 'author5' => 'author_user_human_3_solid',
2855 'author6' => 'author_user_human_6_line',
2856 'user' => 'author_user_human_3_line',
2857
2858 // Device aliases
2859 'desktop' => 'desktop_monitor_computer_line',
2860 'laptop' => 'laptop_computer_line',
2861 'tablet' => 'tablet_ipad_pad_line',
2862 'mobile' => 'mobile_smartphone_phone_line',
2863
2864 // Emoji aliases
2865 'angry_line' => 'angry_emoji_line',
2866 'angry_solid' => 'angry_emoji_solid',
2867 'confused_line' => 'confused_emoji_line',
2868 'confused_solid' => 'confused_emoji_solid',
2869 'happy_line' => 'happy_emoji_line',
2870 'happy_solid' => 'happy_emoji_solid',
2871 'smile_line' => 'smile_emoji_line',
2872 'smile_solid' => 'smile_emoji_solid',
2873
2874 // Social aliases
2875 'share_line' => 'social_community_line',
2876 'share' => 'share_social_solid',
2877 'apple_solid' => 'apple_logo_icon_solid',
2878 'android_solid' => 'android_logo_icon_solid',
2879 'google_solid' => 'google_logo_icon_solid',
2880 'messenger' => 'messenger_logo_icon_solid',
2881 'microsoft_solid' => 'microsoft_logo_icon_solid',
2882 'mail' => 'mail_email_messege_solid',
2883 'facebook' => 'facebook_logo_icon_solid',
2884 'twitter' => 'twitter_x_logo_icon_line',
2885 'link' => 'link_chains_line',
2886
2887 // Misc aliases
2888 'media_document' => 'media_document',
2889 'arrowDown2' => 'arrow_down_dropdown_maximize_chevron_line',
2890 'setting' => 'settings_tool_function_solid',
2891 'upload_solid' => 'upload_1_solid',
2892 'collapse_button_line' => 'collapse_button_line',
2893 'collapse_bottom_line' => 'collapse_bottom_line',
2894
2895 // Empty aliases for missing icons (return empty string)
2896 'correct_solid' => 'correct_save_check_circle_line',
2897 'dot_solid' => 'dot_circle_solid',
2898 'right_circle_solid' => 'correct_save_check_circle_solid',
2899 'full_screen' => 'full_screen_corners_out_solid',
2900 'zoom_in' => 'zoom_in_magnifying_glass_plus_line',
2901 'zoom_out' => 'zoom_out_magnifying_glass_minus_line',
2902 'gallery_indicator' => 'gallery_indicator_image_solid',
2903 'ascending' => 'sort_ascending_order_solid',
2904 'descending' => 'sort_descending_order_line',
2905 'unlink' => 'unlink_link_break_line',
2906 'rocket' => 'rocket_fly_boost_launch_pro_line',
2907 'unlock' => 'unlocked_open_security_solid',
2908 'connect' => 'plugin_connect_socket_integration_solid',
2909 'leftAngle' => 'arrow_left_previous_backward_chevron_line',
2910 'rightAngle' => 'right_triangle_angle_play_arrow_forward_line',
2911 'plus2' => '',
2912 'hamicon_1' => 'left_align_1_line',
2913 // extra in assets\img\iconpack folder
2914 'hamicon_2' => 'hemicon_2_line',
2915 'hamicon_3' => 'hemicon_3_line',
2916 'hamicon_4' => 'hamicon_5_line',
2917 'hamicon_5' => 'hamicon_4_sloid',
2918 'hamicon_6' => 'hamicon_6_line',
2919 'instagram_solid' => 'instagram_logo_icon_solid',
2920 'linkedin' => 'linkedin_logo_icon_solid',
2921 'pause_solid' => 'pause_solid',
2922 'pinterest' => 'pinterest_logo_icon_solid',
2923 'reddit' => 'reddit_logo_icon_solid',
2924 'skype' => 'skype_logo_icon_solid',
2925 'tiktok_lite_solid' => 'tiktok_logo_icon_line',
2926 'tiktok_solid' => 'tiktok_logo_icon_circle_solid',
2927 'whatsapp' => 'whatsapp_logo_icon_solid',
2928 'wordpress_lite_solid' => 'wordpress_logo_icon_solid',
2929 'wordpress_solid' => 'wordpress_logo_icon_2_solid',
2930 'wrong_solid' => 'cross_close_x_minimize_circle_solid',
2931 'youtube_solid' => 'youtube_logo_icon_solid',
2932 'five_star_line' => 'star_rating_line',
2933 'rightAngleBold' => 'arrow_right_next_forward_chevron_line',
2934 'leftAngleBold' => 'arrow_left_previous_backward_chevron_line',
2935 'plus' => 'plus',
2936 'reset_left_line' => 'refresh_reset_cycle_loop_infinity_line',
2937 );
2938 // Return resolved alias or false if not found
2939 return isset( $icon_aliases[ $icon_name ] ) ? $icon_aliases[ $icon_name ] : $icon_name;
2940 }
2941 }
2942