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