key => hex. */ public static function get_default_colors( $surface ) { $surface = self::normalize_surface( $surface ); if ( 'entrance' === $surface ) { return array( 'bg' => '#0f1115', 'card' => '#171a21', 'text' => '#e9eaee', 'muted' => '#aab0bd', 'button' => '#21d1a7', 'button_text' => '#04231c', 'accent' => '#d63638', ); } // Inline: empty text/button tokens inherit from the theme until the merchant sets them. return array( 'bg' => '#f9fafb', 'card' => '', 'text' => '', 'muted' => '', 'button' => '', 'button_text' => '', 'accent' => '#d63638', ); } /** * @param string $surface entrance|inline. * @return string */ public static function normalize_surface( $surface ) { return ( 'entrance' === $surface ) ? 'entrance' : 'inline'; } /** * Option name for a colour token. * * @param string $surface entrance|inline. * @param string $key One of COLOR_KEYS. * @return string */ public static function color_option_name( $surface, $key ) { $surface = self::normalize_surface( $surface ); $key = sanitize_key( $key ); return 'ageonce_' . $surface . '_color_' . $key; } /** * Resolved colours for a surface (saved or defaults). * Empty string means “unset” (theme styles apply) — used by inline text/button tokens. * * @param string $surface entrance|inline. * @return array */ public static function get_colors( $surface ) { $surface = self::normalize_surface( $surface ); $defaults = self::get_default_colors( $surface ); $out = array(); foreach ( self::COLOR_KEYS as $key ) { $default = isset( $defaults[ $key ] ) ? $defaults[ $key ] : ''; $saved = get_option( self::color_option_name( $surface, $key ), $default ); $hex = self::sanitize_hex_color( $saved ); if ( $hex !== '' ) { $out[ $key ] = $hex; } elseif ( $default !== '' ) { $out[ $key ] = $default; } else { $out[ $key ] = ''; } } return $out; } /** * @param mixed $value Raw colour. * @return string Hex (#rrggbb) or empty. */ public static function sanitize_hex_color( $value ) { if ( function_exists( 'sanitize_hex_color' ) ) { $hex = sanitize_hex_color( (string) $value ); return is_string( $hex ) ? $hex : ''; } $value = trim( (string) $value ); if ( preg_match( '/^#([A-Fa-f0-9]{3}){1,2}$/', $value ) ) { return $value; } return ''; } /** * Logo attachment ID (0 = none / fall back to theme custom logo). * * @return int */ public static function get_logo_id() { return absint( get_option( self::OPTION_LOGO_ID, 0 ) ); } /** * Logo display width in px (0 = natural). * * @return int */ public static function get_logo_width() { return absint( get_option( self::OPTION_LOGO_WIDTH, 0 ) ); } /** * Entrance background image attachment ID (0 = none). * * @return int */ public static function get_bg_image_id() { return absint( get_option( self::OPTION_BG_IMAGE_ID, 0 ) ); } /** * Full-size URL for the entrance background image, or empty. * * @return string */ public static function get_bg_image_url() { $image_id = self::get_bg_image_id(); if ( $image_id <= 0 ) { return ''; } $src = wp_get_attachment_image_url( $image_id, 'full' ); return ( is_string( $src ) && $src !== '' ) ? $src : ''; } /** * Logo image URL for gates. * * @return string */ public static function get_logo_url() { $logo_id = self::get_logo_id(); if ( $logo_id > 0 ) { $src = wp_get_attachment_image_url( $logo_id, 'medium' ); if ( is_string( $src ) && $src !== '' ) { return $src; } } $theme_logo_id = (int) get_theme_mod( 'custom_logo' ); if ( $theme_logo_id > 0 ) { $src = wp_get_attachment_image_url( $theme_logo_id, 'medium' ); if ( is_string( $src ) && $src !== '' ) { return $src; } } return ''; } /** * Optional merchant heading for inline gates. Empty = use translated default at render. * * @return string */ public static function get_inline_heading() { return sanitize_text_field( (string) get_option( self::OPTION_INLINE_HEADING, '' ) ); } /** * Optional merchant message for inline gates. May contain %d for the age. Empty = i18n default. * * @return string */ public static function get_inline_message() { return sanitize_textarea_field( (string) get_option( self::OPTION_INLINE_MESSAGE, '' ) ); } /** * Custom CSS from settings (unslashed, stripped of closing style tags). * * @return string */ public static function get_custom_css() { $css = (string) get_option( self::OPTION_CUSTOM_CSS, '' ); $css = wp_strip_all_tags( $css ); return $css; } /** * Reset appearance options to plugin defaults. * * @param string $scope entrance|inline|all. * @return array{ * scope:string, * logo_id?:int, * logo_width?:int, * bg_image_id?:int, * custom_css?:string, * inline_heading?:string, * inline_message?:string, * entrance?:array, * inline?:array * } */ public static function reset_to_defaults( $scope = 'all' ) { $scope = sanitize_key( (string) $scope ); if ( ! in_array( $scope, array( 'entrance', 'inline', 'all' ), true ) ) { $scope = 'all'; } $result = array( 'scope' => $scope ); if ( 'entrance' === $scope || 'all' === $scope ) { update_option( self::OPTION_LOGO_ID, 0, false ); update_option( self::OPTION_LOGO_WIDTH, 0, false ); update_option( self::OPTION_BG_IMAGE_ID, 0, false ); $entrance = self::get_default_colors( 'entrance' ); foreach ( $entrance as $key => $hex ) { update_option( self::color_option_name( 'entrance', $key ), $hex, false ); } $result['logo_id'] = 0; $result['logo_width'] = 0; $result['bg_image_id'] = 0; $result['entrance'] = $entrance; } if ( 'inline' === $scope || 'all' === $scope ) { update_option( self::OPTION_INLINE_HEADING, '', false ); update_option( self::OPTION_INLINE_MESSAGE, '', false ); $inline = self::get_default_colors( 'inline' ); foreach ( $inline as $key => $hex ) { update_option( self::color_option_name( 'inline', $key ), $hex, false ); } $result['inline_heading'] = ''; $result['inline_message'] = ''; $result['inline'] = $inline; } if ( 'all' === $scope ) { update_option( self::OPTION_CUSTOM_CSS, '', false ); $result['custom_css'] = ''; } return $result; } /** * Build a CSS custom-properties block for a surface. * Skips empty tokens so unset inline colours can inherit from the theme. * * @param string $surface entrance|inline. * @return string */ public static function get_css_variables_block( $surface ) { $surface = self::normalize_surface( $surface ); $colors = self::get_colors( $surface ); $prefix = ( 'entrance' === $surface ) ? '--ageonce-entrance-' : '--ageonce-inline-'; $lines = array(); foreach ( $colors as $key => $hex ) { if ( $hex === '' ) { continue; } $lines[] = $prefix . str_replace( '_', '-', $key ) . ':' . $hex . ';'; } if ( empty( $lines ) ) { return ''; } // Entrance vars on :root so body (page Background) can use them; // .ageonce-gate is the Card/panel and inherits the same tokens. return ':root{' . implode( '', $lines ) . '}'; } /** * Full inline stylesheet: both surfaces + custom CSS. * * @return string */ public static function get_frontend_css() { $css = self::get_css_variables_block( 'entrance' ); $css .= self::get_css_variables_block( 'inline' ); $css .= self::get_default_component_css(); $custom = self::get_custom_css(); if ( $custom !== '' ) { $css .= "\n" . $custom; } return $css; } /** * Map CSS variables onto existing gate class names so defaults keep working * when merchants only change colours. * * @return string */ private static function get_default_component_css() { $css = ' /* Entrance card (body Background is set only in templates/entrance-gate.php). */ .ageonce-gate{background:var(--ageonce-entrance-card,#171a21);color:var(--ageonce-entrance-text,#e9eaee);} .ageonce-gate__card,.ageonce-gate > .ageonce-gate__inner{background:var(--ageonce-entrance-card,#171a21);} .ageonce-gate .ageonce-gate__title,.ageonce-gate h1{color:var(--ageonce-entrance-text,#e9eaee);} .ageonce-gate .ageonce-gate__lead{color:var(--ageonce-entrance-muted,#aab0bd);} .ageonce-gate .ageonce-gate__btn{background:var(--ageonce-entrance-button,#21d1a7);color:var(--ageonce-entrance-button-text,#04231c);} .ageonce-gate .ageonce-gate__sign{border-color:var(--ageonce-entrance-accent,#d63638);color:var(--ageonce-entrance-accent,#d63638);} .ageonce-gate .ageonce-gate__links a{color:var(--ageonce-entrance-muted,#aab0bd);} .ageonce-gate .ageonce-gate__secure,.ageonce-gate .ageonce-gate__secure a{color:var(--ageonce-entrance-muted,#aab0bd);} '; $css .= self::get_inline_component_css(); return $css; } /** * Inline banner colour overrides. Borders stay fixed in stylesheet files. * Text/button rules are emitted only when the merchant set a colour (theme otherwise). * * @return string */ private static function get_inline_component_css() { $c = self::get_colors( 'inline' ); $rules = array(); if ( $c['bg'] !== '' ) { $rules[] = '.ageonce-content-gate{background:var(--ageonce-inline-bg);}'; $rules[] = '.ageonce-gate-container{background:var(--ageonce-inline-bg);}'; } if ( $c['accent'] !== '' ) { $rules[] = '.ageonce-content-gate-sign{border-color:var(--ageonce-inline-accent);color:var(--ageonce-inline-accent);}'; $rules[] = '.ageonce-gate-container{border-top-color:var(--ageonce-inline-accent);}'; } if ( $c['text'] !== '' ) { $rules[] = '.ageonce-content-gate,.ageonce-content-gate-title{color:var(--ageonce-inline-text);}'; $rules[] = '.ageonce-gate-container,.ageonce-gate-title{color:var(--ageonce-inline-text);}'; $rules[] = '.ageonce-gate-footnote{color:var(--ageonce-inline-text);opacity:0.55;}'; } if ( $c['muted'] !== '' ) { $rules[] = '.ageonce-content-gate-lead{color:var(--ageonce-inline-muted);}'; $rules[] = '.ageonce-gate-lead{color:var(--ageonce-inline-muted);}'; } $btn_decls = array(); if ( $c['button'] !== '' ) { $btn_decls[] = 'background:var(--ageonce-inline-button)!important'; $btn_decls[] = 'border-color:var(--ageonce-inline-button)!important'; } if ( $c['button_text'] !== '' ) { $btn_decls[] = 'color:var(--ageonce-inline-button-text)!important'; } if ( ! empty( $btn_decls ) ) { $decl = implode( ';', $btn_decls ); $rules[] = '.ageonce-content-gate .ageonce-gate-btn,.ageonce-content-gate a.button{' . $decl . ';}'; $rules[] = '.ageonce-verify-btn{' . $decl . ';}'; } $rules[] = '.ageonce-gate-container .ageonce-verify-btn.ageonce-verify-btn--full{margin:0 0 8px;}'; // Trust mark — keep tiny even when themes force img { height:auto; max-width:100% }. $rules[] = '.ageonce-secured-with{margin:12px 0 0;padding:0;font-size:11px;line-height:1.4;color:#888;text-align:center;}'; $rules[] = '.ageonce-secured-with__link{display:inline-flex;align-items:center;justify-content:center;gap:6px;color:inherit;text-decoration:none;}'; $rules[] = '.ageonce-secured-with__link:hover{color:#555;}'; $rules[] = '.ageonce-secured-with__brand{display:inline-flex;align-items:center;gap:3px;font-weight:600;}'; $rules[] = '.ageonce-secured-with__logo{display:block!important;height:9px!important;width:auto!important;max-width:42px!important;max-height:9px!important;margin:0!important;padding:0!important;border:0!important;border-radius:0!important;box-shadow:none!important;opacity:0.9;vertical-align:middle;}'; $rules[] = '.ageonce-secured-with__link:hover .ageonce-secured-with__logo{opacity:1;}'; return "\n" . implode( "\n", $rules ) . "\n"; } /** * Print or enqueue frontend appearance CSS. */ public static function enqueue_frontend_css() { $handle = 'ageonce-appearance'; $version = defined( 'AGEONCE_VERIFICATION_VERSION' ) ? AGEONCE_VERIFICATION_VERSION : '1.0.0'; wp_register_style( $handle, false, array(), $version ); wp_enqueue_style( $handle ); wp_add_inline_style( $handle, self::get_frontend_css() ); } }