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

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