run(); } } add_action( 'plugins_loaded', 'aitm_init' ); /** * Activation hook */ function aitm_activate() { // Set default options $default_options = array( 'auto_generation' => true, 'enabled_post_types' => array( 'post', 'page' ), 'overwrite_existing' => false, 'min_image_width' => 0, 'min_image_height' => 0, 'generation_method' => 'first_content_image', 'ai_content_source' => 'title_first_paragraph', 'ai_api_key' => '', 'ai_prompt_model' => 'gpt-4o-mini', 'ai_language' => 'en_US', 'ai_image_model' => 'dall-e-3', 'ai_image_resolution' => '1024x1024', 'ai_image_style' => 'natural', 'title_image_width' => 1200, 'title_image_height' => 630, 'title_image_bg_color' => '#2271b1', 'title_image_text_color' => '#ffffff', 'title_image_font_size' => 48, 'default_image_id' => 0, 'download_remote_images' => false, ); if ( ! get_option( 'aitm_settings' ) ) { add_option( 'aitm_settings', $default_options ); } // Initialize generation log in separate option if ( ! get_option( 'aitm_generation_log' ) ) { add_option( 'aitm_generation_log', array() ); } // Set activation time for first run if ( ! get_option( 'aitm_activation_time' ) ) { add_option( 'aitm_activation_time', time() ); } // Create log directory and protection files require_once AITM_PLUGIN_DIR . 'includes/class-log-manager.php'; $log_manager = new AITM_Log_Manager(); // Directory creation is handled in constructor // Schedule daily log cleanup if ( ! wp_next_scheduled( 'aitm_daily_log_cleanup' ) ) { wp_schedule_event( time(), 'daily', 'aitm_daily_log_cleanup' ); } } register_activation_hook( __FILE__, 'aitm_activate' ); /** * Deactivation hook */ function aitm_deactivate() { // Clear scheduled cron events $timestamp = wp_next_scheduled( 'aitm_daily_log_cleanup' ); if ( $timestamp ) { wp_unschedule_event( $timestamp, 'aitm_daily_log_cleanup' ); } } register_deactivation_hook( __FILE__, 'aitm_deactivate' );