ID, '_smartcontent_generated', true);
$tone = get_post_meta($post->ID, '_smartcontent_tone', true);
$length = get_post_meta($post->ID, '_smartcontent_length', true);
$replace = get_post_meta($post->ID, '_smartcontent_replace', true);
$tone_options = ['Friendly', 'Professional', 'Witty', 'Informative'];
$length_options = ['Short (300 words)', 'Medium (600 words)', 'Long (900 words)'];
include_once AI_WRITEX_ABSPATH . 'views/meta-box.php';
}
public function save_meta_box_data($post_id)
{
// Abort if doing autosave
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return;
}
// Verify nonce
if (
! isset($_POST['smartcontent_meta_box_nonce']) ||
! wp_verify_nonce($_POST['smartcontent_meta_box_nonce'], 'save_smartcontent_meta')
) {
return;
}
// Check user capability
if (! current_user_can('edit_post', $post_id)) {
return;
}
// Check user capability
update_post_meta($post_id, '_smartcontent_tone', sanitize_text_field($_POST['smartcontent_tone'] ?? ''));
update_post_meta($post_id, '_smartcontent_length', sanitize_text_field($_POST['smartcontent_length'] ?? ''));
update_post_meta($post_id, '_smartcontent_generated', sanitize_textarea_field($_POST['smartcontent_input'] ?? ''));
update_post_meta($post_id, '_smartcontent_replace', isset($_POST['smartcontent_replace']) ? 1 : 0);
}
public function ajax_generate_content()
{
// Verify nonce
if (! isset($_POST['_ajax_nonce']) || ! wp_verify_nonce($_POST['_ajax_nonce'], 'ai_writeX_ajax_nonce')) {
wp_send_json_error(['message' => 'Invalid or missing nonce.']);
wp_die();
}
// Check user capability
if (! current_user_can('edit_posts')) {
wp_send_json_error(['message' => 'Permission denied.']);
wp_die();
}
// Sanitize inputs
$desc = sanitize_text_field($_POST['description']);
$tone = sanitize_text_field($_POST['tone']);
$length = sanitize_text_field($_POST['length']);
$generator = new AI_writeX_SCG_Content_Generator();
$result = $generator->generate_post($desc, $tone, $length);
// $seo_validator = new AI_writeX_SCG_SEO_Validator();
// $score = $seo_validator->analyze_content($result);
// echo wp_kses_post($result . "
SEO Score: " . esc_html($score) . "%");
echo wp_kses_post($result);
wp_die();
}
}
class AI_writeX_SCG_Content_Generator
{
private $tool;
public function __construct()
{
$settings = get_option('writex_ai_save_settings');
if (!$settings) {
$this->tool = null;
return;
}
$manager = new AI_WriteX_Tool_Manager($settings);
if ($manager->is_valid_tool()) {
$this->tool = $manager->get_tool_instance();
} else {
$this->tool = null;
}
}
public function generate_post($description, $tone = 'Informative', $length = 'Medium (600 words)')
{
if (!$this->tool) {
return 'AI tool not properly configured.';
}
$word_count = 600;
if (strpos($length, '300') !== false) $word_count = 300;
if (strpos($length, '900') !== false) $word_count = 900;
// $prompt = "Write a $tone, SEO-friendly blog post (about $word_count words) on the topic: $description. Use only simple HTML tags like
,
,