0, 'status' => 'pending'); } public static function begin_login() { update_user_meta(get_current_user_id(), self::key(), array('step' => 0, 'status' => 'pending', 'show_once' => true)); } public static function show() { if (!current_user_can('manage_options') || !get_option('seoai_site_token', '')) return false; $state = self::state(); $automatic = !empty($state['show_once']); if ($automatic) { // Consume the welcome prompt once; ordinary Overview visits stay on the dashboard. $state['show_once'] = false; update_user_meta(get_current_user_id(), self::key(), $state); } return $automatic || (isset($_GET['welcome']) && $_GET['welcome'] === '1'); } public static function url($step = null) { $url = admin_url('admin.php?page=seo-ai-connector&welcome=1'); return $step === null ? $url : add_query_arg('step', $step, $url); } public static function handle() { if (!isset($_POST['ai4ranks_welcome_action'])) return; if (!current_user_can('manage_options') || !get_option('seoai_site_token', '')) wp_die('Please connect an administrator account first.', '', array('response' => 403)); if (!isset($_REQUEST['_wpnonce']) || !is_string($_REQUEST['_wpnonce'])) wp_die('Invalid security token.', '', array('response' => 403)); check_admin_referer('ai4ranks_welcome'); $action = is_string($_POST['ai4ranks_welcome_action']) ? sanitize_key(wp_unslash($_POST['ai4ranks_welcome_action'])) : ''; if (!in_array($action, array('next', 'skip', 'finish'), true)) wp_die('Invalid setup action.'); $step = isset($_POST['welcome_step']) && is_string($_POST['welcome_step']) ? filter_var(wp_unslash($_POST['welcome_step']), FILTER_VALIDATE_INT, array('options' => array('min_range' => 0, 'max_range' => 4))) : false; if ($step === false || ($action === 'finish' && $step !== 4)) wp_die('Invalid setup step.'); if ($action === 'next' && $step === 2) { if (!isset($_POST['welcome_titles']) || !is_array($_POST['welcome_titles'])) wp_die('Invalid SEO settings.'); $fields = array( 'post_title_template' => isset($_POST['welcome_titles']['post_title_template']) && is_string($_POST['welcome_titles']['post_title_template']) ? sanitize_text_field(wp_unslash($_POST['welcome_titles']['post_title_template'])) : '', 'post_description_template' => isset($_POST['welcome_titles']['post_description_template']) && is_string($_POST['welcome_titles']['post_description_template']) ? sanitize_textarea_field(wp_unslash($_POST['welcome_titles']['post_description_template'])) : '', 'separator' => isset($_POST['welcome_titles']['separator']) && is_string($_POST['welcome_titles']['separator']) ? sanitize_text_field(wp_unslash($_POST['welcome_titles']['separator'])) : '', ); $settings = SEO_AI_Connector::get_instance()->sanitize_titles_settings($fields); update_option('ai4ranks_titles_settings', $settings); } $status = $action === 'skip' ? 'skipped' : ($action === 'finish' ? 'complete' : 'pending'); $next = min(4, $step + 1); update_user_meta(get_current_user_id(), self::key(), array('status' => $status, 'step' => $next)); wp_safe_redirect($status === 'pending' ? self::url($next) : admin_url('admin.php?page=seo-ai-connector')); exit; } public static function render() { $state = self::state(); $saved_step = isset($state['step']) && (is_int($state['step']) || is_string($state['step'])) ? filter_var($state['step'], FILTER_VALIDATE_INT, array('options' => array('min_range' => 0, 'max_range' => 4))) : false; // Step links only select a view. Saving progress and settings requires the verified POST above. $requested_step = isset($_GET['step']) && is_string($_GET['step']) ? filter_var(wp_unslash($_GET['step']), FILTER_VALIDATE_INT, array('options' => array('min_range' => 0, 'max_range' => 4))) : false; $step = $requested_step !== false ? $requested_step : ($saved_step !== false ? $saved_step : 0); $labels = array('Welcome', 'Your website', 'SEO essentials', 'Your workflow', 'Ready to begin'); $settings = wp_parse_args((array) get_option('ai4ranks_titles_settings', array()), array('post_title_template' => '{{post.title}} {{separator}} {{site.title}}', 'post_description_template' => '{{post.excerpt}}', 'separator' => '–')); $plugin = SEO_AI_Connector::get_instance(); $owns = $plugin->output_ownership() === 'ai4ranks_primary'; ?>
A GOOD START FOR YOUR WEBSITE
A few focused steps to help you get started with your connected website.
STEP OF 5