200]); $page_options = []; foreach ($pages as $page) { $page_options[$page->ID] = $page->post_title; } $post_types = get_post_types(['public' => true], 'objects'); $elementor_templates = get_posts([ 'post_type' => 'elementor_library', 'posts_per_page' => 50, ]); // Normalize options to prevent undefined index notices on fresh installs/older saved settings. $options = (isset($options) && is_array($options)) ? $options : []; $is_premium = isset($is_premium) ? (bool) $is_premium : false; $options['general'] = wp_parse_args($options['general'] ?? [], [ 'enabled' => 0, 'audience' => 'guests', 'mode' => 'confirm', 'min_age' => 18, 'cookie_days' => 30, ]); $options['display'] = wp_parse_args($options['display'] ?? [], [ 'scope' => 'site', 'exclude_ids' => [], 'mode' => 'global', 'cpt_scope' => [], 'archives' => 0, 'woo' => [ 'enabled' => 0, 'apply_to' => 'product', 'categories' => [], ], ]); $options['display']['exclude_ids'] = array_map('intval', (array) $options['display']['exclude_ids']); $options['display']['cpt_scope'] = array_values(array_map('strval', (array) $options['display']['cpt_scope'])); $options['display']['woo'] = wp_parse_args($options['display']['woo'] ?? [], [ 'enabled' => 0, 'apply_to' => 'product', 'categories' => [], ]); $options['display']['woo']['categories'] = array_map('intval', (array) $options['display']['woo']['categories']); $product_cats = []; if (taxonomy_exists('product_cat')) { $woo_terms = get_terms([ 'taxonomy' => 'product_cat', 'hide_empty' => false, ]); if (!is_wp_error($woo_terms)) { foreach ($woo_terms as $woo_term) { $product_cats[(int) $woo_term->term_id] = $woo_term->name; } } } $options['design'] = wp_parse_args($options['design'] ?? [], [ 'template' => 'center-card', 'overlay_color' => '#000000', 'overlay_opacity' => 0.6, 'card_background' => '#ffffff', 'card_width' => 420, 'title' => __('Age Verification', 'king-addons'), 'subtitle' => __('You must be 18+ to enter.', 'king-addons'), 'text_color' => '#111111', 'button_yes' => __('Yes', 'king-addons'), 'button_no' => __('No', 'king-addons'), 'title_size' => 24, 'body_size' => 16, 'title_weight' => 700, 'body_weight' => 400, 'button_yes_color' => '#ffffff', 'button_yes_bg' => '#6d28d9', 'button_no_color' => '#111111', 'button_no_bg' => '#e5e7eb', 'button_yes_hover_bg' => '#5b21b6', 'button_yes_hover_color' => '#ffffff', 'button_no_hover_bg' => '#d1d5db', 'button_no_hover_color' => '#111111', 'animation' => 'fade', 'elementor_template' => 0, 'logo' => '', 'background_image' => '', ]); $options['design']['elementor_template'] = (int) $options['design']['elementor_template']; $options['behaviour'] = wp_parse_args($options['behaviour'] ?? [], [ 'deny_action' => 'redirect_url', 'deny_redirect_page' => 0, 'deny_redirect_url' => 'https://google.com', 'block_message' => __('Access denied.', 'king-addons'), 'reset_on_rule_change' => 0, 'repeat_mode' => 'days', 'consent_checkbox' => 0, ]); $options['behaviour']['deny_action'] = ($options['behaviour']['deny_action'] === 'redirect') ? 'redirect_page' : $options['behaviour']['deny_action']; $options['behaviour']['deny_redirect_page'] = (int) $options['behaviour']['deny_redirect_page']; $options['behaviour']['deny_redirect_url'] = is_string($options['behaviour']['deny_redirect_url']) ? trim($options['behaviour']['deny_redirect_url']) : 'https://google.com'; $options['dob'] = wp_parse_args($options['dob'] ?? [], [ 'format' => 'dmy', 'max_age' => 120, 'error_invalid' => __('Please enter a valid date.', 'king-addons'), 'error_denied' => __('You do not meet the minimum age requirement.', 'king-addons'), ]); $options['dob']['max_age'] = (int) $options['dob']['max_age']; $options['geo'] = wp_parse_args($options['geo'] ?? [], [ 'enabled' => 0, 'default_age' => 18, 'map' => [], ]); $options['geo']['default_age'] = (int) $options['geo']['default_age']; if (is_string($options['geo']['map'])) { $map = []; foreach (preg_split('/\r\n|\r|\n/', $options['geo']['map']) as $line) { $line = trim($line); if ($line === '' || strpos($line, '=') === false) { continue; } [$code, $age] = array_map('trim', explode('=', $line, 2)); if ($code === '') { continue; } $map[strtoupper($code)] = (int) $age; } $options['geo']['map'] = $map; } if (!is_array($options['geo']['map'])) { $options['geo']['map'] = []; } // Theme mode is per-user $theme_mode = get_user_meta(get_current_user_id(), 'king_addons_theme_mode', true); $allowed_theme_modes = ['dark', 'light', 'auto']; if (!in_array($theme_mode, $allowed_theme_modes, true)) { $theme_mode = 'auto'; } ?>