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