init_hooks(); $this->load_dependencies(); } /** * Initialize hooks */ private function init_hooks() { add_action('init', array($this, 'init')); register_activation_hook(__FILE__, array($this, 'activate')); register_deactivation_hook(__FILE__, array($this, 'deactivate')); } /** * Load plugin dependencies */ private function load_dependencies() { // Load required files require_once AIAPG_PLUGIN_DIR . 'includes/class-utils.php'; require_once AIAPG_PLUGIN_DIR . 'includes/class-admin-settings.php'; require_once AIAPG_PLUGIN_DIR . 'includes/class-schedule-manager.php'; require_once AIAPG_PLUGIN_DIR . 'includes/class-post-generator.php'; require_once AIAPG_PLUGIN_DIR . 'includes/class-image-generator.php'; require_once AIAPG_PLUGIN_DIR . 'includes/class-scheduler.php'; } /** * Initialize plugin */ public function init() { // Initialize components $this->admin_settings = new AIAPG_Admin_Settings(); $this->schedule_manager = new AIAPG_Schedule_Manager(); $this->post_generator = new AIAPG_Post_Generator(); $this->image_generator = new AIAPG_Image_Generator(); $this->scheduler = new AIAPG_Scheduler(); // Register shortcodes add_shortcode('aiapg_image', array($this, 'handle_image_shortcode')); // Setup is always complete - no wizard needed } /** * Handle image shortcode * * @param array $atts * @return string */ public function handle_image_shortcode($atts) { // This shortcode is primarily for AI processing during post generation // If it appears in the frontend, we'll show a placeholder or nothing $atts = shortcode_atts(array( 'prompt' => '', ), $atts); // In frontend, return empty string as images should already be processed if (!is_admin()) { return ''; } // In admin/editor, show placeholder return sprintf( '
AI Image Placeholder
Prompt: %s
This will be replaced with a generated image when the post is published.
', esc_html($atts['prompt']) ); } /** * Plugin activation */ public function activate() { // Create database tables $this->create_tables(); // Set default options $this->set_default_options(); // Flush rewrite rules flush_rewrite_rules(); } /** * Plugin deactivation */ public function deactivate() { // Clear scheduled events wp_clear_scheduled_hook('aiapg_schedule_run'); // Flush rewrite rules flush_rewrite_rules(); } /** * Create database tables */ private function create_tables() { global $wpdb; $charset_collate = $wpdb->get_charset_collate(); // Schedules table $table_schedules = $wpdb->prefix . 'aiapg_schedules'; $sql_schedules = "CREATE TABLE $table_schedules ( id mediumint(9) NOT NULL AUTO_INCREMENT, name varchar(255) NOT NULL, description text, categories longtext, custom_prompts longtext, posts_per_run int(11) DEFAULT 1, text_model varchar(100) DEFAULT 'gpt-3.5-turbo', image_model varchar(100) DEFAULT 'dall-e-2', fallback_image_model varchar(100) DEFAULT 'pollinations', enable_images tinyint(1) DEFAULT 1, image_placement varchar(50) DEFAULT 'featured', image_size varchar(20) DEFAULT '1024x1024', images_per_post int(11) DEFAULT 1, interval_type varchar(20) DEFAULT 'daily', interval_value int(11) DEFAULT 1, custom_cron varchar(255), is_active tinyint(1) DEFAULT 1, last_run datetime DEFAULT NULL, next_run datetime DEFAULT NULL, created_at datetime DEFAULT CURRENT_TIMESTAMP, updated_at datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (id) ) $charset_collate;"; // Logs table $table_logs = $wpdb->prefix . 'aiapg_logs'; $sql_logs = "CREATE TABLE $table_logs ( id mediumint(9) NOT NULL AUTO_INCREMENT, schedule_id mediumint(9), run_time datetime DEFAULT CURRENT_TIMESTAMP, posts_created int(11) DEFAULT 0, text_model varchar(100), image_model varchar(100), status varchar(20) DEFAULT 'success', message text, details longtext, PRIMARY KEY (id), KEY schedule_id (schedule_id), KEY run_time (run_time) ) $charset_collate;"; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql_schedules); dbDelta($sql_logs); } /** * Set default options */ private function set_default_options() { $default_options = array( 'openai_api_key' => '', 'gemini_api_key' => '', 'default_text_model' => 'gpt-3.5-turbo', 'default_image_model' => 'dall-e-2', 'default_fallback_image_model' => 'pollinations', 'setup_completed' => true, 'version' => AIAPG_VERSION ); foreach ($default_options as $key => $value) { if (get_option('aiapg_' . $key) === false) { add_option('aiapg_' . $key, $value); } } } /** * Check if setup is complete - always true since no wizard * * @return bool */ public function is_setup_complete() { return true; } /** * Get plugin URL * * @param string $path * @return string */ public function get_url($path = '') { return AIAPG_PLUGIN_URL . $path; } /** * Get plugin path * * @param string $path * @return string */ public function get_path($path = '') { return AIAPG_PLUGIN_DIR . $path; } } /** * Get plugin instance * * @return AI_Auto_Post_Generator */ function aiapg() { return AI_Auto_Post_Generator::get_instance(); } // Initialize plugin aiapg();