Make your WordPress site irresistible. Natural SEO attraction with: - robots.txt management - sitemap.xml generation - LLMs.txt support - Google integration (Analytics, Search Console, Tag Manager) - Schema.org structured data - Open Graph / Twitter Card meta tags - AMP support - Visual elements gallery - Built-in backup/restore module Includes build.sh and .distignore for WordPress-installable release ZIPs.
195 lines
10 KiB
PHP
195 lines
10 KiB
PHP
<?php
|
|
/**
|
|
* AI Provider Management
|
|
*/
|
|
|
|
// Prevent direct access
|
|
if (!defined('ABSPATH')) {
|
|
exit;
|
|
}
|
|
|
|
class TigerStyleSEO_AI_Provider {
|
|
|
|
private static $instance = null;
|
|
|
|
public static function instance() {
|
|
if (is_null(self::$instance)) {
|
|
self::$instance = new self();
|
|
}
|
|
return self::$instance;
|
|
}
|
|
|
|
private function __construct() {
|
|
add_action('wp_ajax_tigerstyle_ai_test_key', array($this, 'handle_test_api_key'));
|
|
add_action('wp_ajax_tigerstyle_ai_chat', array($this, 'handle_ai_chat'));
|
|
add_action('admin_post_update_ai_provider_settings', array($this, 'handle_update_settings'));
|
|
}
|
|
|
|
public function render_admin_page() {
|
|
$providers = $this->get_api_providers();
|
|
?>
|
|
<div class="seo-info-box">
|
|
<h3><?php _e('💬 AI Chat Assistant', 'tigerstyle-heat'); ?></h3>
|
|
<p class="description">
|
|
<?php _e('Ask AI questions about SEO, content optimization, or get instant help with your website.', 'tigerstyle-heat'); ?>
|
|
</p>
|
|
|
|
<div id="ai-chat-interface" style="background: #fff; border: 1px solid #ddd; border-radius: 8px; padding: 20px; margin: 20px 0;">
|
|
<div style="display: flex; gap: 10px; align-items: center; margin-bottom: 15px;">
|
|
<select id="ai-chat-provider" style="min-width: 200px;">
|
|
<option value=""><?php _e('Select AI Provider...', 'tigerstyle-heat'); ?></option>
|
|
<?php if (!empty($providers)): ?>
|
|
<?php foreach ($providers as $provider_name => $provider_data): ?>
|
|
<?php if (!empty($provider_data['models'])): ?>
|
|
<?php foreach ($provider_data['models'] as $model_id => $model_data): ?>
|
|
<?php if ($model_data['enabled']): ?>
|
|
<option value="<?php echo esc_attr($provider_name . '|' . $model_id); ?>">
|
|
<?php echo esc_html($provider_name . ' - ' . $model_id); ?>
|
|
</option>
|
|
<?php endif; ?>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</select>
|
|
<button type="button" id="ai-chat-clear" class="button"><?php _e('Clear Chat', 'tigerstyle-heat'); ?></button>
|
|
</div>
|
|
|
|
<div id="ai-chat-messages" style="background: #f9f9f9; border: 1px solid #ddd; border-radius: 5px; padding: 15px; min-height: 200px; max-height: 400px; overflow-y: auto; margin-bottom: 15px;">
|
|
<div class="chat-message system-message" style="color: #666; font-style: italic;">
|
|
<?php _e('💡 Ask me anything about SEO, content optimization, meta tags, or website improvement!', 'tigerstyle-heat'); ?>
|
|
</div>
|
|
</div>
|
|
|
|
<div style="display: flex; gap: 10px;">
|
|
<textarea id="ai-chat-input" placeholder="<?php _e('Ask me anything about SEO...', 'tigerstyle-heat'); ?>" style="flex: 1; min-height: 60px; padding: 10px; border: 1px solid #ddd; border-radius: 5px;" rows="3"></textarea>
|
|
<button type="button" id="ai-chat-send" class="button button-primary" disabled style="align-self: flex-end;"><?php _e('Send', 'tigerstyle-heat'); ?></button>
|
|
</div>
|
|
|
|
<div id="ai-chat-status" style="margin-top: 10px; font-size: 12px; color: #666;"></div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="seo-info-box">
|
|
<h3><?php _e('🔧 AI Provider Configuration', 'tigerstyle-heat'); ?></h3>
|
|
<p class="description">
|
|
<?php _e('Configure OpenAI-compatible API providers to enable AI-powered SEO features like content optimization, meta tag generation, and automated analysis.', 'tigerstyle-heat'); ?>
|
|
</p>
|
|
</div>
|
|
|
|
<!-- Add New Provider Form -->
|
|
<div class="seo-info-box">
|
|
<h4><?php _e('Add New API Provider', 'tigerstyle-heat'); ?></h4>
|
|
<form method="post" action="<?php echo admin_url('admin-post.php'); ?>">
|
|
<input type="hidden" name="action" value="update_ai_provider_settings">
|
|
<input type="hidden" name="ai_action" value="add_provider">
|
|
<?php wp_nonce_field('update_ai_provider_settings', 'ai_provider_nonce'); ?>
|
|
|
|
<table class="form-table">
|
|
<tr>
|
|
<th scope="row"><?php _e('Provider Name', 'tigerstyle-heat'); ?></th>
|
|
<td>
|
|
<input type="text" name="provider_name" class="regular-text" placeholder="<?php _e('e.g., openai-main, anthropic-claude', 'tigerstyle-heat'); ?>" required>
|
|
<p class="description"><?php _e('Unique name to identify this API provider.', 'tigerstyle-heat'); ?></p>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<th scope="row"><?php _e('API Key', 'tigerstyle-heat'); ?></th>
|
|
<td>
|
|
<input type="password" name="api_key" class="regular-text" placeholder="<?php _e('sk-...', 'tigerstyle-heat'); ?>" required>
|
|
<p class="description"><?php _e('API key will be encrypted and stored securely.', 'tigerstyle-heat'); ?></p>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<th scope="row"><?php _e('Base URL', 'tigerstyle-heat'); ?></th>
|
|
<td>
|
|
<input type="url" name="base_url" class="regular-text" value="https://api.openai.com/v1" required>
|
|
<p class="description"><?php _e('API base URL (OpenAI: https://api.openai.com/v1, Azure: https://your-resource.openai.azure.com)', 'tigerstyle-heat'); ?></p>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<th scope="row"><?php _e('Description', 'tigerstyle-heat'); ?></th>
|
|
<td>
|
|
<textarea name="description" class="large-text" rows="3" placeholder="<?php _e('Optional description for this provider...', 'tigerstyle-heat'); ?>"></textarea>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
|
|
<p class="submit">
|
|
<input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e('Add Provider', 'tigerstyle-heat'); ?>">
|
|
</p>
|
|
</form>
|
|
</div>
|
|
|
|
<div class="seo-info-box">
|
|
<h4><?php _e('Usage Examples', 'tigerstyle-heat'); ?></h4>
|
|
<p><?php _e('Once configured, you can use the AI providers in your code:', 'tigerstyle-heat'); ?></p>
|
|
|
|
<pre style="background: #f1f1f1; padding: 15px; border-radius: 5px; overflow-x: auto;"><code><?php echo esc_html('// Get client for a specific provider and model
|
|
$client = tigerstyle_heat()->get_module(\'ai_provider\')->get_client(\'openai-main\', \'gpt-4\');
|
|
|
|
// Generate meta description
|
|
$response = $client->chat_completion([
|
|
\'messages\' => [
|
|
[\'role\' => \'user\', \'content\' => \'Generate an SEO meta description for: \' . $post_title]
|
|
],
|
|
\'max_tokens\' => 160
|
|
]);
|
|
|
|
// Use with any enabled model
|
|
$providers = tigerstyle_heat()->get_module(\'ai_provider\')->get_api_providers();
|
|
foreach ($providers as $name => $config) {
|
|
$enabled_models = tigerstyle_heat()->get_module(\'ai_provider\')->get_enabled_models($name);
|
|
// Use the models...
|
|
}'); ?></code></pre>
|
|
</div>
|
|
|
|
<style>
|
|
.status-success { color: #46b450; font-weight: bold; }
|
|
.status-pending { color: #f56e28; }
|
|
.status-error { color: #dc3232; }
|
|
.provider-card { transition: box-shadow 0.2s; }
|
|
.provider-card:hover { box-shadow: 0 2px 5px rgba(0,0,0,0.1); }
|
|
.toggle-switch { position: relative; display: inline-block; width: 60px; height: 34px; }
|
|
.toggle-switch input { opacity: 0; width: 0; height: 0; }
|
|
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #ccc; transition: .4s; border-radius: 34px; }
|
|
.slider:before { position: absolute; content: ""; height: 26px; width: 26px; left: 4px; bottom: 4px; background-color: white; transition: .4s; border-radius: 50%; }
|
|
input:checked + .slider { background-color: #2196F3; }
|
|
input:checked + .slider:before { transform: translateX(26px); }
|
|
</style>
|
|
|
|
<script>
|
|
jQuery(document).ready(function($) {
|
|
// AI Chat functionality
|
|
$('#ai-chat-send').on('click', function() {
|
|
// Implementation for sending AI chat messages
|
|
});
|
|
|
|
$('#ai-chat-clear').on('click', function() {
|
|
$('#ai-chat-messages').html('<div class="chat-message system-message" style="color: #666; font-style: italic;"><?php _e('💡 Ask me anything about SEO, content optimization, meta tags, or website improvement!', 'tigerstyle-heat'); ?></div>');
|
|
});
|
|
});
|
|
</script>
|
|
<?php
|
|
}
|
|
|
|
public function get_api_providers() {
|
|
return get_option('tigerstyle_heat_ai_providers', array());
|
|
}
|
|
|
|
public function handle_test_api_key() {
|
|
// AJAX handler for testing API keys
|
|
wp_die();
|
|
}
|
|
|
|
public function handle_ai_chat() {
|
|
// AJAX handler for AI chat
|
|
wp_die();
|
|
}
|
|
|
|
public function handle_update_settings() {
|
|
// Handler for updating AI provider settings
|
|
wp_redirect(admin_url('admin.php?page=tigerstyle-heat#ai-provider-tab'));
|
|
exit;
|
|
}
|
|
}
|