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

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