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

2,570 lines 105.5 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 return strtotime($date) > strtotime(get_option('edd_ultp_license_expire'));
1579 }
1580 return false;
1581 }
1582
1583 /**
1584 * Get SEO Meta
1585 *
1586 * @since v.2.4.3
1587 * @param NUMBER | Post ID
1588 * @return STRING | SEO Meta Description or Excerpt
1589 */
1590 public function get_excerpt($post_id = 0, $showSeoMeta = 0, $showFullExcerpt = 0, $excerptLimit = 55) {
1591 $html = '';
1592 if ($showSeoMeta) {
1593 $str = '';
1594 if ( function_exists('ultimate_post_pro') ) {
1595 if ( ultimate_post()->get_setting('ultp_yoast') == 'true' ) {
1596 $str = method_exists( ultimate_post_pro(), 'get_yoast_meta' ) ? ultimate_post_pro()->get_yoast_meta($post_id) : '';
1597 } else if ( ultimate_post()->get_setting('ultp_rankmath') == 'true' ) {
1598 $str = method_exists( ultimate_post_pro(), 'get_rankmath_meta' ) ? ultimate_post_pro()->get_rankmath_meta($post_id) : '';
1599 } else if ( ultimate_post()->get_setting('ultp_aioseo') == 'true' ) {
1600 $str = method_exists( ultimate_post_pro(), 'get_aioseo_meta' ) ? ultimate_post_pro()->get_aioseo_meta($post_id) : '';
1601 } else if ( ultimate_post()->get_setting('ultp_seopress') == 'true' ) {
1602 $str = method_exists( ultimate_post_pro(), 'get_seopress_meta' ) ? ultimate_post_pro()->get_seopress_meta($post_id) : '';
1603 } else if ( ultimate_post()->get_setting('ultp_squirrly') == 'true' ) {
1604 $str = method_exists( ultimate_post_pro(), 'get_squirrly_meta' ) ? ultimate_post_pro()->get_squirrly_meta($post_id) : '';
1605 }
1606 }
1607 $html = $str ? $str : ultimate_post()->excerpt($post_id, $excerptLimit);
1608 } else {
1609 if ($showFullExcerpt == 0 ) {
1610 $html = ultimate_post()->excerpt($post_id, $excerptLimit);
1611 } else {
1612 $html = get_the_excerpt();
1613 }
1614 }
1615 return $html;
1616 }
1617
1618 public function get_embeded_video($url, $autoPlay, $loop, $mute, $playback, $preload, $poster, $inline, $size) {
1619 $vidAutoPlay = $vidloop = $vidloop = $vidmute = $vidplayback = $vidPoster = $vidInline = "";
1620
1621 if($autoPlay){
1622 $vidAutoPlay = "autoplay";
1623 }
1624 if($poster){
1625 $vidPoster = 'poster="'.$poster["url"].'"';
1626 }
1627 if($loop){
1628 $vidloop = "loop";
1629 }
1630 if($mute){
1631 $vidmute = "muted";
1632 }
1633 if($playback){
1634 $vidplayback = "controls";
1635 }
1636 if($inline){
1637 $vidInline = "playsinline";
1638 }
1639 if (!empty($url)) {
1640 $embeded = wp_oembed_get($url, $size);
1641 if ($embeded == false) {
1642 $format = '';
1643 $url = strtolower($url);
1644 if (strpos($url, '.mp4')) {
1645 $format = 'mp4';
1646 } elseif (strpos($url, '.ogg')) {
1647 $format = 'ogg';
1648 } elseif (strpos($url, '.webm')) {
1649 $format = 'WebM';
1650 }
1651 $embeded = '<video
1652 '.$vidloop.'
1653 '.$vidmute.'
1654 '.$vidplayback.'
1655 preload="'.$preload.'"
1656 '.$vidAutoPlay.'
1657 '.$vidPoster.'
1658 '.$vidInline.'
1659 class="ultp-video-html"
1660 ><source src="' . $url . '" type="video/' . $format . '">' . __('Your browser does not support the video tag.', 'ultimate-post') . '</video>';
1661 return '<div class="ultp-video-wrapper">'.$embeded.'</div>';
1662 }
1663 return '<div class="ultp-video-wrapper ultp-embaded-video">'.$embeded.'</div>';
1664 } else {
1665 return false;
1666 }
1667 }
1668
1669 /**
1670 * Get Public taxonomy Lists
1671 *
1672 * @since v.2.7.0
1673 * @param NULL
1674 * @return ARRAY | Taxonomy Lists as array
1675 */
1676 public function get_taxonomy_list() {
1677 $taxonomy = get_taxonomies(array('public' => true));
1678 return empty($taxonomy) ? [] : array_keys($taxonomy);
1679 }
1680
1681 /**
1682 * Content Print
1683 *
1684 * @since v.2.7.0
1685 * @param NUMBER | Post ID
1686 * @return STRING | Content of the Post
1687 */
1688 public function get_post_content($post_id, $builder_type = '') {
1689 $content_post = get_post($post_id);
1690 $content = $content_post->post_content;
1691 if($builder_type == 'divi' || $builder_type == 'elementor') {
1692 $content = apply_filters('the_content', $content);
1693 } else {
1694 global $wp_embed;
1695 $content = $wp_embed->autoembed( $content );
1696 $content = do_blocks($content);
1697 $content = do_shortcode($content);
1698 }
1699 $content = str_replace(']]>', ']]&gt;', $content);
1700 $content = preg_replace('%<p>&nbsp;\s*</p>%', '', $content);
1701 $content = preg_replace('/^(?:<br\s*\/?>\s*)+/', '', $content);
1702 echo $content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1703 }
1704
1705 /**
1706 * String Part finder inside array
1707 *
1708 * @since v.2.7.0 updated 4.1.12
1709 * @return ARRAY | String Part
1710 */
1711 public function in_array_part($part, $data, $toR = '') {
1712 $res = array();
1713 foreach( $data as $key => $val ) {
1714 if ( strpos( $val, $part ) !== false ) {
1715 if ( $toR == 'bool' ) {
1716 return true;
1717 } else if ( $toR == 'value' ) {
1718 return $val;
1719 }
1720 $res[$key] = $val;
1721 }
1722 }
1723 if ( $toR == 'bool' ) {
1724 return false;
1725 } else if ( $toR == 'value' ) {
1726 return '';
1727 }
1728 return $res;
1729 }
1730
1731 /**
1732 * Builder Conditions
1733 *
1734 * @since v.2.7.0 updated 4.1.12
1735 * @param STRING | Type of Return
1736 * @return MIXED || ID or Path
1737 */
1738 public function builder_check_conditions( $type = 'return', $cus_condition = '' ) {
1739 $page_id = '';
1740 $conditions = $cus_condition ? $cus_condition : get_option('ultp_builder_conditions', array());
1741
1742 if ( $type == 'header' || $type == 'footer' ) {
1743 if ( !empty($conditions[$type]) ) {
1744 foreach( $conditions[$type] as $key => $val) {
1745 if ( 'publish' == get_post_status($key) && !empty($val) ) {
1746 if ( in_array('include/'.$type.'/entire_site', $val) ) {
1747 $page_id = $key;
1748 } else if ( in_array('exclude/'.$type.'/entire_site', $val) ) {
1749 $page_id = '';
1750 }
1751
1752 $c_page = ( is_archive() || is_search() ) ? 'archive' : 'singular';
1753 $hf_archive = $this->in_array_part($type.'/'.$c_page, $val, '');
1754 if ( !empty($hf_archive) ) {
1755 foreach($hf_archive as $k => $v) {
1756 if ( strpos($v, 'include/'.$type.'/'.$c_page) !== false ) {
1757 $temp = $this->builder_check_conditions('return_h', [$c_page => [$key => [str_replace($type."/", "", $v)]]]);
1758 $page_id = $temp ? $temp : $page_id;
1759 } else if (strpos($v, 'exclude/'.$type.'/'.$c_page) !== false) {
1760 $temp = $this->builder_check_conditions('return_f', [$c_page => [$key => [str_replace("exclude/".$type, "include", $v)]]]);
1761 $page_id = $temp ? '' : $page_id;
1762 }
1763 }
1764 }
1765 }
1766 }
1767 }
1768 } else {
1769 // 404 page
1770 if ( !empty($conditions['404']) && is_404() ) {
1771 foreach( $conditions['404'] as $key => $val ) {
1772 if ( 'publish' == get_post_status($key) ) {
1773 $page_id = $key;
1774 }
1775 }
1776 }
1777 // Singular or Front Page
1778 else if (
1779 (
1780 !empty($conditions['singular']) ||
1781 !empty($conditions['front_page'])
1782 ) &&
1783 (
1784 is_singular() ||
1785 is_front_page() ||
1786 is_home()
1787 )
1788 ) {
1789 $obj = get_queried_object();
1790 $queried_is_obj = is_object($obj);
1791 // front page only
1792 if (
1793 ( is_front_page() && is_home() ) ||
1794 ( is_home() && !$queried_is_obj ) ||
1795 ( is_singular() && is_front_page() && $queried_is_obj )
1796 ) {
1797 $f_conditions = [];
1798 if ( !empty($conditions['front_page']) ) {
1799 $f_conditions = $conditions['front_page'];
1800 } else if ( !empty($conditions['singular']) ) {
1801 $f_conditions = $conditions['singular'];
1802 }
1803 if ( !empty($f_conditions) ) {
1804 foreach( $f_conditions as $key => $val ) {
1805 if (
1806 ( is_array($val) && in_array('include/singular/front_page', $val) ) ||
1807 ( is_array($val) && in_array('include/front_page', $val) ) ||
1808 'include/front_page' == $val
1809 ) {
1810 if ( 'publish' == get_post_status($key) ) {
1811 $page_id = $key;
1812 }
1813 }
1814 }
1815 }
1816 }
1817 // Singular page
1818 else if ( !empty($conditions['singular']) ) {
1819 foreach( $conditions['singular'] as $key => $val ) {
1820 if ( 'publish' == get_post_status($key) ) {
1821 // All Post Type -----Prority 1
1822 if ( $queried_is_obj ) {
1823 if ( in_array('include/singular/'.$obj->post_type, $val) ) {
1824 $page_id = $key;
1825 } else if ( in_array('exclude/singular/'.$obj->post_type, $val) ) {
1826 $page_id = '';
1827 }
1828 }
1829
1830 $singular_in_tax = $this->in_array_part("/singular/in_", $val, '');
1831 if ( !empty($singular_in_tax) ) {
1832 $tax_list = $this->get_taxonomy_list();
1833 foreach( $tax_list as $tax ) {
1834 if ( in_array('include/singular/in_'.$tax.'_children', $singular_in_tax) ) {
1835 $page_id = $key;
1836 } else if ( in_array('exclude/singular/in_'.$tax.'_children', $singular_in_tax) ) {
1837 $page_id = '';
1838 }
1839
1840 if ( $queried_is_obj ) {
1841 $singular_in_tax_children = $this->in_array_part('/singular/in_'.$tax.'_children/', $singular_in_tax, '');
1842 foreach( $singular_in_tax_children as $v ) {
1843 $data = explode("/", $v);
1844 if ( isset($data[3]) && $data[3] ) {
1845 $childs = get_term_children( $data[3], $tax );
1846 if ( !empty($childs) && has_term($childs, $tax) ) {
1847 $page_id = $data[0] == 'exclude' ? '' : $key;
1848 }
1849 }
1850 }
1851 }
1852
1853 if ( in_array('include/singular/in_'.$tax, $singular_in_tax) ) {
1854 if ( $tax == "post_tag" && $queried_is_obj) {
1855 $cat = get_the_terms($obj->ID, "post_tag");
1856 if ( !empty( $cat ) ) {
1857 $page_id = $key;
1858 }
1859 } else {
1860 $page_id = $key;
1861 }
1862 } else if ( in_array('exclude/singular/in_'.$tax, $singular_in_tax) ) {
1863 $page_id = '';
1864 }
1865
1866 if ( $queried_is_obj ) {
1867 $singular_in_tax_only = $this->in_array_part('/singular/in_'.$tax.'/', $singular_in_tax, '');
1868 foreach( $singular_in_tax_only as $v ) {
1869 $data = explode("/", $v);
1870 if ( isset($data[3]) && $data[3] ) {
1871 if ( is_object_in_term($obj->ID , $tax, $data[3] ) ) {
1872 $page_id = $data[0] == 'exclude' ? '' : $key;
1873 }
1874 }
1875 }
1876 }
1877 }
1878 }
1879
1880 // Posts by author -----Prority 9
1881 if ( in_array('include/singular/post_by_author', $val) ) {
1882 $page_id = $key;
1883 } else if ( in_array('exclude/singular/post_by_author', $val) ) {
1884 $page_id = '';
1885 }
1886 if ( $queried_is_obj ) {
1887 if ( in_array('include/singular/post_by_author/'.$obj->post_author, $val) ) {
1888 $page_id = $key;
1889 } else if ( in_array('exclude/singular/post_by_author/'.$obj->post_author, $val) ) {
1890 $page_id = '';
1891 }
1892 // Post Type with specific id -----Prority 10
1893 if ( in_array('include/singular/'.$obj->post_type.'/'.$obj->ID, $val) ) {
1894 $page_id = $key;
1895 } else if ( in_array('exclude/singular/'.$obj->post_type.'/'.$obj->ID, $val) ) {
1896 $page_id = '';
1897 }
1898 }
1899 }
1900 }
1901 }
1902 }
1903
1904 // Archive and Search Page
1905 else if ( !empty($conditions['archive']) ) {
1906 // Search Page
1907 if ( is_search() ) {
1908 foreach( $conditions['archive'] as $key => $val ) {
1909 if ( 'publish' == get_post_status($key) ) {
1910 if ( in_array('include/archive/search', $val) ) {
1911 $page_id = $key;
1912 } else if ( in_array('exclude/archive/search', $val) ) {
1913 $page_id = '';
1914 }
1915 }
1916 }
1917 }
1918 // Archive Page
1919 else if ( is_archive() ) {
1920 $is_cat = is_category();
1921 $is_tag = is_tag();
1922 $is_tax = is_tax();
1923 $is_date = is_date();
1924 $is_author = is_author();
1925 $taxonomy = ( $is_cat || $is_tag || $is_tax ) ? get_queried_object() : (object)[];
1926
1927 foreach( $conditions['archive'] as $key => $val ) {
1928 if ( 'publish' == get_post_status($key) ) {
1929 // This section is for all archive page
1930 if ( in_array('include/archive', $val) ) {
1931 $page_id = $key;
1932 } else if ( in_array('exclude/archive', $val) ) {
1933 $page_id = '';
1934 }
1935 // For Category
1936 if ( $is_cat ) {
1937 // all category
1938 if ( in_array('include/archive/category', $val) ) {
1939 $page_id = $key;
1940 } else if ( in_array('exclude/archive/category', $val) ) {
1941 $page_id = '';
1942 }
1943 // specific category
1944 if ( in_array('include/archive/category/'.$taxonomy->term_id, $val) ) {
1945 $page_id = $key;
1946 } else if ( in_array('exclude/archive/category/'.$taxonomy->term_id, $val) ) {
1947 $page_id = '';
1948 }
1949
1950 // any child of category
1951 if ( in_array('include/archive/any_child_of_category', $val) ) {
1952 $page_id = $key;
1953 } else if ( in_array('exclude/archive/any_child_of_category', $val) ) {
1954 $page_id = '';
1955 }
1956
1957 $any_child_of_cat = $this->in_array_part("archive/any_child_of_category/", $val, '');
1958 if ( !empty($any_child_of_cat) ) {
1959 foreach( $any_child_of_cat as $v ) {
1960 $data = explode("/", $v);
1961 if ( isset($data[3]) && $data[3] ) {
1962 if ( term_is_ancestor_of($data[3], $taxonomy->term_id, 'category') ) {
1963 $page_id = $data[0] == 'exclude' ? '' : $key;
1964 }
1965 }
1966 }
1967 }
1968
1969 // all child of category
1970 if ( in_array('include/archive/child_of_category', $val) ) {
1971 $page_id = $key;
1972 } else if ( in_array('exclude/archive/child_of_category', $val) ) {
1973 $page_id = '';
1974 }
1975 // specific child of category
1976 if ( in_array('include/archive/child_of_category/'.$taxonomy->parent, $val) ) {
1977 $page_id = $key;
1978 } else if ( in_array('exclude/archive/child_of_category/'.$taxonomy->parent, $val) ) {
1979 $page_id = '';
1980 }
1981 }
1982 // For Tag
1983 else if ( $is_tag ) {
1984 if ( in_array('include/archive/post_tag', $val) ) {
1985 $page_id = $key;
1986 } else if ( in_array('exclude/archive/post_tag', $val) ) {
1987 $page_id = '';
1988 }
1989 if ( in_array('include/archive/post_tag/'.$taxonomy->term_id, $val) ) {
1990 $page_id = $key;
1991 } else if ( in_array('exclude/archive/post_tag/'.$taxonomy->term_id, $val) ) {
1992 $page_id = '';
1993 }
1994 }
1995 // Other taxonomy
1996 else if ( $is_tax ) {
1997 if ( in_array('include/archive/'.$taxonomy->taxonomy, $val) ) {
1998 $page_id = $key;
1999 } else if ( in_array('exclude/archive/'.$taxonomy->taxonomy, $val) ) {
2000 $page_id = '';
2001 }
2002
2003 if ( in_array('include/archive/'.$taxonomy->taxonomy.'/'.$taxonomy->term_id, $val) ) {
2004 $page_id = $key;
2005 } else if ( in_array('exclude/archive/'.$taxonomy->taxonomy.'/'.$taxonomy->term_id, $val) ) {
2006 $page_id = '';
2007 }
2008
2009 if ( in_array('include/archive/any_child_of_'.$taxonomy->taxonomy, $val) ) {
2010 $page_id = $key;
2011 } else if ( in_array('exclude/archive/any_child_of_'.$taxonomy->taxonomy, $val) ) {
2012 $page_id = '';
2013 }
2014
2015 $any_child_of_tax = $this->in_array_part('archive/any_child_of_'.$taxonomy->taxonomy.'/', $val, '');
2016 if ( !empty($any_child_of_tax) ) {
2017 foreach( $any_child_of_tax as $v ) {
2018 $data = explode("/", $v);
2019 if ( isset($data[3]) && $data[3] ) {
2020 if ( term_is_ancestor_of($data[3], $taxonomy->term_id, $taxonomy->taxonomy) ) {
2021 $page_id = $data[0] == 'exclude' ? '' : $key;
2022 }
2023 }
2024 }
2025 }
2026
2027 if ( in_array('include/archive/child_of_'.$taxonomy->taxonomy, $val) ) {
2028 $page_id = $key;
2029 } else if ( in_array('exclude/archive/child_of_'.$taxonomy->taxonomy, $val) ) {
2030 $page_id = '';
2031 }
2032
2033 if ( in_array('include/archive/child_of_'.$taxonomy->taxonomy.'/'.$taxonomy->parent, $val) ) {
2034 $page_id = $key;
2035 } else if ( in_array('exclude/archive/child_of_'.$taxonomy->taxonomy.'/'.$taxonomy->parent, $val) ) {
2036 $page_id = '';
2037 }
2038
2039 }
2040 // For Date
2041 else if ( $is_date ) {
2042 if ( in_array('include/archive/date', $val) ) {
2043 $page_id = $key;
2044 } else if ( in_array('exclude/archive/date', $val) ) {
2045 $page_id = '';
2046 }
2047 }
2048 // For Author
2049 else if ( $is_author ) {
2050 if ( in_array('include/archive/author', $val) ) {
2051 $page_id = $key;
2052 } else if ( in_array('exclude/archive/author', $val) ) {
2053 $page_id = '';
2054 }
2055 $author_id = get_the_author_meta('ID');
2056 if ( in_array('include/archive/author/'.$author_id, $val) ) {
2057 $page_id = $key;
2058 } else if ( in_array('exclude/archive/author/'.$author_id, $val) ) {
2059 $page_id = '';
2060 }
2061 }
2062 }
2063 }
2064 }
2065 }
2066 }
2067 return $page_id;
2068 }
2069
2070 /**
2071 * Get Date Default Format
2072 *
2073 * @since v.2.7.2
2074 * @return ARRAY | Default Data
2075 */
2076 public function get_format($format) {
2077 if ($format == 'default_date') {
2078 return get_option('date_format');
2079 } else if ($format == 'default_date_time') {
2080 return get_option('date_format').' '.get_option('time_format');
2081 } else {
2082 return $format;
2083 }
2084 }
2085
2086 /**
2087 * Common Frontend and Backend CSS and JS Scripts
2088 *
2089 * @since v.1.0.0
2090 * @return NULL
2091 */
2092 public function register_scripts_common() {
2093 if ( !( isset($GLOBALS['wp_scripts']) && isset($GLOBALS['wp_scripts']->registered) && isset($GLOBALS['wp_scripts']->registered['ultp-script']) ) ) {
2094 wp_enqueue_style('ultp-style', ULTP_URL.'assets/css/style.min.css', array(), ULTP_VER );
2095 wp_enqueue_script('ultp-script', ULTP_URL.'assets/js/ultp.min.js', array('jquery', 'wp-api-fetch'), ULTP_VER, true);
2096 wp_localize_script('ultp-script', 'ultp_data_frontend', array(
2097 'url' => ULTP_URL,
2098 'active' => ultimate_post()->is_lc_active(),
2099 'ultpSavedDLMode' => ultimate_post()->get_dl_mode(),
2100 'ajax' => admin_url('admin-ajax.php'),
2101 'security' => wp_create_nonce('ultp-nonce'),
2102 'home_url' => home_url(),
2103 'dark_logo' => get_option('ultp_site_dark_logo', false)
2104 ));
2105 }
2106 }
2107 /**
2108 * Get Dark Light Mode
2109 *
2110 * @since 4.0.0
2111 * @return string
2112 */
2113 public function get_dl_mode() {
2114 $data = get_option('postx_global', []);
2115 $mode = 'ultplight';
2116 if(!empty($data)) {
2117 $mode = isset($data['enableDark']) && $data['enableDark'] ? 'ultpdark' : 'ultplight';
2118 }
2119 return $mode;
2120 }
2121
2122 /**
2123 * Get Page Post Id ( Kadence element )
2124 *
2125 * @since v.2.8.9
2126 * @return NULL
2127 */
2128 public function get_page_post_id($blockId) {
2129 global $wpdb;
2130 $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
2131 // For FSE theme
2132 if ( !$post_meta ) {
2133 if ( wp_is_block_theme() ) {
2134 $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
2135 if ( isset($template->ID) ) {
2136 return $template->ID;
2137 }
2138 }
2139 }
2140 if ( $post_meta && isset($post_meta->post_id) ) {
2141 return $post_meta->post_id;
2142 }
2143 return ultimate_post()->get_ID();
2144 }
2145
2146
2147 /**
2148 * Get no Result found html
2149 *
2150 * @since v.2.9.0
2151 * @param STRING | No result found text
2152 * @return STRING | Taxonomy Lists as array
2153 */
2154 public function get_no_result_found_html($text) {
2155 return $text ? '<div class="ultp-not-found-message" role="alert">'.wp_kses($text, ultimate_post()->ultp_allowed_html_tags()).'</div>' : '';
2156 }
2157
2158 /**
2159 * Get all Saved Templates Lists
2160 *
2161 * @since v.2.9.9
2162 * @param STRING | No result found text
2163 * @return STRING | Taxonomy Lists as array
2164 */
2165 public function get_all_lists($post_type = 'post', $empty = '') {
2166 $args = array(
2167 'post_type' => $post_type,
2168 'post_status' => 'publish',
2169 'posts_per_page' => -1
2170 );
2171 $loop = new \WP_Query( $args );
2172 $data[ $empty ? $empty : '' ] = __( '- Select Template -', 'ultimate-post' );
2173 if($loop->have_posts()){
2174 foreach ( $loop->posts as $post ) {
2175 $data[$post->ID] = $post->post_title ;
2176 }
2177 }
2178 wp_reset_postdata();
2179 return $data;
2180 }
2181
2182 /**
2183 * Get ID from the Youtube URL
2184 *
2185 * @since v.3.1.7
2186 * @param STRING | No result found text
2187 * @return STRING | Taxonomy Lists as array
2188 */
2189 public function get_youtube_id($url = '') {
2190 if (strpos($url, 'youtu') !== false) {
2191 $reg = '/youtu(?:.*\/v\/|.*v\=|\.be\/)([A-Za-z0-9_\-]{11})/m';
2192 preg_match($reg, $url, $matches);
2193 if (isset($matches[1])) {
2194 return $matches[1];
2195 }
2196 }
2197 return false;
2198 }
2199
2200 /**
2201 * Get Option Value bypassing cache
2202 * Inspired By WordPress Core get_option
2203 * @since v.3.1.6
2204 * @param string $option Option Name.
2205 * @param boolean $default_value option default value.
2206 * @return mixed
2207 */
2208 public function get_option_without_cache($option, $default_value=false) {
2209 global $wpdb;
2210
2211 if ( is_scalar( $option ) ) {
2212 $option = trim( $option );
2213 }
2214
2215 if ( empty( $option ) ) {
2216 return false;
2217 }
2218
2219 $value = $default_value;
2220
2221 $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
2222
2223 if ( is_object( $row ) ) {
2224 $value = $row->option_value;
2225 } else {
2226 return apply_filters( "ultp_default_option_{$option}", $default_value, $option );
2227 }
2228
2229 return apply_filters( "ultp_option_{$option}", maybe_unserialize( $value ), $option );
2230 }
2231
2232 /**
2233 * Get Transient Value bypassing cache
2234 * Inspired By WordPress Core get_transient
2235 * @since v.3.1.6
2236 * @param string $transient Transient Name.
2237 * @return mixed
2238 */
2239 public function get_transient_without_cache($transient) {
2240 $transient_option = '_transient_' . $transient;
2241 $transient_timeout = '_transient_timeout_' . $transient;
2242 $timeout = $this->get_option_without_cache( $transient_timeout );
2243
2244 if ( false !== $timeout && $timeout < time() ) {
2245 delete_option( $transient_option );
2246 delete_option( $transient_timeout );
2247 $value = false;
2248 }
2249
2250 if ( ! isset( $value ) ) {
2251 $value = $this->get_option_without_cache( $transient_option );
2252 }
2253
2254 return apply_filters( "ultp_transient_{$transient}", $value, $transient );
2255 }
2256
2257 /**
2258 * Set transient without adding to the cache
2259 * Inspired By WordPress Core set_transient
2260 * @since v.3.1.6
2261 * @param string $transient Transient Name.
2262 * @param mixed $value Transient Value.
2263 * @param integer $expiration Time until expiration in seconds.
2264 * @return bool
2265 */
2266 public function set_transient_without_cache($transient, $value, $expiration = 0) {
2267 $expiration = (int) $expiration;
2268
2269 $transient_timeout = '_transient_timeout_' . $transient;
2270 $transient_option = '_transient_' . $transient;
2271
2272 $result = false;
2273
2274 if ( false === $this->get_option_without_cache( $transient_option ) ) {
2275 $autoload = 'yes';
2276 if ( $expiration ) {
2277 $autoload = 'no';
2278 $this->add_option_without_cache( $transient_timeout, time() + $expiration, 'no' );
2279 }
2280 $result = $this->add_option_without_cache( $transient_option, $value, $autoload );
2281 } else {
2282 /*
2283 * If expiration is requested, but the transient has no timeout option,
2284 * delete, then re-create transient rather than update.
2285 */
2286 $update = true;
2287
2288 if ( $expiration ) {
2289 if ( false === $this->get_option_without_cache( $transient_timeout ) ) {
2290 delete_option( $transient_option );
2291 $this->add_option_without_cache( $transient_timeout, time() + $expiration, 'no' );
2292 $result = $this->add_option_without_cache( $transient_option, $value, 'no' );
2293 $update = false;
2294 } else {
2295 update_option( $transient_timeout, time() + $expiration );
2296 }
2297 }
2298
2299 if ( $update ) {
2300 $result = update_option( $transient_option, $value );
2301 }
2302 }
2303
2304 return $result;
2305
2306 }
2307
2308 /**
2309 * Add option without adding to the cache
2310 * Inspired By WordPress Core set_transient
2311 * @since v.3.1.6
2312 * @param string $option option name.
2313 * @param string $value option value.
2314 * @param string $autoload whether to load wordpress startup.
2315 * @return bool
2316 */
2317 public function add_option_without_cache( $option, $value = '', $autoload = 'yes' ) {
2318 global $wpdb;
2319
2320
2321 if ( is_scalar( $option ) ) {
2322 $option = trim( $option );
2323 }
2324
2325 if ( empty( $option ) ) {
2326 return false;
2327 }
2328
2329 wp_protect_special_option( $option );
2330
2331 if ( is_object( $value ) ) {
2332 $value = clone $value;
2333 }
2334
2335 $value = sanitize_option( $option, $value );
2336
2337 /*
2338 * Make sure the option doesn't already exist.
2339 */
2340
2341 if ( apply_filters( "ultp_default_option_{$option}", false, $option, false ) !== $this->get_option_without_cache( $option ) ) {
2342 return false;
2343 }
2344
2345
2346 $serialized_value = maybe_serialize( $value );
2347 $autoload = ( 'no' === $autoload || false === $autoload ) ? 'no' : 'yes';
2348
2349
2350 $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
2351 if ( ! $result ) {
2352 return false;
2353 }
2354
2355 return true;
2356 }
2357
2358 /**
2359 * permission_check_for_restapi
2360 * @since v.3.2.4
2361 * @param $post_id string/bool
2362 * @param $cap string
2363 * @return bool
2364 */
2365 public function permission_check_for_restapi( $post_id=false, $cap='' ) {
2366 $cap = $cap ? $cap : 'edit_others_posts';
2367 $is_passed = false;
2368 if($post_id) {
2369 $post_author =(int) get_post_field('post_author',$post_id);
2370 $is_passed = (int)get_current_user_id()===$post_author;
2371 }
2372 return $is_passed || current_user_can($cap);
2373 }
2374
2375 /**
2376 * Sanitize params
2377 * @param $params
2378 * @return array|bool|mixed|string
2379 * @since v.4.0.0
2380 */
2381 public function ultp_rest_sanitize_params($params) {
2382 if ( is_array($params) ) {
2383 return array_map(array($this,'ultp_rest_sanitize_params'),$params);
2384 } else {
2385 if( is_bool($params) ) {
2386 return rest_sanitize_boolean($params);
2387 } else if( is_object($params) ) {
2388 return $params;
2389 } else {
2390 return sanitize_text_field($params);
2391 }
2392 }
2393 }
2394
2395 /**
2396 * Get Adv Filter Data Attributes
2397 * @param array|null $attr
2398 * @param array|null $filter_attributes
2399 * @return string
2400 * @since v.3.2.5
2401 */
2402 public function get_adv_data_attrs($attr, $filter_attributes=null) {
2403 // Adv Filter Integration
2404 $adv_filter_dataset = array();
2405
2406 if ($filter_attributes) {
2407 $adv_filter_dataset[] = 'data-filter-value="' . htmlspecialchars($filter_attributes['queryTaxValue']) . '"';
2408 $adv_filter_dataset[] = 'data-filter-type="' . htmlspecialchars($filter_attributes['queryTax']) . '"';
2409
2410 $is_adv = isset($filter_attributes['isAdv']) ? $filter_attributes['isAdv'] : 0;
2411 $adv_filter_dataset[] = 'data-filter-is-adv="' . $is_adv . '"';
2412
2413 if ($is_adv) {
2414 if ( isset($filter_attributes['queryAuthor'] ) ) {
2415 $adv_filter_dataset[] = "data-filter-author='" . $filter_attributes['queryAuthor'] . "'";
2416 }
2417
2418 if ( isset($filter_attributes['queryOrder'] ) ) {
2419 $adv_filter_dataset[] = "data-filter-order='" . $filter_attributes['queryOrder'] . "'";
2420 }
2421
2422 if ( isset($filter_attributes['queryOrderBy'] ) ) {
2423 $adv_filter_dataset[] = "data-filter-orderby='" . $filter_attributes['queryOrderBy'] . "'";
2424 }
2425
2426 if ( isset($filter_attributes['search'] ) ) {
2427 $adv_filter_dataset[] = 'data-filter-search="' . $filter_attributes['search'] . '"';
2428 }
2429
2430 if ( isset($filter_attributes['queryQuick'] ) && $filter_attributes['queryQuick'] ) {
2431 $adv_filter_dataset[] = 'data-filter-adv-sort="' . $filter_attributes['queryQuick'] . '"';
2432 }
2433 }
2434 }
2435
2436 if ($attr && isset($attr['advFilterEnable']) && $attr['advFilterEnable']) {
2437 $adv_filter_dataset[] = 'data-filter-is-adv="1"';
2438 $adv_filter_dataset[] = 'data-filter-type="multiTaxonomy"';
2439
2440 $data_filter_value = isset($attr['filterValue']) && $attr['filterValue'] ? $attr['filterValue'] : "[]";
2441 $adv_filter_dataset[] = 'data-filter-value="' . htmlspecialchars($data_filter_value) . '"';
2442
2443 $data_author = isset($attr['queryAuthor']) && $attr['queryAuthor'] ? $attr['queryAuthor'] : "[]";
2444 $adv_filter_dataset[] = 'data-filter-author="' . $data_author . '"';
2445
2446 $data_order = isset($attr['queryOrder']) && $attr['queryOrder'] ? $attr['queryOrder'] : "DESC";
2447 $adv_filter_dataset[] = 'data-filter-order="' . $data_order . '"';
2448
2449 $data_orderby = isset($attr['queryOrderBy']) && $attr['queryOrderBy'] ? $attr['queryOrderBy'] : "date";
2450 $adv_filter_dataset[] = 'data-filter-orderby="' . $data_orderby . '"';
2451
2452 $adv_filter_dataset[] = 'data-filter-search="' . (isset($attr['querySearch']) ? $attr['querySearch'] : '') . '"';
2453
2454 $adv_filter_dataset[] = 'data-filter-adv-sort="' . (isset($attr['queryQuick']) ? $attr['queryQuick'] : '') . '"';
2455 }
2456
2457 $adv_filter_dataset = implode(' ', $adv_filter_dataset);
2458 return $adv_filter_dataset;
2459 }
2460
2461 /**
2462 * Custom Text kses
2463 * @param $params
2464 * @return array|bool|mixed|string
2465 * @since v.4.0.2
2466 */
2467 public function ultp_allowed_html_tags($extras=[]) {
2468 $allowed = array(
2469 'a' => array(
2470 'href' => true,
2471 'title' => true,
2472 ),
2473 'abbr' => array(
2474 'title' => true,
2475 ),
2476 'b' => array(),
2477 'br' => array(),
2478 'blockquote' => array(
2479 'cite' => true,
2480 ),
2481 'em' => array(),
2482 'i' => array(),
2483 'q' => array(
2484 'cite' => true,
2485 ),
2486 'strong' => array(),
2487 );
2488
2489 return array_merge($allowed, $extras);
2490 }
2491
2492 /**
2493 * Allowed Block Tags
2494 * @return array
2495 * @since v.4.0.2
2496 */
2497 public function ultp_allowed_block_tags($search='') {
2498 $array_lists = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'span', 'p', 'div', 'section', 'article' ];
2499 return $search ? in_array($search, $array_lists) : $array_lists ;
2500 }
2501
2502 /**
2503 * Formats datasets for html
2504 * @since v.4.0.2
2505 *
2506 * @param array $datasets
2507 * @return string
2508 */
2509 public function get_formatted_datasets(&$datasets) {
2510 $res = '';
2511 foreach($datasets as $key => $value) {
2512 $res .= ' data-' . $key . '="' . $value . '" ';
2513 }
2514 return $res;
2515 }
2516
2517 /**
2518 * Sanitizes a attributes after running necessary checks
2519 * @since v.4.1.0
2520 *
2521 * @param array $datasets
2522 * @return string
2523 */
2524 public function sanitize_attr(&$attr, $key, $sanitize_callback = null, $def_value = '') {
2525 return isset($attr[$key]) && $attr[$key] ?
2526 (
2527 $sanitize_callback ?
2528 $sanitize_callback($attr[$key]) :
2529 $attr[$key]
2530 )
2531 : $def_value;
2532 }
2533
2534 /**
2535 * Checks if dynamic content is active
2536 * @since v.4.1.1
2537 *
2538 * @return boolean
2539 */
2540 public function is_dc_active(&$attr) {
2541 if ( class_exists('\ULTP\DCService') ) {
2542 return \ULTP\DCService::is_dc_active($attr);
2543 }
2544 return false;
2545 }
2546
2547
2548 /**
2549 * Checks all the taxonomy of a post type for a given slug. Returns the taxonomy
2550 * if it exists.
2551 * @since v.4.1.16
2552 * @param string $post_type
2553 * @param string $slug
2554 *
2555 * @return string|null
2556 */
2557 public function get_taxonomy_by_term_slug($post_type, $slug) {
2558 $taxonomies = get_object_taxonomies( $post_type );
2559 foreach ( $taxonomies as $taxonomy ) {
2560 $res = get_term_by( 'slug', $slug, $taxonomy );
2561
2562 if ( ! empty( $res ) ) {
2563 return $taxonomy;
2564 }
2565 }
2566
2567 return null;
2568 }
2569 }
2570