array( 'name' => __('Popups', 'ai-eshop-optimizer'), 'singular_name' => __('Popup', 'ai-eshop-optimizer'), 'add_new_item' => __('Add Popup', 'ai-eshop-optimizer'), 'edit_item' => __('Edit Popup', 'ai-eshop-optimizer'), 'menu_name' => __('Popups', 'ai-eshop-optimizer'), ), 'public' => false, 'publicly_queryable' => true, 'exclude_from_search' => true, 'has_archive' => false, 'rewrite' => false, 'show_ui' => true, 'show_in_menu' => false, 'show_in_rest' => true, 'menu_icon' => 'dashicons-external', 'supports' => array('title', 'editor', 'revisions', 'page-attributes'), 'template' => array(array('aieo/popup-panel')), )); $auth = static function () { return current_user_can('edit_posts'); }; foreach (array(self::META_START, self::META_END, self::META_TRIGGER, self::META_FREQ, self::META_DEVICE, self::META_VISITOR, self::META_CART, self::META_URL_CONTAINS, self::META_COUPON, self::META_SURFACE, self::META_DATA_DELAY, self::META_TEST, self::META_INSTIGATOR, self::META_INSTIGATOR_REF) as $key) { register_post_meta(self::POST_TYPE, $key, array( 'type' => 'string', 'single' => true, 'show_in_rest' => true, 'auth_callback' => $auth, )); } foreach (array(self::META_DELAY_MS, self::META_SCROLL_PCT, self::META_IDLE_S, self::META_FREQ_DAYS, self::META_MAX_IMPR, self::META_AUDIENCE_ID, self::META_MAX_PER_SESSION) as $key) { register_post_meta(self::POST_TYPE, $key, array( 'type' => 'integer', 'single' => true, 'show_in_rest' => true, 'auth_callback' => $auth, )); } register_post_meta(self::POST_TYPE, self::META_CART_MIN, array( 'type' => 'number', 'single' => true, 'show_in_rest' => true, 'auth_callback' => $auth, )); foreach (array(self::META_PAGES, self::META_EXCLUDE_PAGES) as $key) { register_post_meta(self::POST_TYPE, $key, array( 'type' => 'array', 'single' => true, 'auth_callback' => $auth, 'show_in_rest' => array('schema' => array('type' => 'array', 'items' => array('type' => 'string'))), )); } register_post_meta(self::POST_TYPE, self::META_POST_IDS, array( 'type' => 'array', 'single' => true, 'auth_callback' => $auth, 'show_in_rest' => array('schema' => array('type' => 'array', 'items' => array('type' => 'integer'))), )); } public static function defaults() { return array( self::META_START => '', self::META_END => '', self::META_TRIGGER => 'load', self::META_DELAY_MS => 1500, self::META_SCROLL_PCT => 50, self::META_IDLE_S => 20, self::META_DATA_DELAY => 'no', self::META_TEST => 'no', self::META_FREQ => 'session', self::META_FREQ_DAYS => 7, self::META_MAX_IMPR => 0, self::META_MAX_PER_SESSION => 0, self::META_INSTIGATOR => 'any', self::META_INSTIGATOR_REF => '', self::META_PAGES => array('all'), self::META_EXCLUDE_PAGES => array(), self::META_POST_IDS => array(), self::META_URL_CONTAINS => '', self::META_DEVICE => 'all', self::META_VISITOR => 'all', self::META_CART => 'any', self::META_CART_MIN => 0, self::META_AUDIENCE_ID => 0, self::META_COUPON => '', ); } public static function coupon_code($post_id) { return AIEO_Popup_Offer::code_for((int) $post_id); } public static function get($post_id, $key) { $defaults = self::defaults(); $default = isset($defaults[$key]) ? $defaults[$key] : ''; $raw = get_post_meta((int) $post_id, $key, true); if (is_array($default)) { return is_array($raw) ? $raw : $default; } if ($raw === '' || $raw === null) { return $default; } if (is_int($default)) { return (int) $raw; } if (is_float($default)) { return (float) $raw; } return $raw; } public static function schedule_state($post_id) { return self::state_from( (string) self::get($post_id, self::META_START), (string) self::get($post_id, self::META_END) ); } public static function state_from($start, $end) { $now = current_time('mysql'); if ($start !== '' && $now < $start) { return 'before'; } if ($end !== '' && $now > $end) { return 'ended'; } return 'live'; } public static function to_epoch($mysql_dt) { $mysql_dt = trim((string) $mysql_dt); if ($mysql_dt === '') { return 0; } $gmt = get_gmt_from_date($mysql_dt, 'U'); return $gmt ? (int) $gmt : 0; } private static function load_dt_helpers() { if (class_exists('AIEO_Competition_CPT')) { return true; } if (defined('AIEO_DIR') && file_exists(AIEO_DIR . 'includes/dmm/competitions/class-aieo-competition-cpt.php')) { require_once AIEO_DIR . 'includes/dmm/competitions/class-aieo-competition-cpt.php'; } return class_exists('AIEO_Competition_CPT'); } public static function normalize_dt($v) { if (self::load_dt_helpers()) { return AIEO_Competition_CPT::normalize_dt($v); } $v = str_replace('T', ' ', trim((string) $v)); return preg_match('/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}(:\d{2})?$/', $v) ? (strlen($v) === 16 ? $v . ':00' : $v) : ''; } public static function to_input($mysql_dt) { if (self::load_dt_helpers()) { return AIEO_Competition_CPT::to_input($mysql_dt); } $mysql_dt = trim((string) $mysql_dt); return $mysql_dt === '' ? '' : str_replace(' ', 'T', substr($mysql_dt, 0, 16)); } public static function fmt_dt($mysql_dt) { if (self::load_dt_helpers()) { return AIEO_Competition_CPT::fmt_dt($mysql_dt); } $mysql_dt = trim((string) $mysql_dt); return $mysql_dt; } public static function surface_tag($post_id) { $post_id = (int) $post_id; $stored = (string) get_post_meta($post_id, self::META_SURFACE, true); if ($stored !== '') { return $stored; } return self::mint_surface_tag($post_id); } public static function mint_surface_tag($post_id) { $post_id = (int) $post_id; $stored = (string) get_post_meta($post_id, self::META_SURFACE, true); if ($stored !== '') { return $stored; } $slug = sanitize_key((string) get_post_field('post_name', $post_id)); if ($slug === '') { $slug = 'p' . $post_id; } if (strlen($slug) > self::SLUG_MAX) { $slug = substr($slug, 0, self::SLUG_MAX - strlen((string) $post_id) - 1) . '-' . $post_id; } $tag = 'popup_' . $slug; update_post_meta($post_id, self::META_SURFACE, $tag); return $tag; } public static function placement_rules($post_id) { return array( 'pages' => array_values((array) self::get($post_id, self::META_PAGES)), 'exclude' => array_values((array) self::get($post_id, self::META_EXCLUDE_PAGES)), 'ids' => array_map('intval', (array) self::get($post_id, self::META_POST_IDS)), 'url' => trim((string) self::get($post_id, self::META_URL_CONTAINS)), 'advertises' => class_exists('AIEO_Popup_Offer', false) && AIEO_Popup_Offer::advertises((int) $post_id) ? (int) $post_id : 0, ); } public static function placement_matches(array $rules) { $matches = class_exists('AIEO_Display_Conditions') ? AIEO_Display_Conditions::placement_matches($rules, false) : self::placement_matches_legacy($rules); if ($matches && !empty($rules['advertises']) && class_exists('AIEO_Popup_Offer', false)) { return AIEO_Popup_Offer::shows((int) $rules['advertises']); } return $matches; } private static function placement_matches_legacy(array $rules) { $include = isset($rules['pages']) ? (array) $rules['pages'] : array('all'); $exclude = isset($rules['exclude']) ? (array) $rules['exclude'] : array(); $ids = isset($rules['ids']) ? (array) $rules['ids'] : array(); $needle = isset($rules['url']) ? (string) $rules['url'] : ''; if ($needle !== '') { $uri = isset($_SERVER['REQUEST_URI']) ? esc_url_raw(wp_unslash($_SERVER['REQUEST_URI'])) : ''; if (stripos($uri, $needle) === false) { return false; } } foreach ($exclude as $token) { if (self::token_matches($token, $ids)) { return false; } } if (in_array('all', $include, true)) { return true; } foreach ($include as $token) { if (self::token_matches($token, $ids)) { return true; } } return false; } private static function token_matches($token, array $ids) { switch ($token) { case 'all': return true; case 'front': return is_front_page(); case 'blog': return is_home() || is_singular('post') || is_category() || is_tag(); case 'shop': return function_exists('is_shop') && (is_shop() || (function_exists('is_product_taxonomy') && is_product_taxonomy())); case 'product': return function_exists('is_product') && is_product(); case 'product_cat': return function_exists('is_product_category') && is_product_category(); case 'cart': return function_exists('is_cart') && is_cart(); case 'checkout': return function_exists('is_checkout') && is_checkout(); case 'account': return function_exists('is_account_page') && is_account_page(); case 'ids': return $ids && is_singular() && in_array((int) get_queried_object_id(), array_map('intval', $ids), true); } return false; } private static function conditions_from_meta($post_id) { $post_id = (int) $post_id; $offer = class_exists('AIEO_Popup_Offer', false) ? AIEO_Popup_Offer::window_for($post_id) : array(0, 0, 0); $start = (int) self::to_epoch(self::get($post_id, self::META_START)); $end = (int) self::to_epoch(self::get($post_id, self::META_END)); $own = (int) self::get($post_id, self::META_AUDIENCE_ID); return array( 'start' => max($start, (int) $offer[0]), 'end' => $end > 0 && $offer[1] > 0 ? min($end, (int) $offer[1]) : max($end, (int) $offer[1]), 'trigger' => (string) self::get($post_id, self::META_TRIGGER), 'delayMs' => (int) self::get($post_id, self::META_DELAY_MS), 'scrollPct' => (int) self::get($post_id, self::META_SCROLL_PCT), 'idleS' => (int) self::get($post_id, self::META_IDLE_S), 'freq' => (string) self::get($post_id, self::META_FREQ), 'freqDays' => (int) self::get($post_id, self::META_FREQ_DAYS), 'maxImpr' => (int) self::get($post_id, self::META_MAX_IMPR), 'maxPerSession' => (int) self::get($post_id, self::META_MAX_PER_SESSION), 'instigator' => (string) self::get($post_id, self::META_INSTIGATOR), 'instigatorRef' => (string) self::get($post_id, self::META_INSTIGATOR_REF), 'device' => (string) self::get($post_id, self::META_DEVICE), 'visitor' => (string) self::get($post_id, self::META_VISITOR), 'cart' => (string) self::get($post_id, self::META_CART), 'cartMin' => (float) self::get($post_id, self::META_CART_MIN), 'audience' => $own > 0 ? $own : (int) $offer[2], 'test' => self::get($post_id, self::META_TEST) === 'yes', 'priority' => $post_id > 0 ? (int) get_post_field('menu_order', $post_id) : 10, ); } public static function client_config($post_id) { $post_id = (int) $post_id; $post = get_post($post_id); $identity = array( 'id' => $post_id, 'surface' => self::surface_tag($post_id), 'v' => $post ? (int) strtotime($post->post_modified_gmt . ' UTC') : 0, ); if (!class_exists('AIEO_Display_Conditions')) { return self::with_offer($post_id, array_merge($identity, self::conditions_from_meta($post_id))); } return self::with_offer($post_id, AIEO_Display_Conditions::client_config( self::conditions_from_meta($post_id), $identity )); } private static function with_offer($post_id, array $cfg) { if (class_exists('AIEO_Popup_Offer', false) && AIEO_Popup_Offer::advertises((int) $post_id)) { $cfg['offer'] = (int) get_post_meta((int) $post_id, self::META_OFFER_ID, true); $cfg['offerCart'] = esc_url_raw(rest_url('wc/store/v1/cart')); } return $cfg; } public static function on_save($post_id, $post) { if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return; } if (wp_is_post_revision($post_id)) { return; } if (isset($post->post_status) && $post->post_status === 'publish') { self::mint_surface_tag($post_id); } self::purge_caches(); self::arm_boundaries($post_id); } public static function on_delete($post_id) { if (get_post_type($post_id) !== self::POST_TYPE) { return; } wp_clear_scheduled_hook(self::BOUNDARY_HOOK, array((int) $post_id)); self::purge_caches(); AIEO_Popup_Offer::on_delete((int) $post_id); } public static function arm_boundaries($post_id) { $post_id = (int) $post_id; $args = array($post_id); wp_clear_scheduled_hook(self::BOUNDARY_HOOK, $args); $now = time(); foreach (array(self::META_START, self::META_END) as $key) { $ts = self::to_epoch(self::get($post_id, $key)); if ($ts > $now) { wp_schedule_single_event($ts + 5, self::BOUNDARY_HOOK, $args); } } $offer_end = AIEO_Popup_Offer::end_epoch($post_id); if (null !== $offer_end && $offer_end > $now) { wp_schedule_single_event($offer_end + 5, self::BOUNDARY_HOOK, $args); } } public static function purge_caches() { do_action('aieo_purge_page_cache'); do_action('aieo_popup_caches_purged'); } public static function no_canonical_redirect($redirect, $requested = '') { if (is_singular(self::POST_TYPE)) { return false; } if ('' !== $requested && false !== strpos($requested, self::POST_TYPE . '=')) { return false; } return $redirect; } public static function gate_single_view() { if (!is_singular(self::POST_TYPE)) { return; } $cap = defined('AIEO_CAPABILITY') ? AIEO_CAPABILITY : 'manage_options'; if (current_user_can($cap) || current_user_can('edit_posts')) { return; } global $wp_query; $wp_query->set_404(); status_header(404); nocache_headers(); include get_query_template('404'); exit; } public static function bare_template($template) { if (!is_singular(self::POST_TYPE)) { return $template; } add_filter('wp_robots', 'wp_robots_no_robots'); $bare = defined('AIEO_DIR') ? AIEO_DIR . 'includes/dmm/popups/template-popup-bare.php' : ''; return ($bare && file_exists($bare)) ? $bare : $template; } public static function enqueue_editor_assets() { $screen = function_exists('get_current_screen') ? get_current_screen() : null; if (!$screen || $screen->post_type !== self::POST_TYPE) { return; } wp_enqueue_media(); if (function_exists('rooster_admin_table_assets')) { rooster_admin_table_assets(); } } public static function add_metabox() { add_meta_box( 'aieo-popup-display', __('Popup display', 'ai-eshop-optimizer'), array(__CLASS__, 'render_metabox'), self::POST_TYPE, 'normal', 'high' ); } private static function notice($html, $tone, $detail = '') { return AIEO_DMM_UI::notice($html, $tone, array('detail' => $detail)); } public static function render_metabox($post) { wp_nonce_field(self::NONCE, 'aieo_popup_meta_nonce'); $id = (int) $post->ID; $UI = 'AIEO_Display_Conditions_UI'; if (!class_exists($UI)) { echo '

' . esc_html__('The shared display controls are unavailable. Reactivate Rooster One to edit this popup\'s rules.', 'ai-eshop-optimizer') . '

'; return; } $cond = self::conditions_from_meta($id); $page_labels = array( 'all' => __('Everywhere', 'ai-eshop-optimizer'), 'front' => __('Front page', 'ai-eshop-optimizer'), 'blog' => __('Blog (posts, categories, tags)', 'ai-eshop-optimizer'), 'shop' => __('Shop and product archives', 'ai-eshop-optimizer'), 'product' => __('Product pages', 'ai-eshop-optimizer'), 'product_cat' => __('Product categories', 'ai-eshop-optimizer'), 'cart' => __('Cart', 'ai-eshop-optimizer'), 'checkout' => __('Checkout', 'ai-eshop-optimizer'), 'account' => __('My account', 'ai-eshop-optimizer'), 'ids' => __('Specific page/post IDs', 'ai-eshop-optimizer'), ); $start = (string) self::get($id, self::META_START); $end = (string) self::get($id, self::META_END); $state = self::schedule_state($id); echo ''; echo '
'; $testing = self::get($id, self::META_TEST) === 'yes'; echo '

' . esc_html__('Test mode', 'ai-eshop-optimizer') . '

'; echo self::notice( '', $testing ? 'warning' : 'mono', '

' . esc_html__('Ignores the active period, where it appears, who sees it and how often — so you can reload the storefront and keep seeing it while you work on the design. The popup carries a visible TEST MODE badge and records no statistics while this is on. Remember to switch it off.', 'ai-eshop-optimizer') . '

' ); echo '
'; echo '

' . esc_html__('Active period', 'ai-eshop-optimizer') . '

'; echo '


'; echo '

'; echo '


'; echo '

'; echo '

' . esc_html__('Leave a field empty to leave that side open. Times are in the site timezone.', 'ai-eshop-optimizer') . '

'; if ($start !== '' || $end !== '') { $note = $state === 'before' ? sprintf(__('Scheduled — starts %s.', 'ai-eshop-optimizer'), self::fmt_dt($start)) : ($state === 'ended' ? sprintf(__('Finished — ended %s.', 'ai-eshop-optimizer'), self::fmt_dt($end)) : ($end !== '' ? sprintf(__('Live — until %s.', 'ai-eshop-optimizer'), self::fmt_dt($end)) : __('Live.', 'ai-eshop-optimizer'))); echo self::notice(esc_html($note), 'before' === $state ? 'info' : ('ended' === $state ? 'mono' : 'success')); } echo '
'; echo '

' . esc_html__('Trigger', 'ai-eshop-optimizer') . '

'; $UI::render_field('trigger', 'aieo_pop_trigger', $cond, array( 'only' => array('load', 'delay', 'scroll', 'exit'), 'label' => __('Show it', 'ai-eshop-optimizer'), 'help' => __('Exit intent falls back to an idle timer or a fast scroll up on touch devices, where a mouse leaving the window cannot be detected.', 'ai-eshop-optimizer'), )); $UI::render_field('delayMs', 'aieo_pop_delay_ms', $cond, array( 'help' => __('Used by "when the page loads" and "after a delay".', 'ai-eshop-optimizer'), )); $UI::render_field('scrollPct', 'aieo_pop_scroll_pct', $cond); $UI::render_field('idleS', 'aieo_pop_idle_s', $cond, array( 'label' => __('Idle seconds (touch fallback)', 'ai-eshop-optimizer'), )); echo '

'; echo '' . esc_html__('On a product page, wait as long as shoppers typically spend on that product before deciding, rather than a fixed number.', 'ai-eshop-optimizer') . '

'; echo '
'; echo '

' . esc_html__('How often', 'ai-eshop-optimizer') . '

'; $UI::render_field('freq', 'aieo_pop_freq', $cond, array( 'label' => __('Repeat', 'ai-eshop-optimizer'), 'help' => __('Whichever you choose, a visitor who closes this popup does not see it again for the rest of their visit. Editing this popup resets the counters, so returning visitors see the new version.', 'ai-eshop-optimizer'), )); $UI::render_field('freqDays', 'aieo_pop_freq_days', $cond, array('label' => __('Days between shows', 'ai-eshop-optimizer'))); $UI::render_field('maxImpr', 'aieo_pop_max_impr', $cond, array('label' => __('Maximum times shown', 'ai-eshop-optimizer'))); $UI::render_field('maxPerSession', 'aieo_pop_max_per_session', $cond); echo '
'; echo '

' . esc_html__('What sent them here', 'ai-eshop-optimizer') . '

'; $UI::render_field('instigator', 'aieo_pop_instigator', $cond, array( 'label' => __('Only for visitors who arrived', 'ai-eshop-optimizer'), )); $UI::render_field('instigatorRef', 'aieo_pop_instigator_ref', $cond); echo '
'; $inc = (array) self::get($id, self::META_PAGES); $exc = (array) self::get($id, self::META_EXCLUDE_PAGES); echo '

' . esc_html__('Where it appears', 'ai-eshop-optimizer') . '

'; echo '
'; foreach ($page_labels as $token => $label) { echo ''; } echo '
'; echo '


'; echo '

'; echo '


'; echo '

'; echo '

' . esc_html__('Never show on', 'ai-eshop-optimizer') . '

'; foreach ($page_labels as $token => $label) { if ($token === 'all') { continue; } echo ''; } echo '
'; echo '

' . esc_html__('Who sees it', 'ai-eshop-optimizer') . '

'; $UI::render_field('device', 'aieo_pop_device', $cond, array('label' => __('Devices', 'ai-eshop-optimizer'))); $UI::render_field('visitor', 'aieo_pop_visitor', $cond, array('label' => __('Visitors', 'ai-eshop-optimizer'))); $UI::render_field('cart', 'aieo_pop_cart', $cond, array('label' => __('Cart', 'ai-eshop-optimizer'))); $UI::render_field('cartMin', 'aieo_pop_cart_min', $cond, array('label' => __('Minimum cart total', 'ai-eshop-optimizer'))); echo '


'; echo '
' . esc_html__('Audience matching needs a signed-in customer, so guests never match an audience-restricted popup.', 'ai-eshop-optimizer') . '

'; AIEO_Popup_Offer::render_field($id); echo '


'; echo '
'; echo '' . esc_html__('Used to attribute the discount this popup gives away as a cost. Leave empty if it offers no coupon.', 'ai-eshop-optimizer') . '

'; echo '
'; echo '
'; } public static function save_metabox($post_id, $post) { if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return; } if (!isset($_POST['aieo_popup_meta_nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['aieo_popup_meta_nonce'])), self::NONCE)) { return; } if (!current_user_can('edit_post', $post_id)) { return; } $post_id = (int) $post_id; update_post_meta($post_id, self::META_START, self::normalize_dt(isset($_POST['aieo_pop_start']) ? sanitize_text_field(wp_unslash($_POST['aieo_pop_start'])) : '')); update_post_meta($post_id, self::META_END, self::normalize_dt(isset($_POST['aieo_pop_end']) ? sanitize_text_field(wp_unslash($_POST['aieo_pop_end'])) : '')); $enum = static function ($key, array $allowed, $fallback) { $v = isset($_POST[$key]) ? sanitize_key(wp_unslash($_POST[$key])) : ''; return in_array($v, $allowed, true) ? $v : $fallback; }; update_post_meta($post_id, self::META_TRIGGER, $enum('aieo_pop_trigger', array('load', 'delay', 'scroll', 'exit'), 'load')); update_post_meta($post_id, self::META_FREQ, $enum('aieo_pop_freq', array('session', 'once', 'days', 'always'), 'session')); update_post_meta($post_id, self::META_DEVICE, $enum('aieo_pop_device', array('all', 'desktop', 'mobile'), 'all')); update_post_meta($post_id, self::META_VISITOR, $enum('aieo_pop_visitor', array('all', 'guest', 'logged_in', 'new', 'returning'), 'all')); update_post_meta($post_id, self::META_CART, $enum('aieo_pop_cart', array('any', 'empty', 'has_items', 'min_total'), 'any')); update_post_meta($post_id, self::META_DELAY_MS, min(600000, max(0, (int) ($_POST['aieo_pop_delay_ms'] ?? 1500)))); update_post_meta($post_id, self::META_SCROLL_PCT, min(100, max(1, (int) ($_POST['aieo_pop_scroll_pct'] ?? 50)))); update_post_meta($post_id, self::META_IDLE_S, min(600, max(3, (int) ($_POST['aieo_pop_idle_s'] ?? 20)))); update_post_meta($post_id, self::META_FREQ_DAYS, min(3650, max(1, (int) ($_POST['aieo_pop_freq_days'] ?? 7)))); update_post_meta($post_id, self::META_MAX_IMPR, max(0, (int) ($_POST['aieo_pop_max_impr'] ?? 0))); update_post_meta($post_id, self::META_MAX_PER_SESSION, max(0, (int) ($_POST['aieo_pop_max_per_session'] ?? 0))); $instigators = class_exists('AIEO_Display_Conditions') ? AIEO_Display_Conditions::INSTIGATORS : array('any'); $inst = isset($_POST['aieo_pop_instigator']) ? sanitize_key(wp_unslash($_POST['aieo_pop_instigator'])) : 'any'; update_post_meta($post_id, self::META_INSTIGATOR, in_array($inst, $instigators, true) ? $inst : 'any'); update_post_meta($post_id, self::META_INSTIGATOR_REF, substr( sanitize_text_field(wp_unslash($_POST['aieo_pop_instigator_ref'] ?? '')), 0, 191 )); update_post_meta($post_id, self::META_CART_MIN, max(0, (float) ($_POST['aieo_pop_cart_min'] ?? 0))); update_post_meta($post_id, self::META_AUDIENCE_ID, max(0, (int) ($_POST['aieo_pop_audience_id'] ?? 0))); $tokens = static function ($key) { $raw = isset($_POST[$key]) ? (array) wp_unslash($_POST[$key]) : array(); $out = array(); foreach ($raw as $t) { $t = sanitize_key($t); if (in_array($t, self::PAGE_TOKENS, true)) { $out[] = $t; } } return array_values(array_unique($out)); }; $include = $tokens('aieo_pop_pages'); update_post_meta($post_id, self::META_PAGES, $include ? $include : array('all')); update_post_meta($post_id, self::META_EXCLUDE_PAGES, $tokens('aieo_pop_exclude_pages')); $ids_raw = isset($_POST['aieo_pop_post_ids']) ? sanitize_text_field(wp_unslash($_POST['aieo_pop_post_ids'])) : ''; $ids = array_values(array_filter(array_map('intval', preg_split('/[^0-9]+/', $ids_raw)))); update_post_meta($post_id, self::META_POST_IDS, $ids); update_post_meta($post_id, self::META_DATA_DELAY, empty($_POST['aieo_pop_data_delay']) ? 'no' : 'yes'); update_post_meta($post_id, self::META_TEST, empty($_POST['aieo_pop_test']) ? 'no' : 'yes'); update_post_meta($post_id, self::META_URL_CONTAINS, isset($_POST['aieo_pop_url_contains']) ? sanitize_text_field(wp_unslash($_POST['aieo_pop_url_contains'])) : ''); update_post_meta($post_id, self::META_COUPON, isset($_POST['aieo_pop_coupon']) ? sanitize_text_field(wp_unslash($_POST['aieo_pop_coupon'])) : ''); AIEO_Popup_Offer::save_choice($post_id); } } require_once __DIR__ . '/class-aieo-popup-offer.php';