[ 'gpt-4-turbo' ], 2 => [ 'gpt-4-turbo', 'gpt-4.1' ], 3 => [ 'gpt-4-turbo', 'gpt-4.1', 'gpt-4o' ], 4 => [ 'gpt-4-turbo', 'gpt-4.1', 'gpt-4o' ], // Ultra-Premium (o3) removed ][$lvl] ?? [ 'gpt-4-turbo' ]; } /** * Render the settings page (two tabs: Site Key & SEO). * * @return void */ function aissp_render_settings_page() { /* Admin cache guard */ if ( function_exists('nocache_headers') ) { nocache_headers(); } $__aissp_build = 'aissp-settings-2025-09-02-GLOBAL-REMAINING-v3'; /* ---------------- Load current options ---------------- */ $opts = get_option( 'aissp_settings', [] ); $token = $opts['site_token'] ?? ''; $model = $opts['model_choice'] ?? 'gpt-4-turbo'; $tab = ( isset($_GET['tab']) && $_GET['tab']==='seo-settings' ) ? 'seo-settings' : 'site-key'; /* ===================================================== 1) FORM POSTS ===================================================== */ if ( isset( $_POST['aissp_action'] ) ) { if ( ! current_user_can( 'manage_options' ) ) { return; } $action = sanitize_key( wp_unslash( $_POST['aissp_action'] ) ); if ( $action === 'aissp_save_site_key' ) { check_admin_referer( 'aissp_save_site_key' ); $newKey = sanitize_text_field( wp_unslash( $_POST['site_token'] ?? '' ) ); $test = aissp_check_token_status( $newKey ); if ( ! empty( $test['error'] ) ) { echo '

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

'; unset( $opts['site_token'] ); } else { $opts['site_token'] = $newKey; echo '

Site Key saved.

'; } update_option( 'aissp_settings', $opts ); $token = $opts['site_token'] ?? ''; $tab = 'site-key'; } elseif ( $action === 'aissp_save_seo_settings' ) { check_admin_referer( 'aissp_save_seo_settings' ); $mc = sanitize_text_field( wp_unslash( $_POST['model_choice'] ?? 'gpt-4-turbo' ) ); $opts['model_choice'] = $mc; $opts['custom_prompt'] = sanitize_textarea_field( wp_unslash( $_POST['custom_prompt'] ?? '' ) ); $opts['auto_slug'] = ( isset( $_POST['auto_slug'] ) && 'yes' === wp_unslash( $_POST['auto_slug'] ) ) ? 'yes' : 'no'; foreach ( [ 'post','page','landing_page','category','post_tag','product_cat','product_tag' ] as $k ) { $raw = isset( $_POST["index_$k"] ) ? wp_unslash( $_POST["index_$k"] ) : 'no'; $opts["index_$k"] = in_array( $raw, [ 'yes','no' ], true ) ? $raw : 'no'; } update_option( 'aissp_settings', $opts ); $model = $mc; $tab = 'seo-settings'; echo '

Settings saved.

'; } } /* ===================================================== 2) TOKEN / MEMBERSHIP / MODEL GATES (GLOBAL NORMALIZE) ===================================================== */ $usage = $limit = $remain = $site_usage = null; // $usage = GLOBAL usage (all sites) $membership='free'; $allowed =[ 'gpt-4-turbo' ]; if ( $token ){ $st = aissp_check_token_status( $token ); // If the API didn't provide 'remaining_total', derive it from balances. if ( ! isset( $st['remaining_total'] ) ) { $fb = (int)($st['free_balance'] ?? 0); $pr = (int)($st['plan_remaining'] ?? 0); $pb = (int)($st['pack_balance'] ?? 0); if ( ($fb + $pr + $pb) > 0 ) { $st['remaining_total'] = $fb + $pr + $pb; } } if ( empty( $st['error'] ) ){ /* ---- Read raw fields (tolerate different API versions) ---- */ $site_usage = (int) ( $st['site_usage'] ?? 0 ); $limit = (int) ( $st['plan_limit_total'] ?? $st['plan_limit'] ?? $st['token_limit'] ?? 0 ); /* Global usage (all sites) – try common keys */ $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; } } /* Global remaining (all sites) – try common keys */ $remain_total = null; foreach ( ['remaining_total','remaining_all','global_remaining'] as $k ){ if ( isset($st[$k]) ) { $remain_total = (int)$st[$k]; break; } } /* Some APIs only provide 'remaining' which may already be global */ if ( $remain_total === null && isset($st['remaining']) ) { $remain_total = (int)$st['remaining']; } /* — Derivations — */ // 1) If usage_total is missing but limit & remain_total exist → usage_total = limit - remain_total if ( $usage_total === null && $limit > 0 && $remain_total !== null ) { $usage_total = max( 0, $limit - $remain_total ); } // 2) If remain_total is missing but limit & usage_total exist → remain_total = limit - usage_total if ( $remain_total === null && $limit > 0 && $usage_total !== null ) { $remain_total = max( 0, $limit - $usage_total ); } // 3) Still missing usage_total → fall back to site_usage (API/UI can differ) if ( $usage_total === null ) { $usage_total = max( 0, (int)$site_usage ); } $usage = (int) $usage_total; // GLOBAL usage $remain = aissp_status_remaining( $st ); // GLOBAL remaining (helper) $membership = strtolower( trim( $st['membership'] ?? 'free' ) ); $allowed = $st['allowed_models'] ?? [ 'gpt-4-turbo' ]; } } /* ➊ Plan by token balance — 0–25 ⇒ Free, 26+ ⇒ Starter */ $user_id = get_current_user_id(); $plan_tokens = (int) get_user_meta( $user_id, 'ai-snippet-seo-pro_membership_tokens', true ); if ( $plan_tokens > 25 && $membership === 'free' ) { $membership = 'starter'; $allowed = aissp_default_allowed_matrix( 2 ); // Starter (lvl 2) → Turbo + 4.1 } /* ---------- PMPro fallback (when API data is missing) ---------- */ if ( function_exists('pmpro_getMembershipLevelForUser') ){ $lvlObj = pmpro_getMembershipLevelForUser(); $lvlId = $lvlObj ? (int)$lvlObj->id : 1; if ( $membership === 'free' ){ $allowed = aissp_default_allowed_matrix( $lvlId ); } if ( $lvlId === 4 ) $membership = 'expert'; elseif ( $lvlId === 3 ) $membership = 'creator'; elseif ( $lvlId === 2 ) $membership = 'starter'; } /* ---------- Ensure the currently selected model is allowed ---------- */ if ( ! in_array( $model, $allowed, true ) ){ $model = 'gpt-4-turbo'; $opts['model_choice'] = $model; update_option( 'aissp_settings', $opts ); } /* ❶ Limit-based correction — apply only when $limit is known */ if ( $limit !== null ) { if ( $limit <= 25 ) { $membership = 'free'; $allowed = aissp_default_allowed_matrix( 1 ); // Turbo } else { if ( $membership === 'free' ) { $membership = 'starter'; $allowed = aissp_default_allowed_matrix( 2 ); // Turbo + 4.1 } } } /* ---------- Get Started / Buy Tokens button ---------- */ if ( $membership === 'free' ){ $token_btn_label = 'GET STARTED'; $token_btn_url = 'https://rankpilotai.com/ai-snippet-seo-pro-pricing/'; }else{ $token_btn_label = 'BUY TOKENS'; $token_btn_url = 'https://rankpilotai.com/tokens/?plugin=ai-snippet-seo-pro'; } /* ---------- Default indexing matrix ---------- */ $def = [ 'post'=>'yes','page'=>'yes','landing_page'=>'yes', 'category'=>'yes','post_tag'=>'no','product_cat'=>'yes','product_tag'=>'no' ]; ?>

RankPilotAI – Site Key Management

Enter your Site Key below to get started.

Generate your Site Key from your account at RankPilotAI.com

Your Active Site Key

Usage Overview

This Site Usage Plan Limit Remaining Progress

Update / Change Site Key

SEO Snippet Settings

'Post','page'=>'Page','landing_page'=>'Landing Page', 'category'=>'Category','post_tag'=>'Post Tag', 'product_cat'=>'Product Category','product_tag'=>'Product Tag']; foreach($labels as $k=>$lab): $val=$opts["index_$k"]??$def[$k];?>

Unavailable options appear greyed-out – upgrade your plan to unlock them.

We already apply an internal prompt that meets all SEO criteria. Add tone or extra instructions here if you want the AI to include them on top of ours.

Index?

Default OFF. When enabled, the AI-generated slug will overwrite the current one.
WordPress instantly creates a 301 from the old URL (_wp_old_slug_ meta).

← enter a Site Key first