'aibp_status', 'meta_value' => 'active', ] ); foreach ( $agents as $agent ) { if ( $agent->should_run_now() ) { $this->run_agent( $agent->get_id() ); } } } public function run_agent( int $agent_id ): void { $agent = new Agent( $agent_id ); if ( ! $agent->exists() || ! $agent->is_active() ) { return; } try { $post_id = \AIBP\AI\AI::generate_post( $agent_id ); if ( $post_id ) { $agent->increment_run(); } } catch ( \Exception $e ) { \AIBP\Log\ActivityLog::log( $agent_id, 'error', $e->getMessage() ); } } public function on_agent_deleted( int $post_id ): void { if ( get_post_type( $post_id ) === 'aibp_events' ) { // No per-agent cron to clear in v2.0 — using global daily check. } } public function cleanup_logs(): void { $options = get_option( 'aibp_settings', [] ); $retention = absint( $options['log_retention'] ?? 90 ); \AIBP\Log\ActivityLog::delete_old_logs( $retention ); } public static function run_now( int $agent_id ): void { $agent = new Agent( $agent_id ); if ( ! $agent->exists() ) { return; } try { $post_id = \AIBP\AI\AI::generate_post( $agent_id ); if ( $post_id ) { $agent->increment_run(); } } catch ( \Exception $e ) { \AIBP\Log\ActivityLog::log( $agent_id, 'error', $e->getMessage() ); throw $e; } } }