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

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

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