repository = new Coreseal_Repository(); $this->exclusions = new Coreseal_Exclusions(); $this->register_scanner( new Coreseal_Core_Scanner() ); $this->register_scanner( new Coreseal_Compromise_Scanner() ); $this->register_scanner( new Coreseal_Malware_Scanner( $this->exclusions ) ); if ( is_admin() ) { new Coreseal_Admin( $this ); } /** * Fires once the plugin is ready. Add-ons hook here to register * scanners, admin screens or scheduled tasks. * * @param Coreseal_Plugin $plugin Main instance. */ do_action( 'coreseal_loaded', $this ); } public function register_scanner( Coreseal_Scanner $scanner ) { $this->scanners[ $scanner->get_id() ] = $scanner; } /** * @return Coreseal_Scanner[] */ public function get_scanners(): array { return $this->scanners; } public function get_repository(): Coreseal_Repository { return $this->repository; } public function get_exclusions(): Coreseal_Exclusions { return $this->exclusions; } /** * Runs a scanner, stores the result and returns the scan ID * (or a WP_Error if the scanner is unknown). * * @return int|WP_Error */ public function run_scanner( string $id ) { if ( ! isset( $this->scanners[ $id ] ) ) { return new WP_Error( 'coreseal_unknown_scanner', __( 'Unknown scanner.', 'coreseal' ) ); } return $this->record_result( $id, $this->scanners[ $id ]->run() ); } /** * Stores a scanner result (after exclusions and ignored items are * removed) and returns the scan ID. Also used by step-by-step scans. * * @param string $id Scanner ID. * @param array|WP_Error $result Scanner result. * @return int */ public function record_result( string $id, $result ): int { if ( is_array( $result ) ) { $this->exclusions->filter_result( $id, $result ); } $scan_id = $this->repository->start_scan( $id ); $this->repository->finish_scan( $scan_id, $result ); $this->repository->prune( $id ); /** * Fires after a scan. Used by add-ons for alerts or reports. * * @param int $scan_id Scan ID. * @param string $id Scanner ID. * @param array|WP_Error $result Result, after exclusions. */ do_action( 'coreseal_scan_finished', $scan_id, $id, $result ); return $scan_id; } }