Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
81.40% covered (warning)
81.40%
35 / 43
53.85% covered (warning)
53.85%
7 / 13
CRAP
0.00% covered (danger)
0.00%
0 / 1
Social
82.93% covered (warning)
82.93%
34 / 41
53.85% covered (warning)
53.85%
7 / 13
18.44
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_pricing_for_ui
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
1
 get_post_checkout_url
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 get_wpcom_product_slug
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 get_status
75.00% covered (warning)
75.00%
3 / 4
0.00% covered (danger)
0.00%
0 / 1
2.06
 get_paid_plan_product_slugs
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
1 / 1
1
 has_paid_plan_for_product
60.00% covered (warning)
60.00%
3 / 5
0.00% covered (danger)
0.00%
0 / 1
5.02
 get_manage_url
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
1<?php
2/**
3 * Jetpack Social product
4 *
5 * @package my-jetpack
6 */
7
8namespace Automattic\Jetpack\My_Jetpack\Products;
9
10use Automattic\Jetpack\My_Jetpack\Hybrid_Product;
11use Automattic\Jetpack\My_Jetpack\Products;
12use Automattic\Jetpack\My_Jetpack\Wpcom_Products;
13use Automattic\Jetpack\Status\Host;
14
15if ( ! defined( 'ABSPATH' ) ) {
16    exit( 0 );
17}
18
19/**
20 * Class responsible for handling the Social product
21 */
22class Social extends Hybrid_Product {
23
24    /**
25     * The product slug
26     *
27     * @var string
28     */
29    public static $slug = 'social';
30
31    /**
32     * The Jetpack module name
33     *
34     * @var string
35     */
36    public static $module_name = 'publicize';
37
38    /**
39     * The slug of the plugin associated with this product.
40     *
41     * @var string
42     */
43    public static $plugin_slug = 'jetpack-social';
44
45    /**
46     * The category of the product
47     *
48     * @var string
49     */
50    public static $category = 'growth';
51
52    /**
53     * Social has a standalone plugin
54     *
55     * @var bool
56     */
57    public static $has_standalone_plugin = true;
58
59    /**
60     * The filename (id) of the plugin associated with this product.
61     *
62     * @var string
63     */
64    public static $plugin_filename = array(
65        'jetpack-social/jetpack-social.php',
66        'social/jetpack-social.php',
67        'jetpack-social-dev/jetpack-social.php',
68    );
69
70    /**
71     * Whether this product has a free offering
72     *
73     * @var bool
74     */
75    public static $has_free_offering = true;
76
77    /**
78     * The feature slug that identifies the paid plan
79     *
80     * @var string
81     */
82    public static $feature_identifying_paid_plan = 'social-enhanced-publishing';
83
84    /**
85     * Get the product name
86     *
87     * @return string
88     */
89    public static function get_name() {
90        return 'Social';
91    }
92
93    /**
94     * Get the product title
95     *
96     * @return string
97     */
98    public static function get_title() {
99        return 'Jetpack Social';
100    }
101
102    /**
103     * Get the internationalized product description
104     *
105     * @return string
106     */
107    public static function get_description() {
108        return __( 'Auto‑share your posts to social networks and track engagement in one place.', 'jetpack-my-jetpack' );
109    }
110
111    /**
112     * Get the internationalized product long description
113     *
114     * @return string
115     */
116    public static function get_long_description() {
117        return __( 'Grow your following by sharing your content across social media automatically.', 'jetpack-my-jetpack' );
118    }
119
120    /**
121     * Get the internationalized features list
122     *
123     * @return array Social features list
124     */
125    public static function get_features() {
126        return array(
127            __( 'Post to social networks', 'jetpack-my-jetpack' ),
128            __( 'Schedule publishing', 'jetpack-my-jetpack' ),
129            __( 'Supports the major social networks', 'jetpack-my-jetpack' ),
130        );
131    }
132
133    /**
134     * Get the product pricing details
135     *
136     * @return array Pricing details
137     */
138    public static function get_pricing_for_ui() {
139        return array_merge(
140            array(
141                'available'          => true,
142                'wpcom_product_slug' => static::get_wpcom_product_slug(),
143            ),
144            Wpcom_Products::get_product_pricing( static::get_wpcom_product_slug() )
145        );
146    }
147
148    /**
149     * Get the URL the user is taken after purchasing the product through the checkout
150     *
151     * @return ?string
152     */
153    public static function get_post_checkout_url() {
154        return self::get_manage_url();
155    }
156
157    /**
158     * Get the WPCOM product slug used to make the purchase
159     *
160     * @return string
161     */
162    public static function get_wpcom_product_slug() {
163        return 'jetpack_social_v1_yearly';
164    }
165
166    /**
167     * Gets the 'status' of the Social product
168     *
169     * @return string
170     */
171    public static function get_status() {
172        $status = parent::get_status();
173        if ( Products::STATUS_NEEDS_PLAN === $status ) {
174            // If the status says that the site needs a plan,
175            // My Jetpack shows "Learn more" CTA,
176            // We want to instead show the "Activate" CTA.
177            $status = Products::STATUS_NEEDS_ACTIVATION;
178        }
179        return $status;
180    }
181
182    /**
183     * Get the product-slugs of the paid plans for this product (not including bundles)
184     *
185     * @return array
186     */
187    public static function get_paid_plan_product_slugs() {
188        return array(
189            'jetpack_social_v1_yearly',
190            'jetpack_social_v1_monthly',
191            'jetpack_social_v1_bi_yearly',
192            'jetpack_social_basic_yearly',
193            'jetpack_social_monthly',
194            'jetpack_social_basic_monthly',
195            'jetpack_social_basic_bi_yearly',
196            'jetpack_social_advanced_yearly',
197            'jetpack_social_advanced_monthly',
198            'jetpack_social_advanced_bi_yearly',
199        );
200    }
201
202    /**
203     * Checks whether the current plan (or purchases) of the site already supports the product
204     *
205     * @return boolean
206     */
207    public static function has_paid_plan_for_product() {
208        if ( parent::has_paid_plan_for_product() ) {
209            return true;
210        }
211
212        // For atomic sites, do a feature check to see if the republicize feature is available
213        // This feature is available by default on all Jetpack sites
214        if ( ( new Host() )->is_woa_site() && static::does_site_have_feature( 'republicize' ) ) {
215            return true;
216        }
217
218        return false;
219    }
220
221    /**
222     * Get the URL where the user manages the product.
223     *
224     * @return string
225     */
226    public static function get_manage_url() {
227        return admin_url( 'admin.php?page=jetpack-social' );
228    }
229
230    /**
231     * Return product bundles list
232     * that supports the product.
233     *
234     * @return boolean|array Products bundle list.
235     */
236    public static function is_upgradable_by_bundle() {
237        return array( 'growth', 'complete' );
238    }
239}