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

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