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

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

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