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

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