Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
50.00% covered (danger)
50.00%
2 / 4
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
WPCOM_Scan
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 get_live_feature_url
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
1<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName -- Feature entry file, named after the feature, also holds the WPCOM_Scan bootstrap class.
2/**
3 * An in-wp-admin Protect page for WordPress.com Simple and WoA sites.
4 * Prompts for a plan upgrade or activation of Scan.
5 *
6 * @package automattic/jetpack-mu-wpcom
7 */
8
9namespace Automattic\Jetpack\Jetpack_Mu_Wpcom;
10
11require_once __DIR__ . '/../wpcom-hosting-feature-page/class-wpcom-hosting-feature-page.php';
12
13/**
14 * Registers the Protect admin page and its wp-build assets.
15 */
16class WPCOM_Scan extends WPCOM_Hosting_Feature_Page {
17
18    /**
19     * The slug the Jetpack plugin is expected to serve Protect from on WoA once Scan is live.
20     */
21    const MENU_SLUG = 'jetpack-protect';
22
23    /**
24     * As declared in routes/wpcom-scan/package.json.
25     */
26    const WP_BUILD_PAGE = 'wpcom-scan';
27
28    /**
29     * Product name, do not translate.
30     */
31    const PAGE_TITLE = 'Jetpack Protect';
32
33    /**
34     * Product name, do not translate.
35     */
36    const MENU_TITLE = 'Protect';
37
38    /**
39     * SCAN_SELF_SERVE, not SCAN: SCAN also covers Personal and Premium plans, which run scans
40     * without exposing Scan's UI. It is also what the dashboard's Scan page gates on.
41     */
42    const FEATURE = 'SCAN_SELF_SERVE';
43
44    /**
45     * Calypso's Scan page, since nothing serves this slug on WoA once Scan is live.
46     *
47     * Drop this override to land back on `jetpack-protect` once the Jetpack plugin serves it.
48     *
49     * @param string|null $new_host The site's address after a transfer, when it changes.
50     * @return string
51     */
52    public static function get_live_feature_url( $new_host = null ) {
53        $host = $new_host ?? wp_parse_url( home_url(), PHP_URL_HOST );
54
55        return 'https://wordpress.com/scan/' . rawurlencode( (string) $host );
56    }
57}
58
59add_action( 'init', array( WPCOM_Scan::class, 'init' ) );