Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
Products_Page
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 2
20
0.00% covered (danger)
0.00%
0 / 1
 is_flag_enabled
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 is_products_only_enabled
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2/**
3 * Gating logic for the flagged "products-only" My Jetpack interface.
4 *
5 * When enabled on WordPress.com Simple and Atomic sites that cannot manage Jetpack modules, the
6 * My Jetpack admin page renders only the products grid (no tabs, no module toggles, no modules
7 * footer link, and no onboarding redirect). Sites that can manage modules get the full My Jetpack.
8 *
9 * @package automattic/my-jetpack
10 */
11
12namespace Automattic\Jetpack\My_Jetpack;
13
14use Automattic\Jetpack\Constants;
15
16/**
17 * Computes whether the products-only mode is active.
18 */
19class Products_Page {
20
21    /**
22     * Constant that turns the products-only mode on.
23     */
24    const FLAG_CONSTANT = 'JETPACK_MY_JETPACK_PRODUCTS_ONLY';
25
26    /**
27     * The wpcom feature that grants module management and the full My Jetpack experience
28     * (i.e. access to more than just the products grid).
29     */
30    const MANAGE_MODULES_FEATURE = 'manage-plugins';
31
32    /**
33     * Whether the products-only feature flag (constant) is set.
34     *
35     * @return bool
36     */
37    private static function is_flag_enabled() {
38        return Constants::is_true( self::FLAG_CONSTANT );
39    }
40
41    /**
42     * Whether the products-only interface should be shown.
43     *
44     * The wpcom "site has feature" lookup only exists on WordPress.com / Atomic sites, so its
45     * presence gates this to those sites (self-hosted sites are unaffected). Within them, sites
46     * that cannot manage modules get the products-only experience.
47     *
48     * @return bool
49     */
50    public static function is_products_only_enabled() {
51        if ( ! self::is_flag_enabled() || ! function_exists( 'wpcom_site_has_feature' ) ) {
52            return false;
53        }
54
55        return ! wpcom_site_has_feature( self::MANAGE_MODULES_FEATURE );
56    }
57}