| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; |
| 4 |
} |
| 5 |
|
| 6 |
if ( ! function_exists( 'easyel_get_pro_clean_version' ) ) { |
| 7 |
function easyel_get_pro_clean_version() { |
| 8 |
|
| 9 |
if ( ! defined( 'EASYELEMENTS_PRO_FILE' ) ) { |
| 10 |
return null; |
| 11 |
} |
| 12 |
|
| 13 |
if ( ! function_exists( 'get_file_data' ) ) { |
| 14 |
require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 15 |
} |
| 16 |
|
| 17 |
$data = get_file_data( |
| 18 |
EASYELEMENTS_PRO_FILE, |
| 19 |
[ 'Version' => 'Version' ] |
| 20 |
); |
| 21 |
|
| 22 |
return $data['Version'] ?? null; |
| 23 |
} |
| 24 |
} |
| 25 |
|
| 26 |
if ( ! function_exists( 'easyel_enable_svg_upload' ) ) { |
| 27 |
function easyel_enable_svg_upload( $mimes ) { |
| 28 |
$mimes['svg'] = 'image/svg+xml'; |
| 29 |
$mimes['svgz'] = 'image/svg+xml'; |
| 30 |
return $mimes; |
| 31 |
} |
| 32 |
add_filter( 'upload_mimes', 'easyel_enable_svg_upload' ); |
| 33 |
} |
| 34 |
|
| 35 |
if ( ! function_exists( 'easyel_fix_svg_filetype' ) ) { |
| 36 |
function easyel_fix_svg_filetype( $data, $file, $filename, $mimes ) { |
| 37 |
$ext = pathinfo( $filename, PATHINFO_EXTENSION ); |
| 38 |
if ( strtolower( $ext ) === 'svg' || strtolower( $ext ) === 'svgz' ) { |
| 39 |
$data['ext'] = 'svg'; |
| 40 |
$data['type'] = 'image/svg+xml'; |
| 41 |
} |
| 42 |
return $data; |
| 43 |
} |
| 44 |
add_filter( 'wp_check_filetype_and_ext', 'easyel_fix_svg_filetype', 10, 4 ); |
| 45 |
} |
| 46 |
|
| 47 |
if ( ! function_exists( 'easyel_handle_sideload_svg' ) ) { |
| 48 |
function easyel_handle_sideload_svg( $file ) { |
| 49 |
$ext = pathinfo( $file['name'], PATHINFO_EXTENSION ); |
| 50 |
if ( strtolower( $ext ) === 'svg' || strtolower( $ext ) === 'svgz' ) { |
| 51 |
$file['type'] = 'image/svg+xml'; |
| 52 |
} |
| 53 |
return $file; |
| 54 |
} |
| 55 |
|
| 56 |
add_filter( 'wp_handle_sideload_prefilter', 'easyel_handle_sideload_svg' ); |
| 57 |
} |
| 58 |
|
| 59 |
if ( ! function_exists( 'easyel_get_cf7_forms' ) ) { |
| 60 |
/** |
| 61 |
* Get a list of all CF7 forms |
| 62 |
* |
| 63 |
* @return array |
| 64 |
*/ |
| 65 |
function easyel_get_cf7_forms() { |
| 66 |
$forms = get_posts( [ |
| 67 |
'post_type' => 'wpcf7_contact_form', |
| 68 |
'post_status' => 'publish', |
| 69 |
'posts_per_page' => -1, |
| 70 |
'orderby' => 'title', |
| 71 |
'order' => 'ASC', |
| 72 |
] ); |
| 73 |
|
| 74 |
if ( ! empty( $forms ) ) { |
| 75 |
return wp_list_pluck( $forms, 'post_title', 'ID' ); |
| 76 |
} |
| 77 |
return []; |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
// Domain Search Code |
| 83 |
add_action('template_redirect', function(){ |
| 84 |
// phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 85 |
if (isset($_POST['easyel_domain_redirect'])) { |
| 86 |
// phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 87 |
$domain = isset($_POST['domain']) ? sanitize_text_field(wp_unslash($_POST['domain'])) : ''; |
| 88 |
// phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 89 |
$base_url = isset($_POST['base_url']) ? esc_url_raw( wp_unslash($_POST['base_url'] ) ) : ''; |
| 90 |
|
| 91 |
if ( !empty($domain) && !empty($base_url) && filter_var($base_url, FILTER_VALIDATE_URL) ) { |
| 92 |
$redirect_url = esc_url_raw($base_url . urlencode($domain)); |
| 93 |
wp_redirect($redirect_url); |
| 94 |
exit; |
| 95 |
} |
| 96 |
} |
| 97 |
}); |
| 98 |
|
| 99 |
function easyel_get_extension_fields() { |
| 100 |
$fields = [ |
| 101 |
'enable_cursor' => [ |
| 102 |
'label' => __('Magic Cursor', 'easy-elements'), |
| 103 |
'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/magic-cursor.svg', |
| 104 |
'is_pro' => true, |
| 105 |
'group' => 'GSAP Extensions', |
| 106 |
'demo_url' => 'https://wpeasyelements.com/', |
| 107 |
], |
| 108 |
'enable_sticky_elements' => [ |
| 109 |
'label' => __('Sticky Elements', 'easy-elements'), |
| 110 |
'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/sticky-elements.svg', |
| 111 |
'is_pro' => true, |
| 112 |
'group' => 'General Extensions', |
| 113 |
'demo_url' => 'https://wpeasyelements.com/', |
| 114 |
], |
| 115 |
'enable_cursor_hover_effect' => [ |
| 116 |
'label' => __('Cursor Hover Effect', 'easy-elements'), |
| 117 |
'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/cursor-hover-effect.svg', |
| 118 |
'is_pro' => true, |
| 119 |
'group' => 'GSAP Extensions', |
| 120 |
'demo_url' => 'https://wpeasyelements.com/', |
| 121 |
], |
| 122 |
'enable_cursor_move_effect' => [ |
| 123 |
'label' => __('Cursor Move Effect', 'easy-elements'), |
| 124 |
'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/cursor-move-effect.svg', |
| 125 |
'is_pro' => true, |
| 126 |
'group' => 'GSAP Extensions', |
| 127 |
'demo_url' => 'https://wpeasyelements.com/', |
| 128 |
], |
| 129 |
'enable_scroll_trigger' => [ |
| 130 |
'label' => __('ScrollTrigger', 'easy-elements'), |
| 131 |
'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/scrolltrigger.svg', |
| 132 |
'is_pro' => true, |
| 133 |
'group' => 'GSAP Extensions', |
| 134 |
'demo_url' => 'https://wpeasyelements.com/', |
| 135 |
], |
| 136 |
'enable_parallax_image' => [ |
| 137 |
'label' => __('Background Parallax', 'easy-elements'), |
| 138 |
'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/background-parallax.svg', |
| 139 |
'is_pro' => true, |
| 140 |
'group' => 'GSAP Extensions', |
| 141 |
'demo_url' => 'https://wpeasyelements.com/', |
| 142 |
], |
| 143 |
'enable_drawsvg' => [ |
| 144 |
'label' => __('DrawSVG', 'easy-elements'), |
| 145 |
'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/drawsvg.svg', |
| 146 |
'is_pro' => true, |
| 147 |
'upcoming' => true, |
| 148 |
'group' => 'GSAP Extensions', |
| 149 |
'demo_url' => 'https://wpeasyelements.com/', |
| 150 |
], |
| 151 |
'enable_image_3d_effect' => [ |
| 152 |
'label' => __('Image 3D Effect', 'easy-elements'), |
| 153 |
'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/image-3d-effect.svg', |
| 154 |
'is_pro' => true, |
| 155 |
'upcoming' => true, |
| 156 |
'group' => 'GSAP Extensions', |
| 157 |
'demo_url' => 'https://wpeasyelements.com/', |
| 158 |
], |
| 159 |
|
| 160 |
'enable_smooth_scroller' => [ |
| 161 |
'label' => __('Scroll Smoother', 'easy-elements'), |
| 162 |
'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/image-3d-effect.svg', |
| 163 |
'is_pro' => true, |
| 164 |
'setting' => true, |
| 165 |
'group' => 'GSAP Extensions', |
| 166 |
'demo_url' => 'https://wpeasyelements.com/extensions/scroll-smoother/', |
| 167 |
'docx_url' => 'https://wpeasyelements.com/extensions/docs/scroll-smoother/', |
| 168 |
], |
| 169 |
'enable_bounce_animation' => [ |
| 170 |
'label' => __('Bounce Animation', 'easy-elements'), |
| 171 |
'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/image-3d-effect.svg', |
| 172 |
'is_pro' => true, |
| 173 |
'setting' => true, |
| 174 |
'group' => 'GSAP Extensions', |
| 175 |
'demo_url' => 'https://wpeasyelements.com/extensions/bounce-animation/', |
| 176 |
'docx_url' => 'https://wpeasyelements.com/extensions/docs/bounce-animation/', |
| 177 |
], |
| 178 |
|
| 179 |
'enable_wrapper_link' => [ |
| 180 |
'label' => __('Wrapper Link', 'easy-elements'), |
| 181 |
'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/wrapper-link.svg', |
| 182 |
'is_pro' => false, |
| 183 |
'group' => 'General Extensions', |
| 184 |
'demo_url' => 'https://wpeasyelements.com/extensions/wrapper-link/', |
| 185 |
'docx_url' => 'https://wpeasyelements.com/extensions/wrapper-link/', |
| 186 |
], |
| 187 |
|
| 188 |
'enable_post_duplicator' => [ |
| 189 |
'label' => __('Duplicator', 'easy-elements'), |
| 190 |
'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/duplicator.svg', |
| 191 |
'is_pro' => false, |
| 192 |
'group' => 'General Extensions', |
| 193 |
'demo_url' => 'https://wpeasyelements.com/docs/post-page-duplicate/', |
| 194 |
'docx_url' => 'https://wpeasyelements.com/docs/post-page-duplicate/', |
| 195 |
], |
| 196 |
|
| 197 |
'enable_postpage_export' => [ |
| 198 |
'label' => __('Easy Export', 'easy-elements'), |
| 199 |
'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/duplicator.svg', |
| 200 |
'is_pro' => false, |
| 201 |
'group' => 'General Extensions', |
| 202 |
'demo_url' => 'https://wpeasyelements.com/extensions/docs/easy-export/', |
| 203 |
'docx_url' => 'https://wpeasyelements.com/extensions/docs/easy-export/', |
| 204 |
], |
| 205 |
|
| 206 |
'enable_visibility_control' => [ |
| 207 |
'label' => __('Visibility Control', 'easy-elements'), |
| 208 |
'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/visibility-control.svg', |
| 209 |
'is_pro' => true, |
| 210 |
'group' => 'General Extensions', |
| 211 |
'demo_url' => 'https://wpeasyelements.com/', |
| 212 |
], |
| 213 |
'enable_dynamic_content' => [ |
| 214 |
'label' => __('Dynamic Content', 'easy-elements'), |
| 215 |
'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/dynamic-content.svg', |
| 216 |
'is_pro' => true, |
| 217 |
'group' => 'General Extensions', |
| 218 |
'demo_url' => 'https://wpeasyelements.com/', |
| 219 |
], |
| 220 |
'enable_live_copy_paste' => [ |
| 221 |
'label' => __('Live Copy Paste', 'easy-elements'), |
| 222 |
'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/live-copy.svg', |
| 223 |
'is_pro' => true, |
| 224 |
'group' => 'General Extensions', |
| 225 |
'demo_url' => 'https://wpeasyelements.com/', |
| 226 |
], |
| 227 |
'enable_easy_custom_css' => [ |
| 228 |
'label' => __('Custom CSS', 'easy-elements'), |
| 229 |
'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/easy-custom-css.svg', |
| 230 |
'is_pro' => true, |
| 231 |
'group' => 'General Extensions', |
| 232 |
'demo_url' => 'https://wpeasyelements.com/', |
| 233 |
], |
| 234 |
'enable_global_badge' => [ |
| 235 |
'label' => __('Global Badge', 'easy-elements'), |
| 236 |
'icon' => EASYELEMENTS_DIR_URL . 'includes/Admin/icons/extension/live-copy.svg', |
| 237 |
'is_pro' => true, |
| 238 |
'group' => 'General Extensions', |
| 239 |
'demo_url' => 'https://wpeasyelements.com/extensions/global-badge/', |
| 240 |
'docx_url' => 'https://wpeasyelements.com/extensions/docs/lobal-badge/', |
| 241 |
], |
| 242 |
|
| 243 |
]; |
| 244 |
|
| 245 |
return apply_filters('easyel_extension_fields', $fields); |
| 246 |
} |
| 247 |
|
| 248 |
function sanitize_conditions_array( $conditions ) { |
| 249 |
if ( ! is_array( $conditions ) ) { |
| 250 |
return []; |
| 251 |
} |
| 252 |
|
| 253 |
$sanitized = []; |
| 254 |
foreach ( $conditions as $cond ) { |
| 255 |
if ( ! is_array( $cond ) ) continue; |
| 256 |
|
| 257 |
$sanitized[] = [ |
| 258 |
'include' => isset($cond['include']) ? sanitize_text_field($cond['include']) : 'include', |
| 259 |
'main' => isset($cond['main']) ? sanitize_text_field($cond['main']) : '', |
| 260 |
'sub' => isset($cond['sub']) ? sanitize_text_field($cond['sub']) : '', |
| 261 |
'child_sub' => isset($cond['child_sub']) ? sanitize_text_field($cond['child_sub']) : '', |
| 262 |
]; |
| 263 |
} |
| 264 |
|
| 265 |
return $sanitized; |
| 266 |
} |
| 267 |
|
| 268 |
/** |
| 269 |
* Safely decode JSON or return array as-is |
| 270 |
*/ |
| 271 |
function safe_json_decode( $data ) { |
| 272 |
if ( is_string($data) ) { |
| 273 |
$decoded = json_decode($data, true); |
| 274 |
if ( json_last_error() === JSON_ERROR_NONE && is_array($decoded) ) { |
| 275 |
return $decoded; |
| 276 |
} |
| 277 |
return []; |
| 278 |
} elseif ( is_array($data) ) { |
| 279 |
return $data; |
| 280 |
} else { |
| 281 |
return []; |
| 282 |
} |
| 283 |
} |
| 284 |
|
| 285 |
class Easy_Widget_Injection { |
| 286 |
public static function init() { |
| 287 |
add_filter( 'elementor/controls/animations/additional_animations', [ __CLASS__, 'inject_easy_animations' ] ); |
| 288 |
} |
| 289 |
|
| 290 |
public static function inject_easy_animations( $animations ) { |
| 291 |
$animations['Easy Animations'] = [ |
| 292 |
'scaleIn' => __( 'Scale In', 'easy-elements' ), |
| 293 |
]; |
| 294 |
return $animations; |
| 295 |
} |
| 296 |
} |
| 297 |
|
| 298 |
// Initialize the class |
| 299 |
Easy_Widget_Injection::init(); |
| 300 |
|
| 301 |
|
| 302 |
/** |
| 303 |
* Check if a specific Easy Element extension setting is enabled. |
| 304 |
* |
| 305 |
* @param string $setting_key The key of the setting to check (e.g. 'enable_sticky_elements'). |
| 306 |
* @return bool True if enabled, false otherwise. |
| 307 |
*/ |
| 308 |
function easy_element_is_enabled( $setting_key ) { |
| 309 |
if ( empty( $setting_key ) ) { |
| 310 |
return false; |
| 311 |
} |
| 312 |
|
| 313 |
$tab_slug = 'extensions'; |
| 314 |
$settings = get_option( 'easy_element_' . $tab_slug, [] ); |
| 315 |
|
| 316 |
// Sanitize and check |
| 317 |
$value = isset( $settings[ $setting_key ] ) ? (int) $settings[ $setting_key ] : 0; |
| 318 |
|
| 319 |
return ( $value === 1 ); |
| 320 |
} |
| 321 |
|
| 322 |
|
| 323 |
function easyel_translate_hfe_template( $template_id ) { |
| 324 |
if ( function_exists( 'pll_get_post' ) ) { |
| 325 |
$translated = pll_get_post( $template_id ); |
| 326 |
if ( $translated ) { |
| 327 |
$template_id = $translated; |
| 328 |
} |
| 329 |
} |
| 330 |
if ( has_filter( 'wpml_object_id' ) ) { |
| 331 |
$translated = apply_filters( 'wpml_object_id', $template_id, 'ee-elementor-hf', true ); |
| 332 |
if ( $translated ) { |
| 333 |
$template_id = $translated; |
| 334 |
} |
| 335 |
} |
| 336 |
return $template_id; |
| 337 |
} |
| 338 |
|
| 339 |
add_filter( 'easyel_get_settings_type_header', 'easyel_translate_hfe_template' ); |
| 340 |
add_filter( 'easyel_get_settings_type_footer', 'easyel_translate_hfe_template' ); |
| 341 |
add_filter( 'easyel_get_settings_type_easy_topbar', 'easyel_translate_hfe_template' ); |
| 342 |
add_filter( 'easyel_get_settings_type_easy_after__header', 'easyel_translate_hfe_template' ); |
| 343 |
add_filter( 'easyel_get_settings_type_before_footer', 'easyel_translate_hfe_template' ); |
| 344 |
|
| 345 |
if ( ! function_exists( 'easyel_get_valid_archive_post_types' ) ) { |
| 346 |
function easyel_get_valid_archive_post_types() { |
| 347 |
|
| 348 |
$post_types = get_post_types( |
| 349 |
[ |
| 350 |
'public' => true, |
| 351 |
'show_in_nav_menus' => true, |
| 352 |
], |
| 353 |
'objects' |
| 354 |
); |
| 355 |
|
| 356 |
$valid = []; |
| 357 |
|
| 358 |
foreach ( $post_types as $post_type => $pt ) { |
| 359 |
|
| 360 |
if ( ! $pt->has_archive || ! get_post_type_archive_link( $post_type ) ) { |
| 361 |
continue; |
| 362 |
} |
| 363 |
|
| 364 |
if ( $post_type === 'page' ) { |
| 365 |
continue; |
| 366 |
} |
| 367 |
|
| 368 |
if ( |
| 369 |
! empty( $pt->_builtin ) === false && |
| 370 |
str_starts_with( $post_type, 'elementor' ) |
| 371 |
) { |
| 372 |
continue; |
| 373 |
} |
| 374 |
|
| 375 |
if ( ! $pt->publicly_queryable ) { |
| 376 |
continue; |
| 377 |
} |
| 378 |
|
| 379 |
$valid[ $post_type ] = $pt; |
| 380 |
} |
| 381 |
|
| 382 |
return $valid; |
| 383 |
} |
| 384 |
} |
| 385 |
|
| 386 |
if ( ! function_exists( 'easyel_get_hierarchical_taxonomies_by_post_type' ) ) { |
| 387 |
function easyel_get_hierarchical_taxonomies_by_post_type() { |
| 388 |
|
| 389 |
$map = []; |
| 390 |
$post_types = easyel_get_valid_archive_post_types(); |
| 391 |
|
| 392 |
foreach ($post_types as $post_type => $pt) { |
| 393 |
$taxonomies = get_object_taxonomies($post_type, 'objects'); |
| 394 |
|
| 395 |
foreach ($taxonomies as $tax_slug => $tax) { |
| 396 |
if (!$tax->public) { |
| 397 |
continue; |
| 398 |
} |
| 399 |
|
| 400 |
$map[$tax_slug] = [ |
| 401 |
'post_type' => $post_type, |
| 402 |
'taxonomy' => $tax_slug, |
| 403 |
]; |
| 404 |
} |
| 405 |
} |
| 406 |
|
| 407 |
return $map; |
| 408 |
} |
| 409 |
} |
| 410 |
|
| 411 |
if ( ! function_exists('easyel_theme_builder_child_options') ) { |
| 412 |
/** |
| 413 |
* Get global condition arrays: needs_child_sub & no_child_sub |
| 414 |
* |
| 415 |
* @return array |
| 416 |
*/ |
| 417 |
function easyel_theme_builder_child_options() { |
| 418 |
// Default needs_child_sub |
| 419 |
$needs_child_sub = [ |
| 420 |
'author', |
| 421 |
'category', |
| 422 |
'child_of_category', |
| 423 |
'any_child_of_category', |
| 424 |
'in_category', |
| 425 |
'in_category_children', |
| 426 |
'post_tag', |
| 427 |
'in_post_tag', |
| 428 |
'child_of', |
| 429 |
'any_child_of', |
| 430 |
'product_cat', |
| 431 |
'product_tag', |
| 432 |
'product_brand', |
| 433 |
'post', |
| 434 |
'page', |
| 435 |
'page_by_author', |
| 436 |
]; |
| 437 |
|
| 438 |
// Default no_child_sub |
| 439 |
$no_child_sub = [ |
| 440 |
"all", |
| 441 |
"front_page", |
| 442 |
"not_found404", |
| 443 |
"index", |
| 444 |
"search", |
| 445 |
"date", |
| 446 |
"post_archive", |
| 447 |
"all_product_archive", |
| 448 |
"product_search", |
| 449 |
"shop_page", |
| 450 |
]; |
| 451 |
|
| 452 |
// Get dynamic archive taxonomies |
| 453 |
$archive_taxonomies = function_exists('easyel_get_hierarchical_taxonomies_by_post_type') |
| 454 |
? easyel_get_hierarchical_taxonomies_by_post_type() |
| 455 |
: []; |
| 456 |
|
| 457 |
if ( is_array($archive_taxonomies) || is_object($archive_taxonomies) ) { |
| 458 |
foreach ($archive_taxonomies as $tax_slug => $data) { |
| 459 |
$needs_child_sub[] = $tax_slug; |
| 460 |
$needs_child_sub[] = 'child_of_' . $tax_slug; |
| 461 |
$needs_child_sub[] = 'any_child_of_' . $tax_slug; |
| 462 |
|
| 463 |
$needs_child_sub[] = 'in_' . $tax_slug; |
| 464 |
$needs_child_sub[] = 'in_' . $tax_slug . '_children'; |
| 465 |
$needs_child_sub[] = $data['post_type'] . '_by_author'; |
| 466 |
|
| 467 |
if ( ! empty($data['post_type']) ) { |
| 468 |
$no_child_sub[] = $data['post_type']."_archive"; |
| 469 |
$needs_child_sub[] = $data['post_type']; |
| 470 |
} |
| 471 |
} |
| 472 |
} |
| 473 |
|
| 474 |
return [ |
| 475 |
'needs_child_sub' => $needs_child_sub, |
| 476 |
'no_child_sub' => $no_child_sub, |
| 477 |
]; |
| 478 |
} |
| 479 |
} |
| 480 |
|
| 481 |
if ( ! function_exists( 'easyel_get_prepared_post_id' ) ) { |
| 482 |
function easyel_get_prepared_post_id() { |
| 483 |
|
| 484 |
if ( is_singular( 'post' ) ) { |
| 485 |
return get_the_ID(); |
| 486 |
} |
| 487 |
|
| 488 |
$cache_key = 'easyel_latest_post_id'; |
| 489 |
$post_id = wp_cache_get( $cache_key, 'easyel' ); |
| 490 |
|
| 491 |
if ( ! $post_id || get_post_status( $post_id ) !== 'publish' ) { |
| 492 |
|
| 493 |
$latest_post = get_posts([ |
| 494 |
'post_type' => 'post', |
| 495 |
'post_status' => 'publish', |
| 496 |
'posts_per_page' => 1, |
| 497 |
'orderby' => 'date', |
| 498 |
'order' => 'DESC', |
| 499 |
'fields' => 'ids', |
| 500 |
]); |
| 501 |
|
| 502 |
$post_id = !empty($latest_post) ? $latest_post[0] : 0; |
| 503 |
|
| 504 |
wp_cache_set( $cache_key, $post_id, 'easyel', 12 * HOUR_IN_SECONDS ); |
| 505 |
} |
| 506 |
|
| 507 |
return $post_id; |
| 508 |
} |
| 509 |
} |