// Add nonce verification
add_action('wp_ajax_aiag_manual_generate', 'aiag_manual_generate_articles');

function aiag_manual_generate_articles() {
    // Check nonce
    if (!isset($_POST['_ajax_nonce']) || !wp_verify_nonce($_POST['_ajax_nonce'], 'aiag_manual_generate')) {
        wp_send_json_error('Security check failed');
        return;
    }
    
    if (!current_user_can('manage_options')) {
        wp_send_json_error('Unauthorized');
        return;
    }
    
    // Check if API key exists
    $default_api = get_option('aiag_default_api', 'gemini');
    $api_key = '';
    
    switch ($default_api) {
        case 'gemini':
            $api_key = get_option('aiag_gemini_api', '');
            break;
        case 'openrouter':
            $api_key = get_option('aiag_openrouter_api', '');
            break;
        case 'groq':
            $api_key = get_option('aiag_groq_api', '');
            break;
    }
    
    if (empty($api_key)) {
        wp_send_json_error('No API key found for ' . $default_api . '. Please configure your API key in settings.');
        return;
    }
    
    // Run generation
    $posts_per_day = get_option('aiag_posts_per_day', 5);
    $suggester = new AIAG_Keyword_Suggester();
    $content_gen = new AIAG_Content_Generator();
    
    $keywords = $suggester->get_pending_keywords($posts_per_day);
    
    if (empty($keywords)) {
        wp_send_json_error('No pending keywords found. Please add keywords first.');
        return;
    }
    
    $generated = 0;
    foreach ($keywords as $keyword_data) {
        $result = $content_gen->generate_article($keyword_data->keyword, $default_api, $api_key);
        
        if ($result) {
            $suggester->mark_keyword_used($keyword_data->id);
            $generated++;
        }
        
        sleep(3); // Prevent API rate limiting
    }
    
    wp_send_json_success("Successfully generated {$generated} out of " . count($keywords) . " articles!");
}<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="//jammuads.com/phuwisoa/wordpress-seo/css/main-sitemap.xsl"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
	<sitemap>
		<loc>https://jammuads.com/post-sitemap.xml</loc>
		<lastmod>2026-04-13T19:46:41+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://jammuads.com/page-sitemap.xml</loc>
		<lastmod>2026-04-10T23:29:17+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://jammuads.com/listing-sitemap.xml</loc>
		<lastmod>2026-04-13T08:52:07+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://jammuads.com/product-sitemap.xml</loc>
		<lastmod>2026-03-22T13:24:32+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://jammuads.com/testimonial-sitemap.xml</loc>
		<lastmod>2018-11-06T11:33:40+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://jammuads.com/category-sitemap.xml</loc>
		<lastmod>2026-04-13T19:46:41+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://jammuads.com/post_tag-sitemap.xml</loc>
		<lastmod>2026-04-11T00:55:44+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://jammuads.com/product_cat-sitemap.xml</loc>
		<lastmod>2026-03-22T13:24:32+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://jammuads.com/author-sitemap.xml</loc>
		<lastmod>2026-03-21T08:48:42+00:00</lastmod>
	</sitemap>
</sitemapindex>
