prompts_option, []); // If no prompts exist, initialize with defaults if (empty($prompts)) { $this->reset_to_defaults(); } } public function get_prompts() { return get_option($this->prompts_option, []); } public function get_prompt($key) { $prompts = $this->get_prompts(); return $prompts[$key] ?? null; } public function save_prompt($key, $data) { $prompts = $this->get_prompts(); $prompts[$key] = [ 'name' => sanitize_text_field($data['name']), 'prompt' => wp_kses_post($data['prompt']), 'type' => sanitize_text_field($data['type']), 'created' => $data['created'] ?? current_time('mysql'), 'updated' => current_time('mysql') ]; return update_option($this->prompts_option, $prompts); } public function delete_prompt($key) { $prompts = $this->get_prompts(); unset($prompts[$key]); return update_option($this->prompts_option, $prompts); } public function reset_to_defaults() { $default_prompts = [ 'content_rewrite' => [ 'name' => 'Content Rewriter', 'prompt' => 'Rewrite the following article to make it 100% unique, keeping all factual details correct. Improve clarity, flow, and readability. Format exactly as follows: Title: [New unique SEO-friendly title] Content: [Full rewritten article body] ===ORIGINAL ARTICLE=== Title: "{title}" Content: {content}', 'type' => 'content', 'created' => current_time('mysql') ], 'title_generator' => [ 'name' => 'Title Generator', 'prompt' => 'Create a compelling, unique, SEO-friendly headline for this article. Make it short (max 60 characters), emotionally engaging, and relevant to the topic. Respond only with the headline text. Original title: "{title}" Article content: "{content}"', 'type' => 'title', 'created' => current_time('mysql') ], 'tags_generator' => [ 'name' => 'Tags Generator', 'prompt' => 'Generate 1-3 short, relevant SEO tags for this article. They must be lowercase, comma-separated, and without hashtags. Title: {title} Content: {content}', 'type' => 'tags', 'created' => current_time('mysql') ], 'seo_description' => [ 'name' => 'SEO Description', 'prompt' => 'Write a compelling meta description for this article in 150-160 characters. It should be natural, informative, and encourage the reader to click. Article content: {content}', 'type' => 'seo', 'created' => current_time('mysql') ], 'image_prompt' => [ 'name' => 'Image Generator', 'prompt' => 'Create a modern, eye-catching news illustration for this headline: "{title}". Style: professional, clean, and suitable for a news website. Use balanced composition, neutral background, high contrast, and sharp details.', 'type' => 'image', 'created' => current_time('mysql') ] ]; return update_option($this->prompts_option, $default_prompts); } public function process_prompt($prompt_key, $variables = []) { $prompt_data = $this->get_prompt($prompt_key); if (!$prompt_data) return ''; $prompt = $prompt_data['prompt']; foreach ($variables as $key => $value) { $prompt = str_replace('{' . $key . '}', $value, $prompt); } return $prompt; } public function get_available_variables($type) { $variables = [ 'content' => ['title', 'content', 'url', 'categories'], 'title' => ['title', 'content', 'categories'], 'tags' => ['title', 'content'], 'seo' => ['title', 'content'], 'image' => ['title', 'content'] ]; return $variables[$type] ?? []; } public function ajax_save_prompt() { if (!current_user_can('manage_options')) { wp_die(esc_html__('Insufficient permissions.', 'ai-rss-rewriter')); } check_ajax_referer('airsrefe_ajax', 'nonce'); $key = sanitize_key($_POST['key'] ?? ''); $name = sanitize_text_field(wp_unslash($_POST['name'] ?? '')); $prompt = wp_kses_post(wp_unslash($_POST['prompt'] ?? '')); $type = sanitize_text_field(wp_unslash($_POST['type'] ?? '')); if (empty($key) || empty($name) || empty($prompt) || empty($type)) { wp_send_json_error('All fields are required'); } if ($this->save_prompt($key, compact('name', 'prompt', 'type'))) { airsrefe_append_log(sprintf('Prompt saved: %s', $name)); wp_send_json_success(['message' => 'Prompt saved successfully']); } else { wp_send_json_error('Failed to save prompt'); } } public function ajax_delete_prompt() { if (!current_user_can('manage_options')) { wp_die(esc_html__('Insufficient permissions.', 'ai-rss-rewriter')); } check_ajax_referer('airsrefe_ajax', 'nonce'); $key = sanitize_key($_POST['key'] ?? ''); if (empty($key)) { wp_send_json_error('Prompt key is required'); } if ($this->delete_prompt($key)) { airsrefe_append_log(sprintf('Prompt deleted: %s', $key)); wp_send_json_success(['message' => 'Prompt deleted successfully']); } else { wp_send_json_error('Failed to delete prompt'); } } public function ajax_reset_prompts() { if (!current_user_can('manage_options')) { wp_die(esc_html__('Insufficient permissions.', 'ai-rss-rewriter')); } check_ajax_referer('airsrefe_ajax', 'nonce'); if ($this->reset_to_defaults()) { airsrefe_append_log('Prompts reset to defaults'); wp_send_json_success(['message' => 'Prompts reset successfully']); } else { wp_send_json_error('Failed to reset prompts'); } } public function render_prompts_tab() { $prompts = $this->get_prompts(); $prompt_types = [ 'content' => 'Content Rewriting', 'title' => 'Title Generation', 'tags' => 'Tags Generation', 'seo' => 'SEO Description', 'image' => 'Image Generation' ]; ?>

AI

$prompt): ?>

150) echo '...'; ?>
get_prompt($key); } function airsrefe_process_prompt($key, $variables = []) { global $airsrefe_prompts_manager; return $airsrefe_prompts_manager->process_prompt($key, $variables); } add_action('wp_ajax_airsrefe_get_prompt', 'airsrefe_ajax_get_prompt'); function airsrefe_ajax_get_prompt() { if (!current_user_can('manage_options')) { wp_die(esc_html__('Insufficient permissions.', 'ai-rss-rewriter')); } check_ajax_referer('airsrefe_ajax', 'nonce'); $key = sanitize_key($_POST['key'] ?? ''); if (empty($key)) { wp_send_json_error('Prompt key is required'); } $prompt = airsrefe_get_prompt($key); if ($prompt) { wp_send_json_success($prompt); } else { wp_send_json_error('Prompt not found'); } } // Hook to initialize prompts on plugin activation // Note: This hook should be registered in the main plugin file, not here // The function is kept for backward compatibility function airsrefe_initialize_default_prompts() { global $airsrefe_prompts_manager; if ($airsrefe_prompts_manager) { $airsrefe_prompts_manager->reset_to_defaults(); } }