Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
73.68% covered (warning)
73.68%
14 / 19
80.00% covered (warning)
80.00%
8 / 10
CRAP
0.00% covered (danger)
0.00%
0 / 1
Site_Accelerator
76.47% covered (warning)
76.47%
13 / 17
80.00% covered (warning)
80.00%
8 / 10
13.88
0.00% covered (danger)
0.00%
0 / 1
 get_name
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 get_title
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 get_description
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 get_long_description
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 get_features
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 get_pricing_for_ui
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 is_active
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 is_plugin_installed
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 get_manage_url
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 activate_plugin
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2/**
3 * Feature: Site Accelerator
4 *
5 * @package my-jetpack
6 */
7
8namespace Automattic\Jetpack\My_Jetpack\Products;
9
10use Automattic\Jetpack\My_Jetpack\Initializer;
11use Automattic\Jetpack\My_Jetpack\Module_Product;
12use WP_Error;
13
14if ( ! defined( 'ABSPATH' ) ) {
15    exit( 0 );
16}
17
18/**
19 * Class responsible for handling the Site Accelerator module.
20 */
21class Site_Accelerator extends Module_Product {
22
23    /**
24     * The product slug
25     *
26     * @var string
27     */
28    public static $slug = 'site-accelerator';
29
30    /**
31     * The category of the product
32     *
33     * @var string
34     */
35    public static $category = 'performance';
36
37    /**
38     * The slug of the plugin associated with this product.
39     * Site Accelerator is a feature available as part of the Jetpack plugin.
40     *
41     * @var string
42     */
43    public static $plugin_slug = self::JETPACK_PLUGIN_SLUG;
44
45    /**
46     * The Plugin file associated with stats
47     *
48     * @var string|null
49     */
50    public static $plugin_filename = self::JETPACK_PLUGIN_FILENAME;
51
52    /**
53     * The Jetpack module name associated with this product
54     *
55     * @var string|null
56     */
57    public static $module_name = 'site-accelerator';
58
59    /**
60     * Whether this module is a Jetpack feature
61     *
62     * @var boolean
63     */
64    public static $is_feature = true;
65
66    /**
67     * Whether this product requires a user connection
68     *
69     * @var boolean
70     */
71    public static $requires_user_connection = false;
72
73    /**
74     * Whether this product has a standalone plugin
75     *
76     * @var bool
77     */
78    public static $has_standalone_plugin = false;
79
80    /**
81     * Whether this product has a free offering
82     *
83     * @var bool
84     */
85    public static $has_free_offering = true;
86
87    /**
88     * Whether the product requires a plan to run
89     * The plan could be paid or free
90     *
91     * @var bool
92     */
93    public static $requires_plan = false;
94
95    /**
96     * Get the product name
97     *
98     * @return string
99     */
100    public static function get_name() {
101        return 'Site Accelerator';
102    }
103
104    /**
105     * Get the product title
106     *
107     * @return string
108     */
109    public static function get_title() {
110        return 'Site Accelerator';
111    }
112
113    /**
114     * Get the internationalized product description
115     *
116     * @return string
117     */
118    public static function get_description() {
119        return __( 'Draw your readers from one post to another', 'jetpack-my-jetpack' );
120    }
121
122    /**
123     * Get the internationalized product long description
124     *
125     * @return string
126     */
127    public static function get_long_description() {
128        return __( 'Draw your readers from one post to another, increasing overall traffic on your site', 'jetpack-my-jetpack' );
129    }
130
131    /**
132     * Get the internationalized feature list
133     *
134     * @return array Site Accelerattor features list
135     */
136    public static function get_features() {
137        return array();
138    }
139
140    /**
141     * Get the product princing details
142     *
143     * @return array Pricing details
144     */
145    public static function get_pricing_for_ui() {
146        return array(
147            'available' => true,
148            'is_free'   => true,
149        );
150    }
151
152    /**
153     * Checks whether the Product is active.
154     *
155     * @return boolean
156     */
157    public static function is_active() {
158        return static::is_jetpack_plugin_active();
159    }
160
161    /**
162     * Checks whether the plugin is installed
163     *
164     * @return boolean
165     */
166    public static function is_plugin_installed() {
167        return static::is_jetpack_plugin_installed();
168    }
169
170    /**
171     * Get the URL where the user manages the product
172     *
173     * @return ?string
174     */
175    public static function get_manage_url() {
176        if ( Initializer::is_settings_consolidation_on_for_site() ) {
177            return admin_url( 'admin.php?page=my-jetpack#/features?search=cdn' );
178        }
179
180        return admin_url( 'admin.php?page=jetpack#/settings?term=site%20accelerator' );
181    }
182
183    /**
184     * Activates the Jetpack plugin
185     *
186     * @return null|WP_Error Null on success, WP_Error on invalid file.
187     */
188    public static function activate_plugin(): ?WP_Error {
189        $plugin_filename = static::get_installed_plugin_filename( self::JETPACK_PLUGIN_SLUG );
190
191        if ( $plugin_filename ) {
192            return activate_plugin( $plugin_filename );
193        }
194    }
195}