Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
93.94% covered (success)
93.94%
31 / 33
91.67% covered (success)
91.67%
11 / 12
CRAP
0.00% covered (danger)
0.00%
0 / 1
Anti_Spam
96.77% covered (success)
96.77%
30 / 31
91.67% covered (success)
91.67%
11 / 12
16
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%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 get_paid_plan_product_slugs
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 has_paid_plan_for_product
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
3
 has_free_plan_for_product
75.00% covered (warning)
75.00%
3 / 4
0.00% covered (danger)
0.00%
0 / 1
3.14
 get_pricing_for_ui
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
1
 get_wpcom_product_slug
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 is_upgradable_by_bundle
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%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2/**
3 * Anti_Spam product
4 *
5 * @package my-jetpack
6 */
7
8namespace Automattic\Jetpack\My_Jetpack\Products;
9
10use Automattic\Jetpack\My_Jetpack\Product;
11use Automattic\Jetpack\My_Jetpack\Wpcom_Products;
12use Automattic\Jetpack\Status\Host;
13
14if ( ! defined( 'ABSPATH' ) ) {
15    exit( 0 );
16}
17
18/**
19 * Class responsible for handling the Anti_Spam product
20 */
21class Anti_Spam extends Product {
22
23    /**
24     * The product slug
25     *
26     * @var string
27     */
28    public static $slug = 'anti-spam';
29
30    /**
31     * The filename (id) of the plugin associated with this product. If not defined, it will default to the Jetpack plugin
32     *
33     * @var string
34     */
35    public static $plugin_filename = 'akismet/akismet.php';
36
37    /**
38     * The slug of the plugin associated with this product. If not defined, it will default to the Jetpack plugin
39     *
40     * @var string
41     */
42    public static $plugin_slug = 'akismet';
43
44    /**
45     * The category of the product
46     *
47     * @var string
48     */
49    public static $category = 'security';
50
51    /**
52     * The feature slug that identifies the paid plan
53     *
54     * @var string
55     */
56    public static $feature_identifying_paid_plan = 'antispam';
57
58    /**
59     * Whether this product requires a user connection
60     *
61     * @var string
62     */
63    public static $requires_user_connection = false;
64
65    /**
66     * Whether this product has a free offering
67     *
68     * @var bool
69     */
70    public static $has_free_offering = true;
71
72    /**
73     * Akismet has a standalone plugin
74     *
75     * @var bool
76     */
77    public static $has_standalone_plugin = true;
78
79    /**
80     * Get the product name
81     *
82     * @return string
83     */
84    public static function get_name() {
85        return 'Akismet Anti-spam';
86    }
87
88    /**
89     * Get the product title
90     *
91     * @return string
92     */
93    public static function get_title() {
94        return 'Jetpack Akismet Anti-spam';
95    }
96
97    /**
98     * Get the internationalized product description
99     *
100     * @return string
101     */
102    public static function get_description() {
103        return __( 'Automatically clear spam from comments and forms.', 'jetpack-my-jetpack' );
104    }
105
106    /**
107     * Get the internationalized product long description
108     *
109     * @return string
110     */
111    public static function get_long_description() {
112        return __( 'Save time and get better responses by automatically blocking spam from your comments and forms.', 'jetpack-my-jetpack' );
113    }
114
115    /**
116     * Get the internationalized features list
117     *
118     * @return array Boost features list
119     */
120    public static function get_features() {
121        return array(
122            _x( 'Comment and form spam protection', 'Anti-Spam Product Feature', 'jetpack-my-jetpack' ),
123            _x( 'Block spam without CAPTCHAs', 'Anti-Spam Product Feature', 'jetpack-my-jetpack' ),
124            _x( 'Advanced stats', 'Anti-Spam Product Feature', 'jetpack-my-jetpack' ),
125        );
126    }
127
128    /**
129     * Get the product-slugs of the paid plans for this product.
130     * (Do not include bundle plans, unless it's a bundle plan itself).
131     *
132     * @return array
133     */
134    public static function get_paid_plan_product_slugs() {
135        return array(
136            'jetpack_anti_spam',
137            'jetpack_anti_spam_monthly',
138            'jetpack_anti_spam_bi_yearly',
139        );
140    }
141
142    /**
143     * Whether the site pays for Anti-spam.
144     *
145     * WordPress.com grants `antispam` only from Business up, though every plan gets the full Akismet service.
146     * Off WordPress.com a free Akismet key grants `akismet` too, so there it proves nothing.
147     *
148     * @return boolean
149     */
150    public static function has_paid_plan_for_product() {
151        if ( ( new Host() )->is_wpcom_platform() && static::does_site_have_feature( 'akismet' ) ) {
152            return true;
153        }
154
155        return parent::has_paid_plan_for_product();
156    }
157
158    /**
159     * Check if the product has a free plan
160     * In this case we are only checking for an API key. The has_paid_plan_for_product will check to see if the specific site has a paid plan
161     *
162     * @return bool
163     */
164    public static function has_free_plan_for_product() {
165        $akismet_api_key = apply_filters( 'akismet_get_api_key', defined( 'WPCOM_API_KEY' ) ? constant( 'WPCOM_API_KEY' ) : get_option( 'wordpress_api_key' ) );
166        if ( ! empty( $akismet_api_key ) ) {
167            return true;
168        }
169
170        return false;
171    }
172
173    /**
174     * Get the product princing details
175     *
176     * @return array Pricing details
177     */
178    public static function get_pricing_for_ui() {
179        return array_merge(
180            array(
181                'available'          => true,
182                'wpcom_product_slug' => static::get_wpcom_product_slug(),
183            ),
184            Wpcom_Products::get_product_pricing( static::get_wpcom_product_slug() )
185        );
186    }
187
188    /**
189     * Get the WPCOM product slug used to make the purchase
190     *
191     * @return ?string
192     */
193    public static function get_wpcom_product_slug() {
194        return 'jetpack_anti_spam';
195    }
196
197    /**
198     * Return product bundles list
199     * that supports the product.
200     *
201     * @return boolean|array Products bundle list.
202     */
203    public static function is_upgradable_by_bundle() {
204        return array( 'security', 'complete' );
205    }
206
207    /**
208     * Get the URL where the user manages the product
209     *
210     * @return ?string
211     */
212    public static function get_manage_url() {
213        return admin_url( 'admin.php?page=akismet-key-config' );
214    }
215}