self::ID, 'name' => __( 'Performance check', 'forensix-digital' ), 'description' => __( 'Lists the scripts, styles and fonts your pages load from other websites, scripts that hold up the page, very large pages and images that could load lazily, with a note on what each means. It does not measure loading time.', 'forensix-digital' ), 'category' => 'performance', 'edition' => Edition::FREE, 'dependencies' => array( SiteScanApp::ID ), 'features' => array( 'F-PERF-01' => Edition::FREE, 'F-PERF-02' => Edition::FREE, 'F-PERF-03' => Edition::FREE, 'F-PERF-04' => Edition::FREE, 'F-PERF-05' => Edition::FREE, ), 'deactivation_effects' => array( __( 'Scans no longer list outside resources, blocking scripts or image loading.', 'forensix-digital' ), __( 'Existing findings stay visible until the next scan. Your pages are not changed.', 'forensix-digital' ), __( 'The Speed test screen is hidden.', 'forensix-digital' ), ), 'factory' => static fn(): self => new self(), ) ); } /** * Hooks the app while it is active. */ public function register(): void { add_filter( 'forensix_scan_checks', array( $this, 'add_checks' ) ); add_filter( 'forensix_admin_screens', array( $this, 'add_screen' ) ); add_action( 'rest_api_init', array( $this->routes(), 'register_routes' ) ); } /** * The Speed test routes. */ private function routes(): SpeedRoutes { $this->routes ??= new SpeedRoutes(); return $this->routes; } /** * Adds the "Speed test" screen. * * @param array $screens Screens. * @return array */ public function add_screen( array $screens ): array { $screens['forensix-speed'] = array( 'key' => 'speed', 'title' => __( 'Speed test', 'forensix-digital' ), 'capability' => Capabilities::VIEW_FINDINGS, ); return $screens; } /** * Nothing to set up. */ public function activate(): void {} /** * Stops adding the check to scans. */ public function deactivate(): void { remove_filter( 'forensix_scan_checks', array( $this, 'add_checks' ) ); remove_filter( 'forensix_admin_screens', array( $this, 'add_screen' ) ); remove_action( 'rest_api_init', array( $this->routes(), 'register_routes' ) ); } /** * Removes the own Google key. Findings belong to the core. */ public function delete_data(): void { delete_option( SpeedRoutes::KEY ); } /** * Adds the check to a site scan. * * @param mixed $checks Page checks of the scan. * @return mixed */ public function add_checks( $checks ) { if ( ! is_array( $checks ) ) { return $checks; } $checks[] = new ThirdPartyCheck( SiteScanApp::hosts() ); $checks[] = new PageWeightCheck(); return $checks; } }