' . esc_html__( 'This tool will soon analyze your post and suggest AI-powered updates for outdated content, keywords, and meta descriptions.', 'ai-seo-tools' ) . '

'; echo ''; $this->display_suggestions_placeholder(); } /** * Displays a placeholder for AI suggestions in the metabox. * * @return void */ private function display_suggestions_placeholder(): void { echo '
'; echo '' . esc_html__('AI Suggestions:', 'ai-seo-tools') . ''; echo ''; echo ''; echo '
'; } /** * Handles AJAX request for content analysis and suggestions. * * Summary: Calls OpenAI API with the post content and returns AI-powered suggestions for updated content, meta, and keywords. * * @return void */ public function handle_ajax_content_refresh_analyze(): void { check_ajax_referer( 'ai_seo_content_refresh_nonce', 'nonce' ); if ( ! current_user_can( 'edit_posts' ) ) { wp_send_json_error( array( 'message' => esc_html__( 'Permission denied.', 'ai-seo-tools' ) ), 403 ); } $post_id = isset($_POST['post_id']) ? intval($_POST['post_id']) : 0; $post = get_post($post_id); if (!$post) { wp_send_json_error( array( 'message' => esc_html__( 'Invalid post.', 'ai-seo-tools' ) ), 400 ); } $options = get_option( $this->option_name ); $api_key = $options['openai_api_key'] ?? ''; $model = $options['openai_model'] ?? 'gpt-4o'; $max_tokens = isset($options['content_refresh_max_tokens']) ? max(500, intval($options['content_refresh_max_tokens'])) : 10000; $strength = isset($options['content_refresh_rewrite_strength']) ? $options['content_refresh_rewrite_strength'] : 'maximal'; if ( empty( $api_key ) ) { wp_send_json_error( array( 'message' => esc_html__( 'OpenAI API key is missing.', 'ai-seo-tools' ) ), 400 ); } $content = $post->post_content; if ($strength === 'minimal') { $prompt = "You are an expert SEO content editor. Rewrite only outdated or inaccurate sections of the following blog post. Keep the rest of the text unchanged. Respond ONLY in valid JSON with this field: {\"updated_content\": \"...\"}. Do not include any explanation or text outside the JSON.\n\nHere is the post content:\n" . $content; } elseif ($strength === 'medium') { $prompt = "You are an expert SEO content editor. Paraphrase and improve clarity throughout the following blog post, but keep the original style and structure. Update any outdated information. Respond ONLY in valid JSON with this field: {\"updated_content\": \"...\"}. Do not include any explanation or text outside the JSON.\n\nHere is the post content:\n" . $content; } else { // maximal $prompt = "You are an expert SEO content editor. Rewrite the entire blog post to make it more engaging, modern, and unique. Paraphrase and reword as much as possible, improve clarity, and update any outdated information. Use dynamic, up-to-date language and avoid copying sentences verbatim. Make the text feel freshly written for 2024. Respond ONLY in valid JSON with this field: {\"updated_content\": \"...\"}. Do not include any explanation or text outside the JSON.\n\nHere is the post content:\n" . $content . "\n\n...Return the full, improved post content as HTML (use

,

,