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

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