get_results("SELECT * FROM {$wpdb->prefix}aicg_templates ORDER BY name ASC"); wp_cache_set($cache_key, $templates, '', 300); // Cache for 5 minutes } ?>


"Write a 1000-word blog post about the benefits of remote work for software developers. Include statistics, pros and cons, and tips for staying productive. Use a professional but conversational tone."

prefix . 'aicg_usage_log'; // Check if table exists and get stats with caching $stats_cache_key = 'aicg_generator_stats_' . $user_id . '_' . gmdate('Y-m-d'); $today_stats = wp_cache_get($stats_cache_key); if ($today_stats === false && $wpdb->get_var($wpdb->prepare("SHOW TABLES LIKE %s", $usage_table)) == $usage_table && $user_id) { $today_stats = $wpdb->get_row($wpdb->prepare( "SELECT COUNT(*) as generations, COALESCE(SUM(cost), 0) as cost, COALESCE(SUM(tokens_used), 0) as tokens FROM {$wpdb->prefix}aicg_usage_log WHERE user_id = %d AND created_at BETWEEN %s AND %s", $user_id, $today_start, $today_end )); wp_cache_set($stats_cache_key, $today_stats, '', 300); // Cache for 5 minutes } if ($today_stats) { $generations = (int)$today_stats->generations; $cost = (float)$today_stats->cost; $tokens = (int)$today_stats->tokens; } else { $generations = 0; $cost = 0.0; $tokens = 0; } ?>

$