settings = $settings; $this->core_ai = $core_ai; $this->admin_ui = $admin_ui; $this->firewall = $firewall; $this->log = $log; } /** * Adds a per-plugin stripper. * * @param Integration $integration Stripper to register. * @return void */ public function add_integration( Integration $integration ): void { $this->integrations[ $integration->get_id() ] = $integration; } /** * Returns every registered stripper. * * @return Integration[] Strippers, keyed by identifier. */ public function get_integrations(): array { return $this->integrations; } /** * Returns the strippers whose target plugin is present. * * @return Integration[] Strippers, keyed by identifier. */ public function get_active_integrations(): array { return array_filter( $this->integrations, static function ( Integration $integration ) { return $integration->is_target_active(); } ); } /** * Registers everything the module hooks into WordPress. * * @return void */ public function register(): void { $this->core_ai->register(); $this->admin_ui->register(); $this->firewall->register(); add_action( 'plugins_loaded', array( $this, 'register_integrations' ), PHP_INT_MIN ); add_action( 'aiblackout_prune_logs', array( $this, 'prune' ) ); // Keeps the call-log table in step with the schema the code expects. add_action( 'admin_init', array( BlockedCalls::class, 'maybe_install' ) ); } /** * Registers each enabled stripper whose target is present. * * @return void */ public function register_integrations(): void { if ( aiblackout_is_disabled() ) { return; } foreach ( $this->integrations as $id => $integration ) { if ( ! $this->is_integration_enabled( $id ) ) { continue; } if ( ! $integration->is_target_active() ) { continue; } $integration->register(); } } /** * Whether a stripper is switched on. * * @param string $id Stripper identifier. * @return bool True when enabled. */ public function is_integration_enabled( string $id ): bool { $stored = $this->settings->get_blackout( 'integrations', array() ); if ( ! is_array( $stored ) || ! array_key_exists( $id, $stored ) ) { return true; } return ! empty( $stored[ $id ] ); } /** * Removes log rows past the retention window. * * @return void */ public function prune(): void { $this->log->prune(); } /** * Whether any part of the module is doing something. * * @return bool True when at least one switch is live. */ public function is_active(): bool { if ( aiblackout_is_disabled() ) { return false; } if ( $this->settings->is_blackout_enabled( Settings::BLACKOUT_CORE_AI ) ) { return true; } if ( $this->settings->is_blackout_enabled( Settings::BLACKOUT_ABILITIES ) ) { return true; } if ( $this->settings->is_blackout_enabled( Settings::BLACKOUT_CONNECTORS_UI ) ) { return true; } if ( Settings::OUTBOUND_OFF !== $this->firewall->get_mode() ) { return true; } foreach ( array_keys( $this->get_active_integrations() ) as $id ) { if ( $this->is_integration_enabled( $id ) ) { return true; } } return false; } /** * Core AI surface. * * @return CoreAi */ public function core_ai(): CoreAi { return $this->core_ai; } /** * Outbound firewall. * * @return OutboundFirewall */ public function firewall(): OutboundFirewall { return $this->firewall; } /** * Call log. * * @return BlockedCalls */ public function log(): BlockedCalls { return $this->log; } }