'empty' ]; if ( ! empty( $chk['error'] ) ) { echo '

Site Key Error: ' . esc_html( (string)$chk['error'] ) . '

'; unset( $opt['site_token'] ); } else { $opt['site_token'] = $new; echo '

Site Key saved.

'; } update_option( 'aatb_settings', $opt ); $token = $opt['site_token'] ?? ''; $tab = 'site-key'; } /* 2) Alt-Text settings (model + language + custom prompt) */ if ( $_POST['aatb_action'] === 'aatb_save_alt_settings' ) { $allowed = ['gpt-4o-mini','gpt-4o','gpt-4.1']; $chosen = sanitize_text_field( $_POST['model_choice'] ?? 'gpt-4o-mini' ); $opt['model_choice'] = in_array( $chosen, $allowed, true ) ? $chosen : 'gpt-4o-mini'; $sel = sanitize_text_field( $_POST['lang_choice'] ?? 'en' ); $opt['lang_choice'] = ( $sel === 'other' ) ? sanitize_text_field( $_POST['lang_custom'] ?? 'en' ) : $sel; // Keep custom prompt size reasonable to avoid provider errors on extreme inputs $cp = sanitize_textarea_field( $_POST['custom_prompt'] ?? '' ); if ( mb_strlen( $cp ) > 1500 ) { $cp = mb_substr( $cp, 0, 1500 ); } $opt['custom_prompt'] = $cp; update_option( 'aatb_settings', $opt ); $model = $opt['model_choice']; $lang = $opt['lang_choice']; $tab = 'alt-settings'; echo '

Settings saved.

'; } } /* ───────────── TOKEN / USAGE NORMALIZATION ───────────── */ $usage=$limit=$remain=$site_usage=null; $membership='free'; $allowed_models_ui = ['gpt-4o-mini','gpt-4o','gpt-4.1']; // default UI allow list if ( $token ) { $st = aatb_check_token_status( $token ); if ( empty( $st['error'] ) ) { $site_usage = (int)($st['site_usage'] ?? 0); $limit = (int)( $st['plan_limit_total'] ?? $st['plan_limit'] ?? $st['token_limit'] ?? 0 ); $usage_total = null; foreach ( ['usage_total','all_usage','total_usage','token_usage','usage'] as $k ) { if ( isset($st[$k]) ) { $usage_total = (int)$st[$k]; break; } } if ( $usage_total === null ) { $usage_total = max(0, (int)$site_usage); } $remain = aatb_status_remaining( $st ); $usage = (int)$usage_total; $membership = strtolower( trim( $st['membership'] ?? 'free' ) ); // If backend explicitly returns allowed models, respect it visually if ( ! empty( $st['allowed_models'] ) && is_array( $st['allowed_models'] ) ) { $allowed_models_ui = array_values( array_intersect( $allowed_models_ui, $st['allowed_models'] ) ); if ( empty($allowed_models_ui) ) { $allowed_models_ui = ['gpt-4o-mini']; } } } } // Canonical models $canonical = ['gpt-4o-mini','gpt-4o','gpt-4.1']; // Membership-based gating $gate = [ 'free' => ['gpt-4o-mini'], 'starter' => ['gpt-4o-mini','gpt-4.1'], 'creator' => ['gpt-4o-mini','gpt-4.1','gpt-4o'], 'expert' => ['gpt-4o-mini','gpt-4.1','gpt-4o'], ]; // Prefer membership rules; otherwise fall back to backend's allowed models if ( isset($gate[$membership]) ) { $allowed_models_ui = array_values( array_intersect($canonical, $gate[$membership]) ); } elseif ( !empty($st['allowed_models']) && is_array($st['allowed_models']) ) { $allowed_models_ui = array_values( array_intersect($canonical, $st['allowed_models']) ); } else { $allowed_models_ui = ['gpt-4o-mini']; } // Ensure selected model remains valid if ( ! in_array($model, $allowed_models_ui, true) ) { $model = 'gpt-4o-mini'; $opt['model_choice'] = $model; update_option('aatb_settings', $opt); } /* Keep selection valid (defensive) */ if ( ! in_array( $model, $allowed_models_ui, true ) ) { $model = 'gpt-4o-mini'; $opt['model_choice'] = $model; update_option( 'aatb_settings', $opt ); } $btn_label = ( $membership === 'free' ) ? 'GET PREMIUM NOW' : 'BUY TOKENS'; $btn_url = ( $membership === 'free' ) ? 'https://rankpilotai.com/ai-alt-text-builder-pricing/' : 'https://rankpilotai.com/tokens-1/?plugin=ai-alt-text-builder'; ?>

Enter your Site Key below to get started.

Generate your Site Key on RankPilotAI.com

Your Active Site Key

Usage Overview

This Site Usage Plan Limit Remaining Progress

Update / Change Site Key

Select “Other / Custom” and type the language exactly as you’d like it.

Optional. Add brand or style guidance. Your note is appended to the built-in instructions and takes priority over general rules; the 125-character limit always applies. Leave blank to use defaults.

← enter a Site Key first