PluginProbe
Post Grid Gutenberg Blocks – PostX / 4.1.30
Post Grid Gutenberg Blocks – PostX v4.1.30
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 4.1.30, at classes/Functions.php

2,598 lines 107.0 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 namespace ULTP;
9
10 defined('ABSPATH') || exit;
11
12 /**
13 * Functions class.
14 */
15
16 class Functions{
17
18 /**
19 * @since v.3.2.4
20 * Instance of the class.
21 *
22 * @var Functions | null
23 */
24 private static $instance = null;
25
26 /**
27 * Setup class.
28 *
29 * @since v.1.0.0
30 */
31 public function __construct() {
32
33 }
34
35 /**
36 * Gets the instance of \ULTP\Functions class
37 *
38 * @return Functions
39 * @since v.3.2.4
40 */
41 public static function get_instance()
42 {
43 if (!isset ($GLOBALS['ultp_settings'])) {
44 $GLOBALS['ultp_settings'] = get_option('ultp_options');
45 }
46
47 if (is_null(self::$instance)) {
48 self::$instance = new self();
49 }
50
51 return self::$instance;
52 }
53
54 /**
55 * ID for the Builder Post or Normal Post
56 *
57 * @since v.2.3.1
58 * @return NUMBER | is Builder or not
59 */
60 public function get_ID() {
61 $id = $this->is_builder();
62 return $id ? $id : (function_exists('is_shop') ? (is_shop() ? wc_get_page_id('shop') : get_the_ID()) : get_the_ID() );
63 }
64
65 /**
66 * Checking Statement of Dynamic Site Builder
67 *
68 * @since v.2.3.1
69 * @return BOOLEAN | is Builder or not
70 */
71 public function is_archive_builder() {
72 $id = get_the_ID();
73 return get_post_type( $id ) == 'ultp_builder' ? get_post_meta( $id, '__ultp_builder_type', true ) : false;
74 }
75
76 /**
77 * Set Link with the Parameters
78 *
79 * @since v.1.1.0
80 * @return STRING | URL with Arg
81 */
82 public function get_premium_link( $url = '', $tag = 'go_premium') {
83 $url_list = array(
84 // PostX Dashboard Menu
85 'menu_save_temp_pro' => array(
86 'utm_source' => 'postx-menu',
87 'utm_medium' => 'ST-go_pro',
88 'utm_campaign' => 'postx-dashboard'
89 ),
90 // PostX Dashboard
91 'dashboard_go_pro' => array(
92 'utm_source' => 'db-postx-plugin',
93 'utm_medium' => 'left-menu-upgrade',
94 'utm_campaign' => 'postx-dashboard'
95 ),
96 'dashboard_db_banner' => array(
97 'utm_source' => 'postx-ad',
98 'utm_medium' => 'DB-banner',
99 'utm_campaign' => 'postx-dashboard'
100 ),
101 // Plugin Directory
102 'plugin_dir_pro' => array(
103 'utm_source' => 'db-postx-plugin',
104 'utm_medium' => 'upgrade',
105 'utm_campaign' => 'postx-dashboard'
106 ),
107 'plugin_dir_support' => array(
108 'utm_source' => 'postx_plugin',
109 'utm_medium' => 'support',
110 'utm_campaign' => 'postx-dashboard'
111 )
112 );
113 $url = $url ? $url : 'https://www.wpxpo.com/postx/pricing/';
114 $affiliate_id = apply_filters( 'ultp_affiliate_id', FALSE );
115 $arg = array();
116 if($tag && isset($url_list[$tag])){
117 $arg = $url_list[$tag];
118 } else {
119 $arg = array( 'utm_source' => $tag );
120 }
121 if ( ! empty( $affiliate_id ) ) {
122 $arg[ 'ref' ] = esc_attr( $affiliate_id );
123 }
124 return add_query_arg( $arg, $url );
125 }
126
127
128 /**
129 * Quick Query
130 *
131 * @since v.1.1.0
132 * @return ARRAY | Query Arg
133 */
134 public function get_quick_query($prams, $args) {
135 switch ($prams['queryQuick']) {
136 case 'related_posts':
137 global $post;
138 $p_id = isset($post->ID) && $post->ID ? $post->ID : (isset($_POST['postId']) ? sanitize_text_field($_POST['postId']) : ''); //phpcs:disable WordPress.Security.NonceVerification.Missing
139 if ($p_id) {
140 $args['post__not_in'] = array($p_id);
141 }
142 break;
143 case 'related_tag':
144 global $post;
145 $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
146 if ($p_id) {
147 $args['tax_query'] = array(
148 array(
149 'taxonomy' => 'post_tag',
150 'terms' => $this->get_terms_id($p_id, 'post_tag'),
151 'field' => 'term_id',
152 )
153 );
154 $args['post__not_in'] = array($p_id);
155 }
156 break;
157 case 'related_category':
158 global $post;
159 $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
160 if ($p_id) {
161 $args['tax_query'] = array(
162 array(
163 'taxonomy' => 'category',
164 'terms' => $this->get_terms_id($p_id, 'category'),
165 'field' => 'term_id',
166 )
167 );
168 $args['post__not_in'] = array($p_id);
169 }
170 break;
171 case 'related_cat_tag':
172 global $post;
173 $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
174 if ($p_id) {
175 $args['tax_query'] = array(
176 array(
177 'taxonomy' => 'post_tag',
178 'terms' => $this->get_terms_id($p_id, 'post_tag'),
179 'field' => 'term_id',
180 ),
181 array(
182 'taxonomy' => 'category',
183 'terms' => $this->get_terms_id($p_id, 'category'),
184 'field' => 'term_id',
185 )
186 );
187 $args['post__not_in'] = array($p_id);
188 }
189 break;
190 case 'sticky_posts':
191 $sticky = get_option('sticky_posts');
192 if (is_array($sticky)) {
193 rsort($sticky);
194 // $sticky = array_slice($sticky, 0, $args['posts_per_page']);
195 }
196 $args['ignore_sticky_posts'] = 1;
197 $args['post__in'] = $sticky;
198 break;
199 case 'latest_post_published':
200 $args['orderby'] = 'date';
201 $args['order'] = 'DESC';
202 $args['ignore_sticky_posts'] = 1;
203 break;
204 case 'latest_post_modified':
205 $args['orderby'] = 'modified';
206 $args['order'] = 'DESC';
207 $args['ignore_sticky_posts'] = 1;
208 break;
209 case 'oldest_post_published':
210 $args['orderby'] = 'date';
211 $args['order'] = 'ASC';
212 break;
213 case 'oldest_post_modified':
214 $args['orderby'] = 'modified';
215 $args['order'] = 'ASC';
216 break;
217 case 'alphabet_asc':
218 $args['orderby'] = 'title';
219 $args['order'] = 'ASC';
220 break;
221 case 'alphabet_desc':
222 $args['orderby'] = 'title';
223 $args['order'] = 'DESC';
224 break;
225 case 'random_post':
226 $args['orderby'] = 'rand';
227 $args['order'] = 'ASC';
228 break;
229 case 'random_post_7_days':
230 $args['orderby'] = 'rand';
231 $args['order'] = 'ASC';
232 $args['date_query'] = array( array( 'after' => '1 week ago') );
233 break;
234 case 'random_post_30_days':
235 $args['orderby'] = 'rand';
236 $args['order'] = 'ASC';
237 $args['date_query'] = array( array( 'after' => '1 month ago') );
238 break;
239 case 'most_comment':
240 $args['orderby'] = 'comment_count';
241 $args['order'] = 'DESC';
242 break;
243 case 'most_comment_1_day':
244 $args['orderby'] = 'comment_count';
245 $args['order'] = 'DESC';
246 $args['date_query'] = array( array( 'after' => '1 day ago') );
247 break;
248 case 'most_comment_7_days':
249 $args['orderby'] = 'comment_count';
250 $args['order'] = 'DESC';
251 $args['date_query'] = array( array( 'after' => '1 week ago') );
252 break;
253 case 'most_comment_30_days':
254 $args['orderby'] = 'comment_count';
255 $args['order'] = 'DESC';
256 $args['date_query'] = array( array( 'after' => '1 month ago') );
257 break;
258 case 'popular_post_1_day_view':
259 $args['meta_key'] = '__post_views_count';
260 $args['orderby'] = 'meta_value_num';
261 $args['order'] = 'DESC';
262 $args['date_query'] = array( array( 'after' => '1 day ago') );
263 break;
264 case 'popular_post_7_days_view':
265 $args['meta_key'] = '__post_views_count';
266 $args['orderby'] = 'meta_value_num';
267 $args['order'] = 'DESC';
268 $args['date_query'] = array( array( 'after' => '1 week ago') );
269 break;
270 case 'popular_post_30_days_view':
271 $args['meta_key'] = '__post_views_count';
272 $args['orderby'] = 'meta_value_num';
273 $args['order'] = 'DESC';
274 $args['date_query'] = array( array( 'after' => '1 month ago') );
275 break;
276 case 'popular_post_all_times_view':
277 $args['meta_key'] = '__post_views_count';
278 $args['orderby'] = 'meta_value_num';
279 $args['order'] = 'DESC';
280 break;
281 default:
282 # code...
283 break;
284 }
285 return $args;
286 }
287
288 /**
289 * Get All Term ID as Array
290 *
291 * @since v.2.4.12
292 * @return ARRAY | Query Arg
293 */
294 public function get_terms_id($id, $type) {
295 $data = array();
296 $arr = get_the_terms($id, $type);
297 if (is_array($arr)) {
298 foreach ($arr as $key => $val) {
299 $data[] = $val->term_id;
300 }
301 }
302 return $data;
303 }
304
305 /**
306 * Get All Reusable ID
307 *
308 * @since v.1.1.0
309 * @return ARRAY | Query Arg
310 */
311 public function get_reusable_ids( $post_id ) {
312 $reusable_id = array();
313 if ( $post_id ) {
314 $post = get_post($post_id);
315 if ( isset($post->post_content) ) {
316 if (
317 has_blocks($post->post_content) &&
318 strpos($post->post_content, 'wp:block') &&
319 strpos($post->post_content, '"ref"') !== false
320 ) {
321 $blocks = parse_blocks($post->post_content);
322 foreach ($blocks as $key => $value) {
323 if ( isset($value['attrs']['ref']) ) {
324 $reusable_id[] = $value['attrs']['ref'];
325 }
326 }
327 }
328 }
329 }
330 return $reusable_id;
331 }
332
333 /**
334 * get directory file contents
335 *
336 * @since v.4.1.8
337 * @return ARRAY | Query Arg
338 */
339 public function get_path_file_contents($path) {
340 global $wp_filesystem;
341 if (! $wp_filesystem ) {
342 require_once( ABSPATH . 'wp-admin/includes/file.php' );
343 $init_fs = WP_Filesystem();
344 if ( !$init_fs ) {
345 return '';
346 }
347 }
348
349 if ( $wp_filesystem->exists($path) ) {
350 return $wp_filesystem->get_contents($path);
351 } else {
352 return '';
353 }
354 }
355
356 /**
357 * build css for inline printing // used for some builder
358 *
359 * @since v.4.1.8
360 * @return ARRAY | Query Arg
361 */
362 public function build_css_for_inline_print( $post_id, $call_common=true ) {
363 if ( $post_id ) {
364 $upload_dir_url = wp_get_upload_dir();
365 $upload_css_dir_url = trailingslashit( $upload_dir_url['basedir'] );
366
367 $css_dir_url = trailingslashit( $upload_dir_url['baseurl'] );
368 if ( is_ssl() ) {
369 $css_dir_url = str_replace('http://', 'https://', $css_dir_url);
370 }
371 $reusable_css = '';
372 $reusable_id = $this->get_reusable_ids($post_id);
373 if ( !empty($reusable_id) ) {
374 foreach ( $reusable_id as $id ) {
375 $reusable_dir_path = $upload_css_dir_url."ultimate-post/ultp-css-{$id}.css";
376 if (file_exists( $reusable_dir_path )) {
377 $reusable_css .= $this->get_path_file_contents($reusable_dir_path);
378 } else {
379 $reusable_css .= get_post_meta($reusable_id, '_ultp_css', true);
380 }
381 }
382 }
383
384 $css_dir_path = $upload_css_dir_url . "ultimate-post/ultp-css-{$post_id}.css";
385 $css = '';
386 if (file_exists( $css_dir_path ) ) {
387 $css = $this->get_path_file_contents($css_dir_path);
388 } else {
389 $css = get_post_meta($post_id, '_ultp_css', true);
390 }
391 if ( $reusable_css.$css ) {
392 if ( $call_common ) {
393 $this->register_scripts_common();
394 }
395 return '<style id="ultp-post-'.$post_id.'" type="text/css">'.wp_strip_all_tags($reusable_css.$css).'</style>';
396 }
397 }
398 return '';
399 }
400
401
402 /**
403 * Get Global Plugin Settings
404 *
405 * @since v.1.0.0
406 * @param STRING | Key of the Option
407 * @return ARRAY | STRING
408 */
409 public function get_setting($key = '') {
410 $data = $GLOBALS['ultp_settings'];
411 if ($key != '') {
412 return isset($data[$key]) ? $data[$key] : '';
413 } else {
414 return $data;
415 }
416 }
417
418
419 /**
420 * Set Option Settings
421 *
422 * @since v.1.0.0
423 * @param STRING | Key of the Option (STRING), Value (STRING)
424 * @return NULL
425 */
426 public function set_setting($key = '', $val = '') {
427 if ($key != '') {
428 $data = $GLOBALS['ultp_settings'];
429 $data[$key] = $val;
430 update_option('ultp_options', $data);
431 $GLOBALS['ultp_settings'] = $data;
432 do_action('ultp_settings_updated',$key,$val);
433 }
434 }
435
436
437 /**
438 * Get Image HTML
439 *
440 * @since v.1.0.0
441 * @param | URL (STRING) | size (STRING) | class (STRING) | alt (STRING)
442 * @return STRING
443 */
444 public function get_image_html($url = '', $size = 'full', $class = '', $alt = '', $lazy = '', $darkImg=[], $srcset = '') {
445 $class = sanitize_html_class($class);
446 $alt = preg_replace('/[^A-Za-z0-9_ -]/', '', $alt);
447 $hasDarkImage = ( $darkImg['enable'] && $darkImg['url'] ) ? ' ultp-light-image-block ' : '';
448 $alt = $alt ? ' alt="'.$alt.'" ' : '';
449 $lazy_data = $lazy ? ' loading="lazy"' : '';
450
451 $dlMode = isset($_COOKIE['ultplocalDLMode']) ? $_COOKIE['ultplocalDLMode'] : ultimate_post()->get_dl_mode();
452
453 $lightMode = $hasDarkImage ? ( $dlMode == 'ultplight' ? '' : 'inactive ' ) : '';
454 $darkMode = $hasDarkImage ? ( $hasDarkImage && $dlMode == 'ultpdark' ? '' : ' inactive ' ) : '';
455
456 $image = '<img '.$lazy_data.$srcset.' class="'.$class.$hasDarkImage.$lightMode.'" '.$alt.' src="'.esc_url($url).'" />';
457 if( $hasDarkImage ) {
458 $image .= '<img '.$lazy_data.$darkImg['srcset'].' class="'.$class.$darkMode.' ultp-dark-image-block " '.$alt.' src="'.esc_url($darkImg['url']).'" />';
459 }
460 return $image;
461 }
462
463
464 /**
465 * Get Image HTML
466 *
467 * @since v.1.0.0
468 * @param | Attach ID (STRING) | size (STRING) | class (STRING) | alt (STRING)
469 * @return STRING
470 */
471 public function get_image($attach_id, $size = 'full', $class = '', $alt = '', $srcset = '', $lazy = '') {
472 $img_alt = get_post_meta($attach_id, '_wp_attachment_image_alt', true);
473 $alt = $img_alt ? $img_alt : $alt;
474 $alt = $alt ? ' alt="'.esc_html($alt).'" ' : '';
475 $class = $class ? ' class="'.$class.'" ' : '';
476 $size = ( ultimate_post()->get_setting('disable_image_size') == 'yes' && strpos($size, 'ultp_layout_') !== false ) ? 'full' : $size;
477 $lazy_data = $lazy ? ' loading="lazy"' : '';
478 $srcset_data = $srcset ? ' srcset="'.esc_attr(wp_get_attachment_image_srcset($attach_id)).'"' : '';
479 return '<img '.$srcset_data.$lazy_data.$class.$alt.' src="'.wp_get_attachment_image_url( $attach_id, $size ).'" />';
480 }
481
482
483 /**
484 * Get Excerpt Text
485 *
486 * @since v.1.0.0
487 * @param | Post ID (STRING) | Limit (NUMBER)
488 * @return STRING
489 */
490 public function excerpt( $post_id, $limit = 55 ) {
491 $content = preg_replace('/(\[postx_template[\s\w="]*)]/m', '', get_the_excerpt( $post_id )); // Remove postx_template shortcode form Content
492 return apply_filters( 'the_excerpt', wp_trim_words($content, $limit) );
493 }
494
495 /**
496 * Builder Attributes
497 *
498 * @since v.1.0.0
499 * @param STRING type
500 * @return STRING
501 */
502 public function get_builder_attr($type) {
503 $builder_data = '';
504 if ($type == 'archiveBuilder') {
505 if (is_archive()) {
506 if (is_date()) {
507 if (is_year()) {
508 $builder_data = 'date###'.get_the_date('Y');
509 } else if (is_month() ) {
510 $builder_data = 'date###'.get_the_date('Y-n');
511 } else if (is_day() ) {
512 $builder_data = 'date###'.get_the_date('Y-n-j');
513 }
514 } else if (is_author()) {
515 $builder_data = 'author###'.get_the_author_meta('ID');
516 } else {
517 $obj = get_queried_object();
518 if (isset($obj->taxonomy)) {
519 $builder_data = 'taxonomy###'.$obj->taxonomy.'###'.$obj->slug;
520 }
521 }
522 } else if (is_search()) {
523 $builder_data = 'search###'.get_search_query(true);
524 }
525 }
526 return $builder_data ? 'data-builder="'.$builder_data.'"' : '';
527 }
528
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 MULTIPLE | Attribute of Posts
547 * @return STRING
548 */
549 public function get_post_number($preDef, $prev, $current) {
550
551 $current = is_object($current) ? json_decode(wp_json_encode($current), true) : $current;
552 if ( ['lg'=> $preDef, 'sm'=> $preDef, 'xs'=> $preDef] == $current ) {
553 if ( $preDef != $prev ) {
554 return $prev;
555 }
556 }
557
558 $lg = isset($current['lg']) ? $current['lg'] : $prev;
559 $sm = isset($current['sm']) ? $current['sm'] : $lg;
560 $xs = isset($current['xs']) ? $current['xs'] : $lg;
561 if ( $lg == $sm && $sm == $xs ) {
562 return $lg;
563 } else {
564 global $ultpDevide;
565 $currentDevice = !empty($ultpDevide) ? $ultpDevide : $this->isDevice();
566 if ( $currentDevice == 'mobile' ) {
567 return $xs;
568 } else if ( $currentDevice == 'tablet' ) {
569 return $sm;
570 } else {
571 return $lg;
572 }
573 }
574 }
575
576
577 /**
578 * Get Post Number Depending On Device
579 *
580 * @since v.2.5.4
581 * @param NULL
582 * @return STRING | Device Type
583 */
584 public function isDevice(){
585 $useragent = isset($_SERVER['HTTP_USER_AGENT']) ? sanitize_key($_SERVER['HTTP_USER_AGENT']) : '';
586 $device = 'desktop';
587 if ( $useragent ) {
588 if ( preg_match('/(tablet|ipad|playbook)|(android(?!.*(mobi|opera mini)))/i', strtolower($useragent)) ) {
589 $device = 'tablet';
590 } else if ( 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))) {
591 $device = 'mobile';
592 }
593 }
594 global $ultpDevide;
595 $ultpDevide = $device;
596 return $device;
597 }
598
599
600 /**
601 * Get Raw Value from Objects
602 *
603 * @since v.2.5.3
604 * @param NULL
605 * @return STRING | Device Type
606 */
607 public function get_value($attr) {
608 $data = [];
609 if ( is_array($attr) ) {
610 foreach ($attr as $val) {
611 $data[] = $val->value;
612 }
613 }
614 return $data;
615 }
616
617 /**
618 * QueryArgs for Filter
619 *
620 * @since v.2.8.9
621 * @param ARRAY | Attribute of the Query
622 * @return ARRAY
623 */
624 public function getFilterQueryArgs( $attr ) {
625 $tax_value = (strlen($attr['queryTaxValue']) > 2) ? $attr['queryTaxValue'] : [];
626 $tax_value = is_array($tax_value) ? $tax_value : json_decode($tax_value);
627
628 $tax_value = (isset($tax_value[0]) && is_object($tax_value[0])) ? $this->get_value($tax_value) : $tax_value;
629
630 if (is_array($tax_value) && count($tax_value) > 0) {
631 $relation = isset($attr['queryRelation']) ? $attr['queryRelation'] : 'OR';
632
633 // Adv Filter Query Relation Override
634 if (isset($attr['advFilterEnable']) && $attr['advFilterEnable'] === true && isset($attr['advRelation'])) {
635 $relation = 'AND' === $attr['advRelation'] || 'OR' === $attr['advRelation'] ? $attr['advRelation'] : $relation;
636 }
637
638 $var = array('relation'=>$relation);
639 foreach ($tax_value as $val) {
640 $tax_name = $attr['queryTax'];
641 // For Custom Terms
642 if ($attr['queryTax'] == 'multiTaxonomy') {
643 $temp = explode('###', $val);
644 if (isset($temp[1])) {
645
646 if ($temp[1] === "_all") {
647 continue;
648 }
649
650 $val = $temp[1];
651 $tax_name = $temp[0];
652 }
653 }
654 $var[] = array('taxonomy'=> $tax_name, 'field' => 'slug', 'terms' => $val );
655 }
656
657 }
658 return isset($var) ? $var : [];
659 }
660
661 /**
662 * Query Builder
663 *
664 * @since v.1.0.0
665 * @param ARRAY | Attribute of the Query
666 * @return ARRAY
667 */
668 public function get_query($attr) {
669 $builder = isset($attr['builder']) ? $attr['builder'] : '';
670 $post_type = isset($attr['queryType']) ? $attr['queryType'] : 'post';
671 if ( $post_type == 'archiveBuilder' && ($builder || $this->is_builder($builder)) ) {
672 $archive_query = array();
673 if ($builder) {
674 $str = explode('###', $builder);
675 if (isset($str[0])) {
676 if ($str[0] == 'taxonomy') {
677 if (isset($str[1]) && isset($str[2])) {
678 $archive_query['tax_query'] = array(
679 array(
680 'taxonomy' => $str[1],
681 'field' => 'slug',
682 'terms' => $str[2]
683 )
684 );
685 }
686 } else if ($str[0] == 'author') {
687 if (isset($str[1])) {
688 $archive_query['author'] = $str[1];
689 }
690 } else if ($str[0] == 'search') {
691 if (isset($str[1])) {
692 $archive_query['s'] = $str[1];
693 }
694 } else if ($str[0] == 'date') {
695 if (isset($str[1])) {
696 $all_date = explode('-', $str[1]);
697 if (!empty($all_date)) {
698 $arg = array();
699 if (isset($all_date[0])) { $arg['year'] = $all_date[0]; }
700 if (isset($all_date[1])) { $arg['month'] = $all_date[1]; }
701 if (isset($all_date[2])) { $arg['day'] = $all_date[2]; }
702 $archive_query['date_query'][] = $arg;
703 }
704 }
705 }
706 }
707 } else {
708 global $wp_query;
709 $archive_query = $wp_query->query_vars;
710 }
711 $archive_query['posts_per_page'] = isset($attr['queryNumber']) ? $attr['queryNumber'] : 1;
712 $archive_query['paged'] = isset($attr['paged']) ? $attr['paged'] : 1;
713
714 $archive_query['paged'] = ! wp_doing_ajax() && isset( $_GET[ $attr['blockId'] . '_page' ] ) && is_numeric( $_GET[ $attr['blockId'] . '_page' ] ) ?
715 intval($_GET[ $attr['blockId'] . '_page' ]) :
716 $archive_query['paged'];
717
718 if (isset($attr['queryOffset']) && $attr['queryOffset'] ) {
719 $offset = $this->get_offset($attr['queryOffset'], $archive_query);
720 $archive_query = array_merge($archive_query, $offset);
721 }
722
723 // Include Remove from Version 2.5.4
724 if (isset($attr['queryInclude']) && $attr['queryInclude']) {
725 $_include = explode(',', $attr['queryInclude']);
726 if (is_array($_include) && count($_include)) {
727 $archive_query['post__in'] = isset($archive_query['post__in']) ? array_merge($archive_query['post__in'], $_include) : $_include;
728 $archive_query['ignore_sticky_posts'] = 1;
729 $archive_query['orderby'] = 'post__in';
730 }
731 }
732
733 if (isset($attr['queryExclude']) && $attr['queryExclude']) {
734 $_exclude = (substr($attr['queryExclude'], 0, 1) === "[") ? $this->get_value(json_decode($attr['queryExclude'])) : explode(',', $attr['queryExclude']);
735 if (is_array($_exclude) && count($_exclude)) {
736 $archive_query['post__not_in'] = isset($archive_query['post__not_in']) ? array_merge($archive_query['post__not_in'], $_exclude) : $_exclude;
737 }
738 }
739
740
741 if(isset($attr['querySticky']) && $attr['querySticky']) {
742 if (filter_var($attr['querySticky'], FILTER_VALIDATE_BOOLEAN)) {
743 $sticky = get_option( 'sticky_posts', [] );
744 $archive_query['post__not_in'] = isset($archive_query['post__not_in']) ? array_merge($archive_query['post__not_in'], $sticky) : $sticky;
745 }
746 }
747 // ===============
748 if (isset($attr['queryUnique']) && $attr['queryUnique']) {
749 global $unique_ID;
750 if (isset($unique_ID[$attr['queryUnique']])) {
751 $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']];
752 }
753 }
754 // ===============
755
756 $archive_query['post_status'] = 'publish';
757 if (is_user_logged_in()) {
758 if( current_user_can('editor') || current_user_can('administrator') ) {
759 $archive_query['post_status'] = array('publish', 'private');
760 }
761 }
762
763 if(!isset($archive_query['orderby'])) {
764 $archive_query['orderby'] = isset($attr['queryOrderBy']) ? $attr['queryOrderBy'] : 'date';
765 }
766
767 // Quick Query Support for Builder
768 if (isset($attr['queryQuick'])) {
769 if ($attr['queryQuick'] != '') {
770 $archive_query = ultimate_post()->get_quick_query($attr, $archive_query);
771 }
772 }
773
774 if (!isset($attr['ajaxCall'])) {
775 if(isset($attr['filterShow']) && $attr['filterShow'] && $attr['filterShow'] != 'false') {
776 if(isset($attr['filterType']) && isset($attr['filterValue']) ) {
777 $filterValue = strlen($attr['filterValue']) > 2 ? $attr['filterValue'] : [];
778 $filterValue = is_array($filterValue) ? $filterValue : json_decode($filterValue);
779 if (count($filterValue) > 0 && $attr['filterType']) {
780 $final = array('relation' => 'OR');
781 foreach ($filterValue as $key => $val) {
782 $final[] = array(
783 'taxonomy' => $attr['filterType'],
784 'field' => 'slug',
785 'terms' => $val,
786 );
787 }
788 $archive_query['tax_query'] = $final;
789 }
790 }
791 }
792 }
793 // from v.3.0.7 - for search builder
794 if(is_search()){
795 $archive_query['orderby'] = 'relevance';
796 if ( isset($_GET['ultp_exclude']) ) { // Added support for search block exclude
797 $ultp_exclude = json_decode(stripslashes($_GET['ultp_exclude']), true);
798 if ( is_array($ultp_exclude) ) {
799 $all_types = get_post_types( array( 'public' => true ), 'names' );
800 $post_type = array_diff($all_types, $ultp_exclude);
801 $archive_query['post_type'] = $post_type;
802 }
803 }
804 }
805
806 return apply_filters('ultp_archive_query', $archive_query);
807 }
808
809 // When you use load more pagination block for a grid that did not have load more feature,
810 // the incoming posts would not align properly with the blocks design and looked bad.
811 // This fixes that.
812 if (
813 isset($attr['paginationType']) &&
814 isset($attr['queryNumber2']) &&
815 isset($attr['notFirstLoad']) &&
816 $attr['paginationType'] === "loadMore" &&
817 $attr['notFirstLoad']
818 ) {
819 $query_number = $attr['queryNumber2'];
820 // $query_number = isset($attr['queryNumber']) ? $attr['queryNumber'] : 3;
821 } else {
822 $query_number = isset($attr['queryNumber']) ? $attr['queryNumber'] : 3;
823 }
824
825 $paged = isset($attr['paged']) ? $attr['paged'] : 1;
826 $paged = ! wp_doing_ajax() &&
827 isset($attr['blockId']) &&
828 isset( $_GET[ $attr['blockId'] . '_page' ] ) &&
829 is_numeric( $_GET[ $attr['blockId'] . '_page' ] ) ?
830 intval($_GET[ $attr['blockId'] . '_page' ]) :
831 $paged;
832
833 $query_args = array(
834 'posts_per_page' => $query_number,
835 'post_type' => $post_type == 'archiveBuilder' ? 'post' : $post_type,
836 'orderby' => isset($attr['queryOrderBy']) ? $attr['queryOrderBy'] : 'date',
837 'order' => isset($attr['queryOrder']) ? $attr['queryOrder'] : 'desc',
838 'paged' => $paged,
839 'post_status' => 'publish'
840 );
841
842 // For Private Post 'private'
843 if (is_user_logged_in()) {
844 if( current_user_can('editor') || current_user_can('administrator') ) {
845 $query_args['post_status'] = array('publish', 'private');
846 }
847 }
848
849 if ($attr['queryType'] == 'posts') {
850 if (isset($attr['queryPosts']) && $attr['queryPosts']) {
851 unset($query_args['post_type']);
852 $data = json_decode(isset($attr['queryPosts'])?$attr['queryPosts']:'[]');
853 $final = $this->get_value($data);
854 if (count($final) > 0) {
855 $query_args['post__in'] = $final;
856 // $query_args['posts_per_page'] = -1;
857 }
858 $query_args['ignore_sticky_posts'] = 1;
859 return $query_args;
860 }
861 } else if ($attr['queryType'] == 'customPosts') {
862 if (isset($attr['queryCustomPosts']) && $attr['queryCustomPosts']) {
863 $query_args['post_type'] = $this->get_post_type();
864 $data = json_decode(isset($attr['queryCustomPosts'])?$attr['queryCustomPosts']:'[]');
865 $final = $this->get_value($data);
866 if (count($final) > 0) {
867 $query_args['post__in'] = $final;
868 // $query_args['posts_per_page'] = -1;
869 }
870 $query_args['ignore_sticky_posts'] = 1;
871 return $query_args;
872 }
873 }
874
875 if (isset($attr['queryExcludeAuthor']) && $attr['queryExcludeAuthor']) {
876 $data = json_decode(isset($attr['queryExcludeAuthor'])?$attr['queryExcludeAuthor']:'[]');
877 $final = $this->get_value($data);
878 if (count($final) > 0) {
879 $query_args['author__not_in'] = $final;
880 }
881 }
882
883
884 if (isset($attr['queryOrderBy']) && isset($attr['metaKey'])) {
885 if ($attr['queryOrderBy'] == 'meta_value_num') {
886 $query_args['meta_key'] = $attr['metaKey'];
887 }
888 }
889
890 // Include Remove from Version 2.5.4
891 if (isset($attr['queryInclude']) && $attr['queryInclude']) {
892 $_include = explode(',', $attr['queryInclude']);
893 if (is_array($_include) && count($_include)) {
894 $query_args['post__in'] = isset($query_args['post__in']) ? array_merge($query_args['post__in'], $_include) : $_include;
895 $query_args['ignore_sticky_posts'] = 1;
896 $query_args['orderby'] = 'post__in';
897 }
898 }
899
900
901 if (isset($attr['queryTax'])) {
902 if (isset($attr['queryTaxValue'])) {
903 $var = $this->getFilterQueryArgs($attr);
904 if (isset($var) && count($var) > 1) {
905 $query_args['tax_query'] = $var;
906 }
907 }
908 }
909
910 if (isset($attr['queryExcludeTerm']) && $attr['queryExcludeTerm']) {
911 $temp = json_decode($attr['queryExcludeTerm']);
912 $_term = [];
913 foreach ($temp as $val) {
914 $temp = explode('###', $val->value);
915 if (isset($temp[1])) {
916 if ( is_array($_term) && array_key_exists($temp[0], $_term)) {
917 $_term[$temp[0]][] = $temp[1];
918 } else {
919 $_term[$temp[0]] = array($temp[1]);
920 }
921 }
922 }
923 if (count($_term) > 0) {
924 $final = array('relation' => 'AND');
925 foreach ($_term as $key => $val) {
926 $final[] = array(
927 'taxonomy' => $key,
928 'field' => 'slug',
929 'terms' => $val,
930 'operator' => 'NOT IN',
931 );
932 }
933
934 if ( is_array($query_args) && array_key_exists('tax_query', $query_args)) {
935 $query_args['tax_query'] = array(
936 'relation' => 'AND',
937 $query_args['tax_query']
938 );
939 $query_args['tax_query'][] = $final;
940 } else {
941 $query_args['tax_query'] = $final;
942 }
943 }
944 }
945
946 if (isset($attr['queryExclude']) && $attr['queryExclude']) {
947 $_exclude = (substr($attr['queryExclude'], 0, 1) === "[") ? $this->get_value(json_decode($attr['queryExclude'])) : explode(',', $attr['queryExclude']);
948 if (is_array($_exclude) && count($_exclude)) {
949 $query_args['post__not_in'] = isset($query_args['post__not_in']) ? array_merge($query_args['post__not_in'], $_exclude) : $_exclude;
950 }
951 }
952
953 if (isset($attr['queryUnique']) && $attr['queryUnique']) {
954 global $unique_ID;
955 if (isset($unique_ID[$attr['queryUnique']])) {
956 $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']];
957 }
958 }
959 // exclude current post from Post blocks // v.2.9.6
960 if (is_single() && get_the_ID()) {
961 $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());
962 }
963
964 if (isset($attr['queryQuick'])) {
965 if ($attr['queryQuick'] != '' && $post_type != 'archiveBuilder') {
966 $query_args = ultimate_post()->get_quick_query($attr, $query_args);
967 }
968 }
969
970 if (isset($attr['queryOffset']) && $attr['queryOffset'] ) {
971 $offset = $this->get_offset($attr['queryOffset'], $query_args);
972 $query_args = array_merge($query_args, $offset);
973 }
974
975 if (isset($attr['queryAuthor']) && $attr['queryAuthor'] ) {
976 $_include = (substr($attr['queryAuthor'], 0, 1) === "[") ? $this->get_value(json_decode($attr['queryAuthor'])) : explode(',', $attr['queryAuthor']);
977 if (is_array($_include) && count($_include)) {
978 $query_args['author__in'] = $_include;
979 }
980 }
981
982 if (isset($attr['querySearch']) && $attr['querySearch'] ) {
983 $query_args['s'] = $attr['querySearch'];
984 }
985
986 if(isset($attr['querySticky']) && $attr['querySticky']) {
987 if (filter_var($attr['querySticky'], FILTER_VALIDATE_BOOLEAN)) {
988 $sticky = get_option( 'sticky_posts', [] );
989 $query_args['post__not_in'] = isset($query_args['post__not_in']) ? array_merge($query_args['post__not_in'], $sticky) : $sticky;
990 }
991 }
992
993 if (!isset($attr['ajaxCall'])) {
994 if(isset($attr['filterShow']) && $attr['filterShow'] && $attr['filterShow'] != 'false') {
995 if(isset($attr['checkFilter']) && isset($attr['queryTax']) && isset($attr['queryTaxValue']) ) {
996 $var = $this->getFilterQueryArgs($attr);
997 if (isset($var) && count($var) > 1) {
998 $query_args['tax_query'] = $var;
999 }
1000 }
1001 else if(isset($attr['filterType']) && isset($attr['filterValue'])) {
1002 $filterValue = strlen($attr['filterValue']) > 2 ? $attr['filterValue'] : [];
1003 $filterValue = is_array($filterValue) ? $filterValue : json_decode($filterValue);
1004 if (is_array($filterValue) && count($filterValue) > 0 && $attr['filterType']) {
1005 $final = array('relation' => 'OR');
1006 foreach ($filterValue as $key => $val) {
1007 $final[] = array(
1008 'taxonomy' => $attr['filterType'],
1009 'field' => 'slug',
1010 'terms' => $val,
1011 // 'operator' => '=',
1012 );
1013 }
1014 $query_args['tax_query'] = $final;
1015 }
1016 }
1017 }
1018 }
1019
1020 // Advanced Filter Select Dropdown Default value
1021 // only on initial page load
1022 if (
1023 ! wp_doing_ajax() &&
1024 isset($attr['advFilterEnable']) &&
1025 $attr['advFilterEnable'] === true &&
1026 isset($attr['defQueryTax']) &&
1027 count($attr['defQueryTax']) > 0
1028 ) {
1029 $tax_query = array(
1030 'relation' =>
1031 isset($attr['advRelation']) &&
1032 ('AND' === $attr['advRelation'] || 'OR' === $attr['advRelation'])
1033 ? $attr['advRelation'] : 'AND'
1034 );
1035 $is_valid = false;
1036
1037 foreach ($attr['defQueryTax'] as $_ => $defQueryTaxValue) {
1038 $term = explode('###', $defQueryTaxValue);
1039
1040 // Validation
1041 if (
1042 ! in_array($term[0], array('category', 'tags', 'author', 'custom_tax'), true) ||
1043 '_all' === $term[1] ||
1044 empty( $term[1] )
1045 ) {
1046 continue;
1047 }
1048
1049 if ('author' === $term[0]) {
1050
1051 if ( ! is_numeric( $term[1] ) ) {
1052 continue;
1053 }
1054
1055 $query_args['author__in'] = $term[1];
1056 }
1057
1058 elseif( 'custom_tax' === $term[0] && isset( $attr['queryType'] ) ) {
1059 $post_type = sanitize_key($attr['queryType']);
1060 $slug = sanitize_key($term[1]);
1061
1062 // These are not custom post type
1063 if ( in_array($post_type, array('posts', 'customPosts'), true) ) {
1064 continue;
1065 }
1066
1067 $taxonomy = $this->get_taxonomy_by_term_slug( $post_type, $slug );
1068
1069 if (! empty($taxonomy)) {
1070 $q = array(
1071 'field' => 'slug',
1072 'taxonomy' => $taxonomy,
1073 'terms' => $slug
1074 );
1075
1076 $tax_query[] = $q;
1077 $is_valid = true;
1078 }
1079 }
1080
1081 else {
1082 if ( ! is_numeric( $term[1] ) ) {
1083 continue;
1084 }
1085
1086 $q = array(
1087 'field' => 'term_id',
1088 'taxonomy' => 'tags' === $term[0] ? 'post_tag' : 'category',
1089 'terms' => $term[1]
1090 );
1091
1092 $tax_query[] = $q;
1093 $is_valid = true;
1094 }
1095 }
1096
1097 if ($is_valid) {
1098 $query_args['tax_query'] = $tax_query;
1099 }
1100 }
1101
1102 $query_args['wpnonce'] = wp_create_nonce( 'ultp-nonce' );
1103
1104 return apply_filters('ultp_frontend_query', $query_args);
1105 }
1106
1107 /**
1108 * Get Page Offset
1109 *
1110 * @since v.1.0.0
1111 * @param | Offset Number(NUMBER) | Query Arg(ARRAY)
1112 * @return ARRAY
1113 */
1114 function get_offset($queryOffset, $query_args) {
1115 $query = array();
1116 if ($query_args['paged'] > 1) {
1117 $offset_post = wp_get_recent_posts($query_args, OBJECT);
1118 if (count($offset_post) > 0 ) {
1119 $offset = array();
1120 for($x = count($offset_post); $x > count($offset_post) - $queryOffset; $x--) {
1121 $offset[] = $offset_post[$x-1]->ID;
1122 }
1123 $query['post__not_in'] = $offset;
1124 }
1125 } else {
1126 $query['offset'] = isset($queryOffset) ? $queryOffset : 0;
1127 }
1128 return $query;
1129 }
1130
1131
1132 /**
1133 * Get Page Number
1134 *
1135 * @since v.1.0.0
1136 * @param | Attribute of the Query(ARRAY) | Post Number(ARRAY)
1137 * @return ARRAY
1138 */
1139 public function get_page_number($attr, $post_number) {
1140 if ($post_number > 0) {
1141 if (isset($attr['queryOffset']) && $attr['queryOffset']) {
1142 $post_number = $post_number - (int)$attr['queryOffset'];
1143 }
1144 $post_per_page = isset($attr['queryNumber']) ? ($attr['queryNumber'] ? $attr['queryNumber'] : 1) : 3;
1145 $pages = ceil($post_number/$post_per_page);
1146 return $pages ? $pages : 1;
1147 }else{
1148 return 1;
1149 }
1150 }
1151
1152
1153 /**
1154 * Get Image Size
1155 *
1156 * @since v.1.0.0
1157 * @param | Attribute of the Query(ARRAY) | Post Number(ARRAY)
1158 * @return ARRAY
1159 */
1160 public function get_image_size() {
1161 $sizes = get_intermediate_image_sizes();
1162 $filter = array('full' => 'Full');
1163 foreach ($sizes as $value) {
1164 $title = ucwords(str_replace(array('_', '-', 'ultp'), array(' ', ' ', 'PostX'), $value));
1165 switch ($value) {
1166 case 'thumbnail':
1167 $title = $title.' [150x150]';
1168 break;
1169 case 'medium':
1170 $title = $title.' [300x300]';
1171 break;
1172 case 'large':
1173 $title = $title.' [1024x1024]';
1174 break;
1175 case 'ultp_layout_landscape_large':
1176 $title = $title.' [1200x800]';
1177 break;
1178 case 'ultp_layout_landscape':
1179 $title = $title.' [870x570]';
1180 break;
1181 case 'ultp_layout_portrait':
1182 $title = $title.' [600x900]';
1183 break;
1184 case 'ultp_layout_square':
1185 $title = $title.' [600x600]';
1186 break;
1187 default:
1188 break;
1189 }
1190 $filter[$value] = $title;
1191 }
1192 return $filter;
1193 }
1194
1195
1196 /**
1197 * Get All PostType Registered
1198 *
1199 * @since v.1.0.0
1200 * @param | Attribute of the Query(ARRAY) | Post Number(ARRAY)
1201 * @return ARRAY
1202 */
1203 public function get_post_type() {
1204 $filter = apply_filters('ultp_public_post_type', true);
1205 $post_type = get_post_types( ($filter ? ['public' => true] : ''), 'names' );
1206 return array_diff($post_type, array( 'attachment' ));
1207 }
1208
1209 /**
1210 * Get Pagination Url
1211 *
1212 * @since v.2.8.9
1213 * @param | pageNo (NUMBER) | baseUrl (STRING)
1214 * @return STRING
1215 */
1216 public function generatePaginationUrl($pageNo , $baseUrl) {
1217 if($baseUrl) {
1218 $url = $baseUrl.($pageNo == 1? '' : "page/".$pageNo);
1219 }
1220 else {
1221 $url = get_pagenum_link($pageNo);
1222 }
1223 return $url;
1224 }
1225 /**
1226 * Get Pagination HTML
1227 *
1228 * @since v.1.0.0
1229 * @param | pages (NUMBER) | Pagination Nav (STRING) | Pagination Text |
1230 * @return STRING
1231 */
1232 public function pagination($pages = '', $paginationNav = '', $paginationText = '', $paginationAjax = true, $baseUrl = '', $blockId = '') {
1233 $html = '';
1234 $showitems = 3;
1235 $paged = is_front_page() ? get_query_var('page') : get_query_var('paged');
1236 $paged = $paged ? $paged : 1;
1237
1238 $paged = ! wp_doing_ajax() &&
1239 isset( $_GET[ $blockId . '_page' ] ) &&
1240 is_numeric( $_GET[ $blockId . '_page' ] ) ?
1241 intval($_GET[ $blockId . '_page' ]) : $paged;
1242
1243 if ($pages == '') {
1244 global $wp_query;
1245 $pages = $wp_query->max_num_pages;
1246 if (!$pages) {
1247 $pages = 1;
1248 }
1249 }
1250
1251 $data = ($paged>=3?[($paged-1),$paged,$paged+1]:[1,2,3]);
1252
1253 $paginationText = explode('|', $paginationText);
1254
1255 $prev_text = isset($paginationText[0]) ? esc_html($paginationText[0]) : __("Previous", "ultimate-post");
1256 $next_text = isset($paginationText[1]) ? esc_html($paginationText[1]) : __("Next", "ultimate-post");
1257
1258 if (1 != $pages) {
1259 $html .= '<ul class="ultp-pagination">';
1260 $display_none = 'style="display:none"';
1261 if ($paged > 1 || $paginationAjax && $pages > 1) {
1262 $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>';
1263 }
1264 if ($pages > 3) {
1265 $html .= '<li class="ultp-first-pages" '.($paged < 2 ? $display_none : "").' data-current="1"><a href="'.$this->generatePaginationUrl(1, $baseUrl).'">1</a></li>';
1266 }
1267 if ($paged > 3 || $paginationAjax && $pages > 4) {
1268 $html .= '<li class="ultp-first-dot"'.($paged == 1 ? $display_none : "").'><a href="#">...</a></li>';
1269 }
1270 foreach ($data as $i) {
1271 if ( $pages > 3 && $pages == $i ) {
1272 continue;
1273 }
1274 if ($pages >= $i) {
1275 $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>';
1276 }
1277 }
1278 if($pages != ($paged + 2) || $paginationAjax && $pages > 4){
1279 $html .= '<li class="ultp-last-dot" '.($pages <= $paged + 1 ? $display_none : "").'><a href="#">...</a></li>';
1280 }
1281 if ($pages > 3) {
1282 $html .= '<li class="ultp-last-pages'.($paged == $pages ? ' pagination-active' : '').'" data-current="'.$pages.'"><a href="'.$this->generatePaginationUrl($pages, $baseUrl).'">'.$pages.'</a></li>';
1283 }
1284 if ($paged != $pages) {
1285 $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>';
1286 }
1287 $html .= '</ul>';
1288 }
1289 return $html;
1290 }
1291
1292 /**
1293 * Svg Icon Source
1294 *
1295 * @since v.1.0.0
1296 * @param string $ultp_icons
1297 * @return string
1298 */
1299 public function get_svg_icon( $ultp_icons = '' ) {
1300 $svg = '';
1301 if ( $ultp_icons ) {
1302 $svg = $this->get_path_file_contents(ULTP_PATH . 'assets/img/iconpack/' . $ultp_icons . '.svg');
1303 }
1304 return $svg;
1305 }
1306
1307 /**
1308 * Get Taxonomy Lists
1309 *
1310 * @since v.1.0.0
1311 * @param STRING | Taxonomy Slug
1312 * @return ARRAY
1313 */
1314 public function taxonomy( $prams = 'category' ) {
1315 $data = array();
1316
1317 $terms = get_terms( is_string($prams) ? array(
1318 'taxonomy' => $prams,
1319 'hide_empty' => false
1320 ) : $prams);
1321 if ( ! is_wp_error( $terms ) ) {
1322 foreach ( $terms as $val ) {
1323 $data[ urldecode_deep( $val->slug ) ] = $val->name;
1324 }
1325 }
1326 return $data;
1327 }
1328
1329
1330 /**
1331 * Get Taxonomy Lists
1332 *
1333 * @since v.2.9.0
1334 * @param STRING | Taxonomy Slug
1335 * @return ARRAY
1336 */
1337 public function builder_preview( $tax_slug, $number ) {
1338 $data = array();
1339 $term_data = get_terms( array( 'taxonomy' => $tax_slug, 'hide_empty' => true, 'number' => $number, 'parent' => 0 ) );
1340 if ( ! empty( $term_data ) ) {
1341 foreach ( $term_data as $terms ) {
1342 $data[] = $this->get_tax_data( $terms );
1343 }
1344 }
1345 return $data;
1346 }
1347
1348 /**
1349 * Get Taxonomy Data Lists
1350 *
1351 * @since v.1.0.0
1352 * @param OBJECT | Taxonomy Object
1353 * @return ARRAY
1354 */
1355 public function get_tax_data($terms) {
1356 $temp = array();
1357 $thumbnail_id = get_term_meta( $terms->term_id, 'ultp_category_image', true );
1358 $image_src = array();
1359 if ($thumbnail_id) {
1360 $image_sizes = ultimate_post()->get_image_size();
1361 foreach ($image_sizes as $key => $value) {
1362 $img_src = wp_get_attachment_image_src($thumbnail_id, $key, false);
1363 if( $img_src ) {
1364 $image_src[$key] = $img_src[0];
1365 }
1366 }
1367 }
1368 $temp['url'] = get_term_link($terms);
1369 $temp['thumbnail_id'] = $thumbnail_id;
1370 $temp['name'] = $terms->name;
1371 $temp['desc'] = $terms->description;
1372 $temp['count'] = $terms->count;
1373 $temp['image'] = $image_src;
1374 $color = get_term_meta($terms->term_id, 'ultp_category_color', true);
1375 $temp['color'] = $color ? $color : '#037fff';
1376 return $temp;
1377 }
1378
1379 public function get_category_data($catSlug, $number = 40, $type = '', $tax_slug = 'category', $archiveBuilder = '') {
1380 $data = array();
1381 if ($type == 'child') {
1382 if($archiveBuilder) {
1383 $data = $this->builder_preview( $tax_slug, $number );
1384 }
1385 else {
1386 if(is_category()) {
1387 $catSlug = array(get_queried_object()->slug);
1388 }
1389 $image = '';
1390 if (!empty($catSlug)) {
1391 foreach ($catSlug as $cat) {
1392 $parent_term = get_term_by('slug', $cat, $tax_slug);
1393 if (!empty($parent_term)) {
1394 $term_data = get_terms(array(
1395 'taxonomy' => $tax_slug,
1396 'hide_empty' => true,
1397 'number' => $number,
1398 'parent' => $parent_term->term_id
1399 ));
1400 if (!empty($term_data)) {
1401 foreach ($term_data as $terms) {
1402 $data[] = $this->get_tax_data($terms);
1403 }
1404 }
1405 }
1406 }
1407 }
1408 }
1409 } else if ($type == 'parent') {
1410 $term_data = is_category() ? array(get_term(get_queried_object()->parent, 'category')) : get_terms( array( 'taxonomy' => $tax_slug,'hide_empty' => true, 'number' => $number, 'parent' => 0 ) );
1411 if($archiveBuilder && !empty($term_data)) {
1412 $term_data = array($term_data[0]);
1413 }
1414 if (!empty($term_data)) {
1415 foreach ($term_data as $terms) {
1416 if (!empty($terms->term_id)) {
1417 $data[] = $this->get_tax_data($terms);
1418 }
1419 }
1420 }
1421 } else if ($type == 'custom') {
1422 foreach ($catSlug as $cat) {
1423 $terms = get_term_by('slug', $cat, $tax_slug);
1424 if (!empty($terms)) {
1425 $data[] = $this->get_tax_data($terms);
1426 }
1427 }
1428 } else if ($type == 'immediate_child') {
1429 if($archiveBuilder) {
1430 $data = $this->builder_preview( $tax_slug, $number );
1431 } else {
1432 $id_ = get_queried_object();
1433 if (isset($id_->term_id)) {
1434 $term_data = get_terms( array( 'taxonomy' => $tax_slug, 'hide_empty' => true, 'number' => 100, 'parent' => $id_->term_id) );
1435 if (!empty($term_data)) {
1436 foreach ($term_data as $terms) {
1437 $data[] = $this->get_tax_data($terms);
1438 }
1439 }
1440 }
1441 }
1442 } else if ($type == 'allchild') {
1443 if($archiveBuilder) {
1444 $data = $this->builder_preview( $tax_slug, $number );
1445 } else {
1446 $id_ = get_queried_object();
1447 if (isset($id_->term_taxonomy_id)) {
1448 $termchildren = get_term_children( $id_->term_taxonomy_id, $tax_slug );
1449 foreach ($termchildren as $key => $value) {
1450 $terms = get_term_by('id', $value, $tax_slug);
1451 $data[] = $this->get_tax_data($terms);
1452 }
1453 }
1454 }
1455 } else if ($type == 'current_level') {
1456 if($archiveBuilder) {
1457 $data = $this->builder_preview( $tax_slug, $number );
1458 } else {
1459 $id_ = get_queried_object();
1460 if (isset($id_->parent)) {
1461 $term_data = get_terms( array('taxonomy' => $tax_slug, 'hide_empty' => true, 'number' => $number, 'parent' => $id_->parent ) );
1462 if (!empty($term_data)) {
1463 foreach ($term_data as $terms) {
1464 if ($terms->term_id != $id_->term_id) {
1465 $data[] = $this->get_tax_data($terms);
1466 }
1467 }
1468 }
1469 }
1470 }
1471 } else {
1472 $term_data = get_terms( array('taxonomy' => $tax_slug, 'hide_empty' => true, 'number' => $number));
1473 if (!empty($term_data)) {
1474 foreach ($term_data as $terms) {
1475 $data[] = $this->get_tax_data($terms);
1476 }
1477 }
1478 }
1479 return $data;
1480 }
1481
1482
1483 /**
1484 * Get Next Previous HTML
1485 *
1486 * @since v.1.0.0
1487 * @param OBJECT | Taxonomy Object
1488 * @return STRING
1489 */
1490 public function next_prev() {
1491 $html = '';
1492 $html .= '<ul>';
1493 $html .= '<li>';
1494 $html .= '<a class="ultp-prev-action ultp-disable" href="#">';
1495 $html .= ultimate_post()->get_svg_icon('leftAngle2').'<span class="screen-reader-text">'.esc_html__("Previous", "ultimate-post").'</span>';
1496 $html .= '</a>';
1497 $html .= '</li>';
1498 $html .= '<li>';
1499 $html .= '<a class="ultp-next-action">';
1500 $html .= ultimate_post()->get_svg_icon('rightAngle2').'<span class="screen-reader-text">'.esc_html__("Next", "ultimate-post").'</span>';
1501 $html .= '</a>';
1502 $html .= '</li>';
1503 $html .= '</ul>';
1504 return $html;
1505 }
1506
1507
1508 /**
1509 * Get Loading HTML
1510 *
1511 * @since v.1.0.0
1512 * @param NULL
1513 * @return STRING
1514 */
1515 public function postx_loading() {
1516 $html = '';
1517 $style = ultimate_post()->get_setting('preloader_style');
1518 if ($style == 'style2') {
1519 $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
1520 } else {
1521 $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>';
1522 }
1523 return '<div class="ultp-loading">'.$html.'</div>';
1524 }
1525
1526
1527 /**
1528 * Get Filter HTML
1529 *
1530 * @since v.1.0.0
1531 * @param | Filter Text (STRING) | Filter Type (STRING) | Filter Value (ARRAY) | Filter Cat (ARRAY) | Filter Tag (ARRAY) |
1532 * @return STRING
1533 */
1534 public function filter_html($filterText = '', $filterType = '', $filterValue = '[]', $filterMobileText = '...', $filterMobile = true) {
1535 $html = '';
1536 $html .= '<ul '.($filterMobile ? 'class="ultp-flex-menu"' : '').' data-name="'.($filterMobileText ? $filterMobileText : '&nbsp;').'">';
1537 $cat = $this->taxonomy($filterType);
1538 if ($filterText) {
1539 $html .= '<li class="filter-item"><a class="filter-active" data-taxonomy="" href="#">'.$filterText.'</a></li>';
1540 }
1541 if ($filterValue) {
1542 $filterValue = strlen($filterValue) > 2 ? $filterValue : [];
1543 $filterValue = is_array($filterValue) ? $filterValue : json_decode($filterValue);
1544 if (is_array($filterValue) && count($filterValue)) {
1545 foreach ($filterValue as $val) {
1546 $val = isset($val->value) ? $val->value : $val;
1547 $html .= '<li class="filter-item"><a data-taxonomy="'.$val.'" href="#">'.(isset($cat[$val]) ? $cat[$val] : $val).'</a></li>';
1548 }
1549 }
1550 }
1551 $html .= '</ul>';
1552 return $html;
1553 }
1554
1555
1556 /**
1557 * Check License Status
1558 *
1559 * @since v.2.4.2
1560 * @return BOOLEAN | Is pro license active or not
1561 */
1562 public function is_lc_active() {
1563 if (function_exists('ultimate_post_pro')) {
1564 return get_option('edd_ultp_license_status') == 'valid' ? true : false;
1565 }
1566 return false;
1567 }
1568
1569
1570 /**
1571 * Check License Status
1572 *
1573 * @since v.4.1.25
1574 * @return BOOLEAN | Is pro license active or not
1575 */
1576 public function is_lc_expired($date) {
1577 if (function_exists('ultimate_post_pro')) {
1578 if(get_option('edd_ultp_license_expire') == "lifetime") {
1579 return false;
1580 } else {
1581 return strtotime($date) > strtotime(get_option('edd_ultp_license_expire'));
1582 }
1583 }
1584 return false;
1585 }
1586
1587 /**
1588 * Get SEO Meta
1589 *
1590 * @since v.2.4.3
1591 * @param NUMBER | Post ID
1592 * @return STRING | SEO Meta Description or Excerpt
1593 */
1594 public function get_excerpt($post_id = 0, $showSeoMeta = 0, $showFullExcerpt = 0, $excerptLimit = 55) {
1595 $html = '';
1596 if ($showSeoMeta) {
1597 $str = '';
1598 if ( function_exists('ultimate_post_pro') ) {
1599 if ( ultimate_post()->get_setting('ultp_yoast') == 'true' ) {
1600 $str = method_exists( ultimate_post_pro(), 'get_yoast_meta' ) ? ultimate_post_pro()->get_yoast_meta($post_id) : '';
1601 } else if ( ultimate_post()->get_setting('ultp_rankmath') == 'true' ) {
1602 $str = method_exists( ultimate_post_pro(), 'get_rankmath_meta' ) ? ultimate_post_pro()->get_rankmath_meta($post_id) : '';
1603 } else if ( ultimate_post()->get_setting('ultp_aioseo') == 'true' ) {
1604 $str = method_exists( ultimate_post_pro(), 'get_aioseo_meta' ) ? ultimate_post_pro()->get_aioseo_meta($post_id) : '';
1605 } else if ( ultimate_post()->get_setting('ultp_seopress') == 'true' ) {
1606 $str = method_exists( ultimate_post_pro(), 'get_seopress_meta' ) ? ultimate_post_pro()->get_seopress_meta($post_id) : '';
1607 } else if ( ultimate_post()->get_setting('ultp_squirrly') == 'true' ) {
1608 $str = method_exists( ultimate_post_pro(), 'get_squirrly_meta' ) ? ultimate_post_pro()->get_squirrly_meta($post_id) : '';
1609 }
1610 }
1611 $html = $str ? $str : ultimate_post()->excerpt($post_id, $excerptLimit);
1612 } else {
1613 if ($showFullExcerpt == 0 ) {
1614 $html = ultimate_post()->excerpt($post_id, $excerptLimit);
1615 } else {
1616 $html = get_the_excerpt();
1617 }
1618 }
1619 return $html;
1620 }
1621
1622 public function get_embeded_video($url, $autoPlay, $loop, $mute, $playback, $preload, $poster, $inline, $size) {
1623 $vidAutoPlay = $vidloop = $vidloop = $vidmute = $vidplayback = $vidPoster = $vidInline = "";
1624
1625 if($autoPlay){
1626 $vidAutoPlay = "autoplay";
1627 }
1628 if($poster){
1629 $vidPoster = 'poster="'.$poster["url"].'"';
1630 }
1631 if($loop){
1632 $vidloop = "loop";
1633 }
1634 if($mute){
1635 $vidmute = "muted";
1636 }
1637 if($playback){
1638 $vidplayback = "controls";
1639 }
1640 if($inline){
1641 $vidInline = "playsinline";
1642 }
1643 if (!empty($url)) {
1644 $embeded = wp_oembed_get($url, $size);
1645 if ($embeded == false) {
1646 $format = '';
1647 $url = strtolower($url);
1648 if (strpos($url, '.mp4')) {
1649 $format = 'mp4';
1650 } elseif (strpos($url, '.ogg')) {
1651 $format = 'ogg';
1652 } elseif (strpos($url, '.webm')) {
1653 $format = 'WebM';
1654 }
1655 $embeded = '<video
1656 '.$vidloop.'
1657 '.$vidmute.'
1658 '.$vidplayback.'
1659 preload="'.$preload.'"
1660 '.$vidAutoPlay.'
1661 '.$vidPoster.'
1662 '.$vidInline.'
1663 class="ultp-video-html"
1664 ><source src="' . $url . '" type="video/' . $format . '">' . __('Your browser does not support the video tag.', 'ultimate-post') . '</video>';
1665 return '<div class="ultp-video-wrapper">'.$embeded.'</div>';
1666 }
1667 return '<div class="ultp-video-wrapper ultp-embaded-video">'.$embeded.'</div>';
1668 } else {
1669 return false;
1670 }
1671 }
1672
1673 /**
1674 * Get Public taxonomy Lists
1675 *
1676 * @since v.2.7.0
1677 * @param NULL
1678 * @return ARRAY | Taxonomy Lists as array
1679 */
1680 public function get_taxonomy_list() {
1681 $taxonomy = get_taxonomies(array('public' => true));
1682 return empty($taxonomy) ? [] : array_keys($taxonomy);
1683 }
1684
1685 /**
1686 * Content Print
1687 *
1688 * @since v.2.7.0
1689 * @param NUMBER | Post ID
1690 * @return STRING | Content of the Post
1691 */
1692 public function get_post_content($post_id, $builder_type = '') {
1693 $content_post = get_post($post_id);
1694 $content = $content_post->post_content;
1695 if($builder_type == 'divi' || $builder_type == 'elementor') {
1696 $content = apply_filters('the_content', $content);
1697 } else {
1698 global $wp_embed;
1699 $content = $wp_embed->autoembed( $content );
1700 $content = do_blocks($content);
1701 $content = do_shortcode($content);
1702 }
1703 $content = str_replace(']]>', ']]&gt;', $content);
1704 $content = preg_replace('%<p>&nbsp;\s*</p>%', '', $content);
1705 $content = preg_replace('/^(?:<br\s*\/?>\s*)+/', '', $content);
1706 echo $content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1707 }
1708
1709 /**
1710 * String Part finder inside array
1711 *
1712 * @since v.2.7.0 updated 4.1.12
1713 * @return ARRAY | String Part
1714 */
1715 public function in_array_part($part, $data, $toR = '') {
1716 $res = array();
1717 foreach( $data as $key => $val ) {
1718 if ( strpos( $val, $part ) !== false ) {
1719 if ( $toR == 'bool' ) {
1720 return true;
1721 } else if ( $toR == 'value' ) {
1722 return $val;
1723 }
1724 $res[$key] = $val;
1725 }
1726 }
1727 if ( $toR == 'bool' ) {
1728 return false;
1729 } else if ( $toR == 'value' ) {
1730 return '';
1731 }
1732 return $res;
1733 }
1734
1735 /**
1736 * Builder Conditions
1737 *
1738 * @since v.2.7.0 updated 4.1.12
1739 * @param STRING | Type of Return
1740 * @return MIXED || ID or Path
1741 */
1742 public function builder_check_conditions( $type = 'return', $cus_condition = '' ) {
1743 $page_id = '';
1744 $conditions = $cus_condition ? $cus_condition : get_option('ultp_builder_conditions', array());
1745
1746 if ( $type == 'header' || $type == 'footer' ) {
1747 if ( !empty($conditions[$type]) ) {
1748 foreach( $conditions[$type] as $key => $val) {
1749 if ( 'publish' == get_post_status($key) && !empty($val) ) {
1750 if ( in_array('include/'.$type.'/entire_site', $val) ) {
1751 $page_id = $key;
1752 } else if ( in_array('exclude/'.$type.'/entire_site', $val) ) {
1753 $page_id = '';
1754 }
1755
1756 $c_page = ( is_archive() || is_search() ) ? 'archive' : 'singular';
1757 $hf_archive = $this->in_array_part($type.'/'.$c_page, $val, '');
1758 if ( !empty($hf_archive) ) {
1759 foreach($hf_archive as $k => $v) {
1760 if ( strpos($v, 'include/'.$type.'/'.$c_page) !== false ) {
1761 $temp = $this->builder_check_conditions('return_'.$type, [$c_page => [$key => [str_replace($type."/", "", $v)]]]);
1762 $page_id = $temp ? $temp : $page_id;
1763 } else if (strpos($v, 'exclude/'.$type.'/'.$c_page) !== false) {
1764 $temp = $this->builder_check_conditions('return_'.$type, [$c_page => [$key => [str_replace("exclude/".$type, "include", $v)]]]);
1765 $page_id = $temp ? '' : $page_id;
1766 }
1767 }
1768 }
1769 }
1770 }
1771 }
1772 } else {
1773 // 404 page
1774 if ( !empty($conditions['404']) && is_404() ) {
1775 foreach( $conditions['404'] as $key => $val ) {
1776 if ( 'publish' == get_post_status($key) ) {
1777 $page_id = $key;
1778 }
1779 }
1780 }
1781 // Singular or Front Page
1782 else if (
1783 (
1784 !empty($conditions['singular']) ||
1785 !empty($conditions['front_page'])
1786 ) &&
1787 (
1788 is_singular() ||
1789 is_front_page() ||
1790 is_home()
1791 )
1792 ) {
1793 $obj = get_queried_object();
1794 $queried_is_obj = is_object($obj);
1795 // front page only
1796 if (
1797 ( is_front_page() && is_home() ) ||
1798 ( is_home() && !$queried_is_obj ) ||
1799 ( is_singular() && is_front_page() && $queried_is_obj )
1800 ) {
1801 $f_conditions = [];
1802 if ( !empty($conditions['front_page']) ) {
1803 $f_conditions = $conditions['front_page'];
1804 } else if ( !empty($conditions['singular']) ) {
1805 $f_conditions = $conditions['singular'];
1806 }
1807 if ( !empty($f_conditions) ) {
1808 foreach( $f_conditions as $key => $val ) {
1809 if (
1810 ( is_array($val) && in_array('include/singular/front_page', $val) ) ||
1811 ( is_array($val) && in_array('include/front_page', $val) ) ||
1812 'include/front_page' == $val
1813 ) {
1814 if ( 'publish' == get_post_status($key) ) {
1815 $page_id = $key;
1816 }
1817 }
1818 // Default Front / Home page Header Footer Compatibility
1819 else if (is_array($val) && 'publish' == get_post_status($key) && ($type == 'return_header' || $type == 'return_footer')) {
1820 $base_include = 'include/singular/' . $obj->post_type;
1821 $base_exclude = 'exclude/singular/' . $obj->post_type;
1822 $specific_include = $base_include . '/' . $obj->ID;
1823 $specific_exclude = $base_exclude . '/' . $obj->ID;
1824
1825 if (in_array($specific_include, $val)) {
1826 $page_id = $key;
1827 } elseif (in_array($specific_exclude, $val)) {
1828 $page_id = '';
1829 } elseif (in_array($base_include, $val)) {
1830 $page_id = $key;
1831 } elseif (in_array($base_exclude, $val)) {
1832 $page_id = '';
1833 }
1834 }
1835 }
1836 }
1837 }
1838 // Singular page
1839 else if ( !empty($conditions['singular']) ) {
1840 foreach( $conditions['singular'] as $key => $val ) {
1841 if ( 'publish' == get_post_status($key) ) {
1842 // All Post Type -----Prority 1
1843 if ( $queried_is_obj ) {
1844 if ( in_array('include/singular/'.$obj->post_type, $val) ) {
1845 $page_id = $key;
1846 } else if ( in_array('exclude/singular/'.$obj->post_type, $val) ) {
1847 $page_id = '';
1848 }
1849 }
1850
1851 $singular_in_tax = $this->in_array_part("/singular/in_", $val, '');
1852 if ( !empty($singular_in_tax) ) {
1853 $tax_list = $this->get_taxonomy_list();
1854 foreach( $tax_list as $tax ) {
1855 if ( in_array('include/singular/in_'.$tax.'_children', $singular_in_tax) ) {
1856 $page_id = $key;
1857 } else if ( in_array('exclude/singular/in_'.$tax.'_children', $singular_in_tax) ) {
1858 $page_id = '';
1859 }
1860
1861 if ( $queried_is_obj ) {
1862 $singular_in_tax_children = $this->in_array_part('/singular/in_'.$tax.'_children/', $singular_in_tax, '');
1863 foreach( $singular_in_tax_children as $v ) {
1864 $data = explode("/", $v);
1865 if ( isset($data[3]) && $data[3] ) {
1866 $childs = get_term_children( $data[3], $tax );
1867 if ( !empty($childs) && has_term($childs, $tax) ) {
1868 $page_id = $data[0] == 'exclude' ? '' : $key;
1869 }
1870 }
1871 }
1872 }
1873
1874 if ( in_array('include/singular/in_'.$tax, $singular_in_tax) ) {
1875 if ( $tax == "post_tag" && $queried_is_obj) {
1876 $cat = get_the_terms($obj->ID, "post_tag");
1877 if ( !empty( $cat ) ) {
1878 $page_id = $key;
1879 }
1880 } else {
1881 $page_id = $key;
1882 }
1883 } else if ( in_array('exclude/singular/in_'.$tax, $singular_in_tax) ) {
1884 $page_id = '';
1885 }
1886
1887 if ( $queried_is_obj ) {
1888 $singular_in_tax_only = $this->in_array_part('/singular/in_'.$tax.'/', $singular_in_tax, '');
1889 foreach( $singular_in_tax_only as $v ) {
1890 $data = explode("/", $v);
1891 if ( isset($data[3]) && $data[3] ) {
1892 if ( is_object_in_term($obj->ID , $tax, $data[3] ) ) {
1893 $page_id = $data[0] == 'exclude' ? '' : $key;
1894 }
1895 }
1896 }
1897 }
1898 }
1899 }
1900
1901 // Posts by author -----Prority 9
1902 if ( in_array('include/singular/post_by_author', $val) ) {
1903 $page_id = $key;
1904 } else if ( in_array('exclude/singular/post_by_author', $val) ) {
1905 $page_id = '';
1906 }
1907 if ( $queried_is_obj ) {
1908 if ( in_array('include/singular/post_by_author/'.$obj->post_author, $val) ) {
1909 $page_id = $key;
1910 } else if ( in_array('exclude/singular/post_by_author/'.$obj->post_author, $val) ) {
1911 $page_id = '';
1912 }
1913 // Post Type with specific id -----Prority 10
1914 if ( in_array('include/singular/'.$obj->post_type.'/'.$obj->ID, $val) ) {
1915 $page_id = $key;
1916 } else if ( in_array('exclude/singular/'.$obj->post_type.'/'.$obj->ID, $val) ) {
1917 $page_id = '';
1918 }
1919 }
1920 }
1921 }
1922 }
1923 }
1924
1925 // Archive and Search Page
1926 else if ( !empty($conditions['archive']) ) {
1927 // Search Page
1928 if ( is_search() ) {
1929 foreach( $conditions['archive'] as $key => $val ) {
1930 if ( 'publish' == get_post_status($key) ) {
1931 if ( in_array('include/archive/search', $val) ) {
1932 $page_id = $key;
1933 } else if ( in_array('exclude/archive/search', $val) ) {
1934 $page_id = '';
1935 }
1936 }
1937 }
1938 }
1939 // Archive Page
1940 else if ( is_archive() ) {
1941 $is_cat = is_category();
1942 $is_tag = is_tag();
1943 $is_tax = is_tax();
1944 $is_date = is_date();
1945 $is_author = is_author();
1946 $taxonomy = ( $is_cat || $is_tag || $is_tax ) ? get_queried_object() : (object)[];
1947
1948 foreach( $conditions['archive'] as $key => $val ) {
1949 if ( 'publish' == get_post_status($key) ) {
1950 // This section is for all archive page
1951 if ( in_array('include/archive', $val) ) {
1952 $page_id = $key;
1953 } else if ( in_array('exclude/archive', $val) ) {
1954 $page_id = '';
1955 }
1956 // For Category
1957 if ( $is_cat ) {
1958 // all category
1959 if ( in_array('include/archive/category', $val) ) {
1960 $page_id = $key;
1961 } else if ( in_array('exclude/archive/category', $val) ) {
1962 $page_id = '';
1963 }
1964 // specific category
1965 if ( in_array('include/archive/category/'.$taxonomy->term_id, $val) ) {
1966 $page_id = $key;
1967 } else if ( in_array('exclude/archive/category/'.$taxonomy->term_id, $val) ) {
1968 $page_id = '';
1969 }
1970
1971 // any child of category
1972 if ( in_array('include/archive/any_child_of_category', $val) ) {
1973 $page_id = $key;
1974 } else if ( in_array('exclude/archive/any_child_of_category', $val) ) {
1975 $page_id = '';
1976 }
1977
1978 $any_child_of_cat = $this->in_array_part("archive/any_child_of_category/", $val, '');
1979 if ( !empty($any_child_of_cat) ) {
1980 foreach( $any_child_of_cat as $v ) {
1981 $data = explode("/", $v);
1982 if ( isset($data[3]) && $data[3] ) {
1983 if ( term_is_ancestor_of($data[3], $taxonomy->term_id, 'category') ) {
1984 $page_id = $data[0] == 'exclude' ? '' : $key;
1985 }
1986 }
1987 }
1988 }
1989
1990 // all child of category
1991 if ( in_array('include/archive/child_of_category', $val) ) {
1992 $page_id = $key;
1993 } else if ( in_array('exclude/archive/child_of_category', $val) ) {
1994 $page_id = '';
1995 }
1996 // specific child of category
1997 if ( in_array('include/archive/child_of_category/'.$taxonomy->parent, $val) ) {
1998 $page_id = $key;
1999 } else if ( in_array('exclude/archive/child_of_category/'.$taxonomy->parent, $val) ) {
2000 $page_id = '';
2001 }
2002 }
2003 // For Tag
2004 else if ( $is_tag ) {
2005 if ( in_array('include/archive/post_tag', $val) ) {
2006 $page_id = $key;
2007 } else if ( in_array('exclude/archive/post_tag', $val) ) {
2008 $page_id = '';
2009 }
2010 if ( in_array('include/archive/post_tag/'.$taxonomy->term_id, $val) ) {
2011 $page_id = $key;
2012 } else if ( in_array('exclude/archive/post_tag/'.$taxonomy->term_id, $val) ) {
2013 $page_id = '';
2014 }
2015 }
2016 // Other taxonomy
2017 else if ( $is_tax ) {
2018 if ( in_array('include/archive/'.$taxonomy->taxonomy, $val) ) {
2019 $page_id = $key;
2020 } else if ( in_array('exclude/archive/'.$taxonomy->taxonomy, $val) ) {
2021 $page_id = '';
2022 }
2023
2024 if ( in_array('include/archive/'.$taxonomy->taxonomy.'/'.$taxonomy->term_id, $val) ) {
2025 $page_id = $key;
2026 } else if ( in_array('exclude/archive/'.$taxonomy->taxonomy.'/'.$taxonomy->term_id, $val) ) {
2027 $page_id = '';
2028 }
2029
2030 if ( in_array('include/archive/any_child_of_'.$taxonomy->taxonomy, $val) ) {
2031 $page_id = $key;
2032 } else if ( in_array('exclude/archive/any_child_of_'.$taxonomy->taxonomy, $val) ) {
2033 $page_id = '';
2034 }
2035
2036 $any_child_of_tax = $this->in_array_part('archive/any_child_of_'.$taxonomy->taxonomy.'/', $val, '');
2037 if ( !empty($any_child_of_tax) ) {
2038 foreach( $any_child_of_tax as $v ) {
2039 $data = explode("/", $v);
2040 if ( isset($data[3]) && $data[3] ) {
2041 if ( term_is_ancestor_of($data[3], $taxonomy->term_id, $taxonomy->taxonomy) ) {
2042 $page_id = $data[0] == 'exclude' ? '' : $key;
2043 }
2044 }
2045 }
2046 }
2047
2048 if ( in_array('include/archive/child_of_'.$taxonomy->taxonomy, $val) ) {
2049 $page_id = $key;
2050 } else if ( in_array('exclude/archive/child_of_'.$taxonomy->taxonomy, $val) ) {
2051 $page_id = '';
2052 }
2053
2054 if ( in_array('include/archive/child_of_'.$taxonomy->taxonomy.'/'.$taxonomy->parent, $val) ) {
2055 $page_id = $key;
2056 } else if ( in_array('exclude/archive/child_of_'.$taxonomy->taxonomy.'/'.$taxonomy->parent, $val) ) {
2057 $page_id = '';
2058 }
2059
2060 }
2061 // For Date
2062 else if ( $is_date ) {
2063 if ( in_array('include/archive/date', $val) ) {
2064 $page_id = $key;
2065 } else if ( in_array('exclude/archive/date', $val) ) {
2066 $page_id = '';
2067 }
2068 }
2069 // For Author
2070 else if ( $is_author ) {
2071 if ( in_array('include/archive/author', $val) ) {
2072 $page_id = $key;
2073 } else if ( in_array('exclude/archive/author', $val) ) {
2074 $page_id = '';
2075 }
2076 $author_id = get_the_author_meta('ID');
2077 if ( in_array('include/archive/author/'.$author_id, $val) ) {
2078 $page_id = $key;
2079 } else if ( in_array('exclude/archive/author/'.$author_id, $val) ) {
2080 $page_id = '';
2081 }
2082 }
2083 }
2084 }
2085 }
2086 }
2087 }
2088 return $page_id;
2089 }
2090
2091 /**
2092 * Get Date Default Format
2093 *
2094 * @since v.2.7.2
2095 * @return ARRAY | Default Data
2096 */
2097 public function get_format($format) {
2098 if ($format == 'default_date') {
2099 return get_option('date_format');
2100 } else if ($format == 'default_date_time') {
2101 return get_option('date_format').' '.get_option('time_format');
2102 } else {
2103 return $format;
2104 }
2105 }
2106
2107 /**
2108 * Common Frontend and Backend CSS and JS Scripts
2109 *
2110 * @since v.1.0.0
2111 * @return NULL
2112 */
2113 public function register_scripts_common() {
2114 if ( !( isset($GLOBALS['wp_scripts']) && isset($GLOBALS['wp_scripts']->registered) && isset($GLOBALS['wp_scripts']->registered['ultp-script']) ) ) {
2115 wp_enqueue_style('ultp-style', ULTP_URL.'assets/css/style.min.css', array(), ULTP_VER );
2116 wp_enqueue_script('ultp-script', ULTP_URL.'assets/js/ultp.min.js', array('jquery', 'wp-api-fetch'), ULTP_VER, true);
2117 wp_localize_script('ultp-script', 'ultp_data_frontend', array(
2118 'url' => ULTP_URL,
2119 'active' => ultimate_post()->is_lc_active(),
2120 'ultpSavedDLMode' => ultimate_post()->get_dl_mode(),
2121 'ajax' => admin_url('admin-ajax.php'),
2122 'security' => wp_create_nonce('ultp-nonce'),
2123 'home_url' => home_url(),
2124 'dark_logo' => get_option('ultp_site_dark_logo', false)
2125 ));
2126 }
2127 }
2128 /**
2129 * Get Dark Light Mode
2130 *
2131 * @since 4.0.0
2132 * @return string
2133 */
2134 public function get_dl_mode() {
2135 $data = get_option('postx_global', []);
2136 $mode = 'ultplight';
2137 if(!empty($data)) {
2138 $mode = isset($data['enableDark']) && $data['enableDark'] ? 'ultpdark' : 'ultplight';
2139 }
2140 return $mode;
2141 }
2142
2143 /**
2144 * Get Page Post Id ( Kadence element )
2145 *
2146 * @since v.2.8.9
2147 * @return NULL
2148 */
2149 public function get_page_post_id($blockId) {
2150 global $wpdb;
2151 $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
2152 // For FSE theme
2153 if ( !$post_meta ) {
2154 if ( wp_is_block_theme() ) {
2155 $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
2156 if ( isset($template->ID) ) {
2157 return $template->ID;
2158 }
2159 }
2160 }
2161 if ( $post_meta && isset($post_meta->post_id) ) {
2162 return $post_meta->post_id;
2163 }
2164 return ultimate_post()->get_ID();
2165 }
2166
2167
2168 /**
2169 * Get no Result found html
2170 *
2171 * @since v.2.9.0
2172 * @param STRING | No result found text
2173 * @return STRING | Taxonomy Lists as array
2174 */
2175 public function get_no_result_found_html($text) {
2176 return $text ? '<div class="ultp-not-found-message" role="alert">'.wp_kses($text, ultimate_post()->ultp_allowed_html_tags()).'</div>' : '';
2177 }
2178
2179 /**
2180 * Get all Saved Templates Lists
2181 *
2182 * @since v.2.9.9
2183 * @param STRING | No result found text
2184 * @return STRING | Taxonomy Lists as array
2185 */
2186 public function get_all_lists($post_type = 'post', $empty = '') {
2187 $args = array(
2188 'post_type' => $post_type,
2189 'post_status' => 'publish',
2190 'posts_per_page' => -1
2191 );
2192 $loop = new \WP_Query( $args );
2193 $data[ $empty ? $empty : '' ] = __( '- Select Template -', 'ultimate-post' );
2194 if($loop->have_posts()){
2195 foreach ( $loop->posts as $post ) {
2196 $data[$post->ID] = $post->post_title ;
2197 }
2198 }
2199 wp_reset_postdata();
2200 return $data;
2201 }
2202
2203 /**
2204 * Get ID from the Youtube URL
2205 *
2206 * @since v.3.1.7
2207 * @param STRING | No result found text
2208 * @return STRING | Taxonomy Lists as array
2209 */
2210 public function get_youtube_id($url = '') {
2211 if (strpos($url, 'youtu') !== false) {
2212 $reg = '/youtu(?:.*\/v\/|.*v\=|\.be\/)([A-Za-z0-9_\-]{11})/m';
2213 preg_match($reg, $url, $matches);
2214 if (isset($matches[1])) {
2215 return $matches[1];
2216 }
2217 }
2218 return false;
2219 }
2220
2221 /**
2222 * Get Option Value bypassing cache
2223 * Inspired By WordPress Core get_option
2224 * @since v.3.1.6
2225 * @param string $option Option Name.
2226 * @param boolean $default_value option default value.
2227 * @return mixed
2228 */
2229 public function get_option_without_cache($option, $default_value=false) {
2230 global $wpdb;
2231
2232 if ( is_scalar( $option ) ) {
2233 $option = trim( $option );
2234 }
2235
2236 if ( empty( $option ) ) {
2237 return false;
2238 }
2239
2240 $value = $default_value;
2241
2242 $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
2243
2244 if ( is_object( $row ) ) {
2245 $value = $row->option_value;
2246 } else {
2247 return apply_filters( "ultp_default_option_{$option}", $default_value, $option );
2248 }
2249
2250 return apply_filters( "ultp_option_{$option}", maybe_unserialize( $value ), $option );
2251 }
2252
2253 /**
2254 * Get Transient Value bypassing cache
2255 * Inspired By WordPress Core get_transient
2256 * @since v.3.1.6
2257 * @param string $transient Transient Name.
2258 * @return mixed
2259 */
2260 public function get_transient_without_cache($transient) {
2261 $transient_option = '_transient_' . $transient;
2262 $transient_timeout = '_transient_timeout_' . $transient;
2263 $timeout = $this->get_option_without_cache( $transient_timeout );
2264
2265 if ( false !== $timeout && $timeout < time() ) {
2266 delete_option( $transient_option );
2267 delete_option( $transient_timeout );
2268 $value = false;
2269 }
2270
2271 if ( ! isset( $value ) ) {
2272 $value = $this->get_option_without_cache( $transient_option );
2273 }
2274
2275 return apply_filters( "ultp_transient_{$transient}", $value, $transient );
2276 }
2277
2278 /**
2279 * Set transient without adding to the cache
2280 * Inspired By WordPress Core set_transient
2281 * @since v.3.1.6
2282 * @param string $transient Transient Name.
2283 * @param mixed $value Transient Value.
2284 * @param integer $expiration Time until expiration in seconds.
2285 * @return bool
2286 */
2287 public function set_transient_without_cache($transient, $value, $expiration = 0) {
2288 $expiration = (int) $expiration;
2289
2290 $transient_timeout = '_transient_timeout_' . $transient;
2291 $transient_option = '_transient_' . $transient;
2292
2293 $result = false;
2294
2295 if ( false === $this->get_option_without_cache( $transient_option ) ) {
2296 $autoload = 'yes';
2297 if ( $expiration ) {
2298 $autoload = 'no';
2299 $this->add_option_without_cache( $transient_timeout, time() + $expiration, 'no' );
2300 }
2301 $result = $this->add_option_without_cache( $transient_option, $value, $autoload );
2302 } else {
2303 /*
2304 * If expiration is requested, but the transient has no timeout option,
2305 * delete, then re-create transient rather than update.
2306 */
2307 $update = true;
2308
2309 if ( $expiration ) {
2310 if ( false === $this->get_option_without_cache( $transient_timeout ) ) {
2311 delete_option( $transient_option );
2312 $this->add_option_without_cache( $transient_timeout, time() + $expiration, 'no' );
2313 $result = $this->add_option_without_cache( $transient_option, $value, 'no' );
2314 $update = false;
2315 } else {
2316 update_option( $transient_timeout, time() + $expiration );
2317 }
2318 }
2319
2320 if ( $update ) {
2321 $result = update_option( $transient_option, $value );
2322 }
2323 }
2324
2325 return $result;
2326
2327 }
2328
2329 /**
2330 * Add option without adding to the cache
2331 * Inspired By WordPress Core set_transient
2332 * @since v.3.1.6
2333 * @param string $option option name.
2334 * @param string $value option value.
2335 * @param string $autoload whether to load wordpress startup.
2336 * @return bool
2337 */
2338 public function add_option_without_cache( $option, $value = '', $autoload = 'yes' ) {
2339 global $wpdb;
2340
2341
2342 if ( is_scalar( $option ) ) {
2343 $option = trim( $option );
2344 }
2345
2346 if ( empty( $option ) ) {
2347 return false;
2348 }
2349
2350 wp_protect_special_option( $option );
2351
2352 if ( is_object( $value ) ) {
2353 $value = clone $value;
2354 }
2355
2356 $value = sanitize_option( $option, $value );
2357
2358 /*
2359 * Make sure the option doesn't already exist.
2360 */
2361
2362 if ( apply_filters( "ultp_default_option_{$option}", false, $option, false ) !== $this->get_option_without_cache( $option ) ) {
2363 return false;
2364 }
2365
2366
2367 $serialized_value = maybe_serialize( $value );
2368 $autoload = ( 'no' === $autoload || false === $autoload ) ? 'no' : 'yes';
2369
2370
2371 $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
2372 if ( ! $result ) {
2373 return false;
2374 }
2375
2376 return true;
2377 }
2378
2379 /**
2380 * permission_check_for_restapi
2381 * @since v.3.2.4
2382 * @param $post_id string/bool
2383 * @param $cap string
2384 * @return bool
2385 */
2386 public function permission_check_for_restapi( $post_id=false, $cap='' ) {
2387 $cap = $cap ? $cap : 'edit_others_posts';
2388 $is_passed = false;
2389 if($post_id) {
2390 $post_author =(int) get_post_field('post_author',$post_id);
2391 $is_passed = (int)get_current_user_id()===$post_author;
2392 }
2393 return $is_passed || current_user_can($cap);
2394 }
2395
2396 /**
2397 * Sanitize params
2398 * @param $params
2399 * @return array|bool|mixed|string
2400 * @since v.4.0.0
2401 */
2402 public function ultp_rest_sanitize_params($params) {
2403 if ( is_array($params) ) {
2404 return array_map(array($this,'ultp_rest_sanitize_params'),$params);
2405 } else {
2406 if( is_bool($params) ) {
2407 return rest_sanitize_boolean($params);
2408 } else if( is_object($params) ) {
2409 return $params;
2410 } else {
2411 return sanitize_text_field($params);
2412 }
2413 }
2414 }
2415
2416 /**
2417 * Get Adv Filter Data Attributes
2418 * @param array|null $attr
2419 * @param array|null $filter_attributes
2420 * @return string
2421 * @since v.3.2.5
2422 */
2423 public function get_adv_data_attrs($attr, $filter_attributes=null) {
2424 // Adv Filter Integration
2425 $adv_filter_dataset = array();
2426
2427 if ($filter_attributes) {
2428 $adv_filter_dataset[] = 'data-filter-value="' . htmlspecialchars($filter_attributes['queryTaxValue']) . '"';
2429 $adv_filter_dataset[] = 'data-filter-type="' . htmlspecialchars($filter_attributes['queryTax']) . '"';
2430
2431 $is_adv = isset($filter_attributes['isAdv']) ? $filter_attributes['isAdv'] : 0;
2432 $adv_filter_dataset[] = 'data-filter-is-adv="' . $is_adv . '"';
2433
2434 if ($is_adv) {
2435 if ( isset($filter_attributes['queryAuthor'] ) ) {
2436 $adv_filter_dataset[] = "data-filter-author='" . $filter_attributes['queryAuthor'] . "'";
2437 }
2438
2439 if ( isset($filter_attributes['queryOrder'] ) ) {
2440 $adv_filter_dataset[] = "data-filter-order='" . $filter_attributes['queryOrder'] . "'";
2441 }
2442
2443 if ( isset($filter_attributes['queryOrderBy'] ) ) {
2444 $adv_filter_dataset[] = "data-filter-orderby='" . $filter_attributes['queryOrderBy'] . "'";
2445 }
2446
2447 if ( isset($filter_attributes['search'] ) ) {
2448 $adv_filter_dataset[] = 'data-filter-search="' . $filter_attributes['search'] . '"';
2449 }
2450
2451 if ( isset($filter_attributes['queryQuick'] ) && $filter_attributes['queryQuick'] ) {
2452 $adv_filter_dataset[] = 'data-filter-adv-sort="' . $filter_attributes['queryQuick'] . '"';
2453 }
2454 }
2455 }
2456
2457 if ($attr && isset($attr['advFilterEnable']) && $attr['advFilterEnable']) {
2458 $adv_filter_dataset[] = 'data-filter-is-adv="1"';
2459 $adv_filter_dataset[] = 'data-filter-type="multiTaxonomy"';
2460
2461 $data_filter_value = isset($attr['filterValue']) && $attr['filterValue'] ? $attr['filterValue'] : "[]";
2462 $adv_filter_dataset[] = 'data-filter-value="' . htmlspecialchars($data_filter_value) . '"';
2463
2464 $data_author = isset($attr['queryAuthor']) && $attr['queryAuthor'] ? $attr['queryAuthor'] : "[]";
2465 $adv_filter_dataset[] = 'data-filter-author="' . $data_author . '"';
2466
2467 $data_order = isset($attr['queryOrder']) && $attr['queryOrder'] ? $attr['queryOrder'] : "DESC";
2468 $adv_filter_dataset[] = 'data-filter-order="' . $data_order . '"';
2469
2470 $data_orderby = isset($attr['queryOrderBy']) && $attr['queryOrderBy'] ? $attr['queryOrderBy'] : "date";
2471 $adv_filter_dataset[] = 'data-filter-orderby="' . $data_orderby . '"';
2472
2473 $adv_filter_dataset[] = 'data-filter-search="' . (isset($attr['querySearch']) ? $attr['querySearch'] : '') . '"';
2474
2475 $adv_filter_dataset[] = 'data-filter-adv-sort="' . (isset($attr['queryQuick']) ? $attr['queryQuick'] : '') . '"';
2476 }
2477
2478 $adv_filter_dataset = implode(' ', $adv_filter_dataset);
2479 return $adv_filter_dataset;
2480 }
2481
2482 /**
2483 * Custom Text kses
2484 * @param $params
2485 * @return array|bool|mixed|string
2486 * @since v.4.0.2
2487 */
2488 public function ultp_allowed_html_tags($extras=[]) {
2489 $allowed = array(
2490 'a' => array(
2491 'href' => true,
2492 'title' => true,
2493 ),
2494 'abbr' => array(
2495 'title' => true,
2496 ),
2497 'b' => array(),
2498 'br' => array(),
2499 'blockquote' => array(
2500 'cite' => true,
2501 ),
2502 'em' => array(),
2503 'i' => array(),
2504 'q' => array(
2505 'cite' => true,
2506 ),
2507 'strong' => array(
2508 'class' => true,
2509 'style' => true,
2510 ),
2511 'mark' => array(
2512 'class' => true,
2513 'style' => true,
2514 ),
2515 );
2516
2517 return array_merge($allowed, $extras);
2518 }
2519
2520 /**
2521 * Allowed Block Tags
2522 * @return array
2523 * @since v.4.0.2
2524 */
2525 public function ultp_allowed_block_tags($search='') {
2526 $array_lists = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'span', 'p', 'div', 'section', 'article' ];
2527 return $search ? in_array($search, $array_lists) : $array_lists ;
2528 }
2529
2530 /**
2531 * Formats datasets for html
2532 * @since v.4.0.2
2533 *
2534 * @param array $datasets
2535 * @return string
2536 */
2537 public function get_formatted_datasets(&$datasets) {
2538 $res = '';
2539 foreach($datasets as $key => $value) {
2540 $res .= ' data-' . $key . '="' . $value . '" ';
2541 }
2542 return $res;
2543 }
2544
2545 /**
2546 * Sanitizes a attributes after running necessary checks
2547 * @since v.4.1.0
2548 *
2549 * @param array $datasets
2550 * @return string
2551 */
2552 public function sanitize_attr(&$attr, $key, $sanitize_callback = null, $def_value = '') {
2553 return isset($attr[$key]) && $attr[$key] ?
2554 (
2555 $sanitize_callback ?
2556 $sanitize_callback($attr[$key]) :
2557 $attr[$key]
2558 )
2559 : $def_value;
2560 }
2561
2562 /**
2563 * Checks if dynamic content is active
2564 * @since v.4.1.1
2565 *
2566 * @return boolean
2567 */
2568 public function is_dc_active(&$attr) {
2569 if ( class_exists('\ULTP\DCService') ) {
2570 return \ULTP\DCService::is_dc_active($attr);
2571 }
2572 return false;
2573 }
2574
2575
2576 /**
2577 * Checks all the taxonomy of a post type for a given slug. Returns the taxonomy
2578 * if it exists.
2579 * @since v.4.1.16
2580 * @param string $post_type
2581 * @param string $slug
2582 *
2583 * @return string|null
2584 */
2585 public function get_taxonomy_by_term_slug($post_type, $slug) {
2586 $taxonomies = get_object_taxonomies( $post_type );
2587 foreach ( $taxonomies as $taxonomy ) {
2588 $res = get_term_by( 'slug', $slug, $taxonomy );
2589
2590 if ( ! empty( $res ) ) {
2591 return $taxonomy;
2592 }
2593 }
2594
2595 return null;
2596 }
2597 }
2598