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

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