'1', 'heading' => __( 'Age Verification', 'ab-age-gate' ), 'description' => __( 'This website requires you to verify your age before entering. Please confirm the statement below to proceed.', 'ab-age-gate' ), 'button_text' => __( 'Submit & Enter', 'ab-age-gate' ), 'accept_all_text' => __( 'Accept All', 'ab-age-gate' ), 'button_color' => '#3FCB08', 'accept_all_color' => '#3FCB08', 'accent_color' => '#3FCB08', 'top_disclaimer_icon' => '⚠️', 'top_disclaimer_title' => __( 'Research Use and Compliance', 'ab-age-gate' ), 'top_disclaimer_text' => __( 'Please review and acknowledge before accessing the website.', 'ab-age-gate' ), 'top_disclaimer_color' => '#f97316', 'bg_color' => '#22262A', 'leave_text' => __( 'Decline & Exit', 'ab-age-gate' ), 'leave_url' => 'https://www.google.com', 'disclaimer_text' => __( 'By proceeding you affirm the statements above are true. This site uses cookies to remember your verification status.', 'ab-age-gate' ), 'disclaimer_link_text' => __( 'Privacy Policy', 'ab-age-gate' ), 'disclaimer_link_url' => '', 'cookie_days' => '1', 'bypass_logged_in' => '0', 'logo_url' => '', 'logo_height' => '60', 'logo_align' => 'center', ]; } function ab_age_gate_get( $key ) { $defaults = ab_age_gate_defaults(); $val = get_option( 'ab_age_gate_' . $key, $defaults[ $key ] ?? '' ); return $val; } function ab_age_gate_default_checkboxes() { return [ [ 'label' => __( 'I am at least 21 years of age.', 'ab-age-gate' ), ], [ 'label' => __( 'I agree to the Terms of Service and Privacy Policy.', 'ab-age-gate' ), ], ]; } function ab_age_gate_allowed_checkbox_tags() { return [ 'strong' => [], 'em' => [], 'b' => [], 'a' => [ 'href' => [], 'target' => [], 'rel' => [], ], ]; } function ab_age_gate_migrate_checkboxes() { $checkboxes = []; $legacy = [ get_option( 'ab_age_gate_checkbox1_label', '' ), get_option( 'ab_age_gate_checkbox2_label', '' ), ]; foreach ( $legacy as $label ) { if ( is_string( $label ) && trim( $label ) !== '' ) { $checkboxes[] = [ 'label' => $label ]; } } return ! empty( $checkboxes ) ? $checkboxes : ab_age_gate_default_checkboxes(); } function ab_age_gate_get_checkboxes() { $stored = get_option( 'ab_age_gate_checkboxes', false ); if ( is_array( $stored ) && ! empty( $stored ) ) { return $stored; } $checkboxes = ab_age_gate_migrate_checkboxes(); update_option( 'ab_age_gate_checkboxes', $checkboxes ); return $checkboxes; } function ab_age_gate_sanitize_checkboxes( $input ) { if ( ! is_array( $input ) ) { return ab_age_gate_default_checkboxes(); } $sanitized = []; $allowed_tags = ab_age_gate_allowed_checkbox_tags(); foreach ( $input as $row ) { if ( ! is_array( $row ) || ! isset( $row['label'] ) ) { continue; } $label = trim( wp_kses( $row['label'], $allowed_tags ) ); if ( $label === '' ) { continue; } $sanitized[] = [ 'label' => $label ]; } return ! empty( $sanitized ) ? $sanitized : ab_age_gate_default_checkboxes(); } /* --------------------------------------------------------------- Activation: set defaults --------------------------------------------------------------- */ register_activation_hook( __FILE__, function() { foreach ( ab_age_gate_defaults() as $key => $val ) { if ( get_option( 'ab_age_gate_' . $key ) === false ) { update_option( 'ab_age_gate_' . $key, $val ); } } if ( get_option( 'ab_age_gate_checkboxes' ) === false ) { update_option( 'ab_age_gate_checkboxes', ab_age_gate_migrate_checkboxes() ); } }); /* --------------------------------------------------------------- Load admin --------------------------------------------------------------- */ if ( is_admin() ) { require_once AB_AGE_GATE_PATH . 'admin/settings-page.php'; } /* --------------------------------------------------------------- Frontend: Enqueue assets --------------------------------------------------------------- */ add_action( 'wp_enqueue_scripts', 'ab_age_gate_enqueue_assets' ); function ab_age_gate_enqueue_assets() { // Kill switch if ( ab_age_gate_get('enabled') !== '1' ) return; // Optionally skip for logged-in users if ( ab_age_gate_get('bypass_logged_in') === '1' && is_user_logged_in() ) return; // Check cookie $cookie_name = 'ab_age_gate_verified'; if ( isset( $_COOKIE[ $cookie_name ] ) && $_COOKIE[ $cookie_name ] === '1' ) return; // Enqueue style in head wp_enqueue_style( 'ab-age-gate-style', AB_AGE_GATE_URL . 'assets/css/overlay.css', [], AB_AGE_GATE_VERSION ); // Enqueue script in footer wp_enqueue_script( 'ab-age-gate-script', AB_AGE_GATE_URL . 'assets/js/overlay.js', [], AB_AGE_GATE_VERSION, true ); $cookie_val = ab_age_gate_get('cookie_days'); $cookie_days = ( $cookie_val === '' ) ? 1 : absint( $cookie_val ); $cookie_secs = $cookie_days * 86400; $accent = esc_attr( ab_age_gate_get('accent_color') ); $btn_color = esc_attr( ab_age_gate_get('button_color') ); $accept_btn_color = esc_attr( ab_age_gate_get('accept_all_color') ); $top_disclaimer_color = esc_attr( ab_age_gate_get('top_disclaimer_color') ); $bg_color = esc_attr( ab_age_gate_get('bg_color') ); $custom_css = " :root { --ab-age-gate-accent: {$accent}; --ab-age-gate-btn: {$btn_color}; --ab-age-gate-accept: {$accept_btn_color}; --ab-age-gate-disclaimer-color: {$top_disclaimer_color}; --ab-age-gate-bg: {$bg_color}; } "; wp_add_inline_style( 'ab-age-gate-style', $custom_css ); wp_localize_script( 'ab-age-gate-script', 'abAgeGateCfg', [ 'cookieName' => $cookie_name, 'cookieSecs' => $cookie_secs, 'accentColor'=> $accent, 'btnColor' => $btn_color, ]); } /* --------------------------------------------------------------- Frontend: show overlay --------------------------------------------------------------- */ add_action( 'wp_footer', 'ab_age_gate_render_overlay' ); function ab_age_gate_render_overlay() { // Kill switch if ( ab_age_gate_get('enabled') !== '1' ) return; // Optionally skip for logged-in users if ( ab_age_gate_get('bypass_logged_in') === '1' && is_user_logged_in() ) return; // Check cookie $cookie_name = 'ab_age_gate_verified'; if ( isset( $_COOKIE[ $cookie_name ] ) && $_COOKIE[ $cookie_name ] === '1' ) return; $top_disclaimer_icon = esc_attr( ab_age_gate_get('top_disclaimer_icon') ); $top_disclaimer_title = esc_attr( ab_age_gate_get('top_disclaimer_title') ); $top_disclaimer_text = esc_attr( ab_age_gate_get('top_disclaimer_text') ); // Disclaimer link config $disc_link_url = ab_age_gate_get('disclaimer_link_url'); $disc_link_text = ab_age_gate_get('disclaimer_link_text'); // Leave site link $leave_text = ab_age_gate_get('leave_text'); $leave_url = ab_age_gate_get('leave_url'); ?>