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

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