self::ID, 'name' => __( 'Launch checklist', 'forensix-digital' ), 'description' => __( 'A list of what your site needs before it goes live, such as search visibility, https, a privacy page and a first scan. Shows what is done and where to fix the rest.', 'forensix-digital' ), 'category' => 'tools', 'edition' => Edition::FREE, 'features' => array( 'C-01' => Edition::FREE, ), 'deactivation_effects' => array( __( 'The Launch checklist page is removed from the menu.', 'forensix-digital' ), __( 'Nothing on your site changes.', 'forensix-digital' ), ), 'factory' => static fn(): self => new self(), ) ); } /** * Hooks the app while it is active. */ public function register(): void { add_action( 'rest_api_init', array( $this, 'register_routes' ) ); add_filter( 'forensix_admin_screens', array( $this, 'add_screen' ) ); } /** * Registers the checklist route. */ public function register_routes(): void { register_rest_route( Api::NAMESPACE, '/launch', array( 'methods' => 'GET', 'callback' => array( $this, 'show' ), 'permission_callback' => static fn(): bool => current_user_can( Capabilities::VIEW_FINDINGS ), ) ); } /** * Adds the page to the Forensix menu. * * @param array $screens Screens. * @phpstan-param array $screens * @return array */ public function add_screen( array $screens ): array { $screens['forensix-launch'] = array( 'key' => 'launch', 'title' => __( 'Launch checklist', 'forensix-digital' ), 'capability' => Capabilities::VIEW_FINDINGS, ); return $screens; } /** * The checklist. */ public function show(): \WP_REST_Response { $store = Plugin::container()->get( FindingStore::class ); $latest = $store->latest_scan( SiteScanApp::ID ); $open = $store->open_by_severity(); $items = LaunchChecklist::items( LaunchChecklist::collect( null === $latest ? '' : (string) $latest['status'], $open[ Priority::CRITICAL ] + $open[ Priority::HIGH ] ) ); return new \WP_REST_Response( array( 'items' => $items, 'done' => LaunchChecklist::done_count( $items ), 'total' => count( $items ), ) ); } /** * Nothing to set up. */ public function activate(): void {} /** * Removes the hooks. */ public function deactivate(): void { remove_action( 'rest_api_init', array( $this, 'register_routes' ) ); remove_filter( 'forensix_admin_screens', array( $this, 'add_screen' ) ); } /** * Stores nothing. */ public function delete_data(): void {} }