'aieo_popup', 'post_status' => 'publish', 'numberposts' => 30, 'orderby' => array('menu_order' => 'ASC', 'ID' => 'DESC'), 'suppress_filters' => false, 'no_found_rows' => true, 'update_post_term_cache' => false, )); $index = array(); foreach ($posts as $p) { $index[] = array( 'id' => (int) $p->ID, 'start' => (string) AIEO_Popup_CPT::get($p->ID, AIEO_Popup_CPT::META_START), 'end' => (string) AIEO_Popup_CPT::get($p->ID, AIEO_Popup_CPT::META_END), 'rules' => AIEO_Popup_CPT::placement_rules($p->ID), 'cfg' => AIEO_Popup_CPT::client_config($p->ID), ); } return $index; }; if (class_exists('AIEO_DMM_Cache')) { return AIEO_DMM_Cache::remember(self::CACHE_DOMAIN, 'index', $loader, AIEO_DMM_Cache::TTL_MEDIUM); } static $memo = null; if (null === $memo) { $memo = $loader(); } return $memo; } public function flush_index() { if (class_exists('AIEO_DMM_Cache')) { AIEO_DMM_Cache::bump_version(self::CACHE_DOMAIN); } } public function flush_index_for_popup($post_id) { if (get_post_type($post_id) !== 'aieo_popup') { return; } $this->flush_index(); } public static function editor_preview() { $elementor = class_exists('Elementor\Plugin', false) && isset(\Elementor\Plugin::$instance->preview) && is_object(\Elementor\Plugin::$instance->preview) && \Elementor\Plugin::$instance->preview->is_preview_mode(); $preview = $elementor || is_customize_preview() || wp_is_json_request() || (defined('REST_REQUEST') && REST_REQUEST); return (bool) apply_filters('aieo_editor_preview', $preview); } public function resolve_and_prerender() { if (is_admin() || wp_doing_ajax() || is_feed() || is_robots() || is_embed()) { return; } if (defined('REST_REQUEST') && REST_REQUEST) { return; } if (self::editor_preview()) { return; } if (is_404()) { return; } if (is_singular('aieo_popup')) { return; } if (function_exists('is_wc_endpoint_url') && is_wc_endpoint_url('order-received')) { return; } if (!class_exists('AIEO_Popup_CPT')) { return; } $index = $this->get_index(); if (empty($index)) { return; } $chosen = null; foreach ($index as $entry) { if (!empty($entry['cfg']['test'])) { $chosen = $entry; break; } } if (!$chosen) { foreach ($index as $entry) { if (AIEO_Popup_CPT::state_from($entry['start'], $entry['end']) !== 'live') { continue; } if (!AIEO_Popup_CPT::placement_matches($entry['rules'])) { continue; } $chosen = $entry; break; } } if (!$chosen) { return; } $content = get_post_field('post_content', $chosen['id']); if (!is_string($content) || trim($content) === '') { return; } $html = do_blocks($content); $html = do_shortcode($html); $cfg = $chosen['cfg']; $cfg['delayMs'] = $this->resolve_delay((int) $chosen['id'], (int) $cfg['delayMs']); $this->pending = array('id' => (int) $chosen['id'], 'html' => $html, 'cfg' => $cfg); $this->enqueue_assets(); } private function resolve_delay($post_id, $default_ms) { if (AIEO_Popup_CPT::get($post_id, AIEO_Popup_CPT::META_DATA_DELAY) !== 'yes') { return $default_ms; } if (!class_exists('AIEO_DMM_Checkout_Timing')) { return $default_ms; } $pid = (function_exists('is_product') && is_product()) ? (int) get_queried_object_id() : 0; $rec = (int) AIEO_DMM_Checkout_Timing::recommended_delay_seconds($pid); if ($rec <= 0) { return $default_ms; } return max(10, min(600, $rec)) * 1000; } public static function enqueue_shell_style() { $version = defined('AIEO_VERSION') ? AIEO_VERSION : '1.0'; $dir = self::asset_dir(); $css_mt = @filemtime($dir . 'assets/css/aieo-popup.css'); wp_enqueue_style( 'aieo-popup', self::asset_uri() . 'assets/css/aieo-popup.css', array(), $css_mt ? $version . '.' . $css_mt : $version ); } private function enqueue_assets() { self::enqueue_shell_style(); $version = defined('AIEO_VERSION') ? AIEO_VERSION : '1.0'; $uri = self::asset_uri(); $dir = self::asset_dir(); $deps = array(); if (self::ensure_conditions()) { AIEO_Display_Conditions::enqueue_runtime(); $deps[] = AIEO_Display_Conditions::HANDLE; $deps[] = AIEO_Display_Conditions::TRIGGERS_HANDLE; } $js_mt = @filemtime($dir . 'assets/js/aieo-popup.js'); wp_enqueue_script( 'aieo-popup', $uri . 'assets/js/aieo-popup.js', $deps, $js_mt ? $version . '.' . $js_mt : $version, true ); wp_localize_script('aieo-popup', 'aieoPopupCfg', array( 'ajaxUrl' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('aieo_popup_audience'), )); } public static function ensure_conditions() { if (class_exists('AIEO_Display_Conditions')) { return true; } $local = __DIR__ . '/class-aieo-display-conditions.php'; if (file_exists($local)) { require_once $local; } if (!class_exists('AIEO_Display_Conditions') && defined('AIEO_DIR') && file_exists(AIEO_DIR . 'includes/class-aieo-display-conditions.php')) { require_once AIEO_DIR . 'includes/class-aieo-display-conditions.php'; } return class_exists('AIEO_Display_Conditions'); } public function print_shell() { if (!$this->pending) { return; } $id = (int) $this->pending['id']; $cfg = (array) $this->pending['cfg']; $title = get_the_title($id); $box = self::box_html($this->pending['html'], !empty($cfg['test'])); if ('load' !== (string) ($cfg['trigger'] ?? '')) { $box = self::lazy_pictures($box); } ?>
next_tag('img')) { if ('lazy' !== strtolower((string) $tags->get_attribute('loading'))) { $tags->set_attribute('loading', 'lazy'); $tags->set_attribute('data-aieo-pop-img', true); } $tags->remove_attribute('fetchpriority'); } return $tags->get_updated_html(); } public static function box_html($content_html, $test_mode = false) { ob_start(); ?>