Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
70.59% covered (warning)
70.59%
12 / 17
80.00% covered (warning)
80.00%
8 / 10
CRAP
0.00% covered (danger)
0.00%
0 / 1
Related_Posts
73.33% covered (warning)
73.33%
11 / 15
80.00% covered (warning)
80.00%
8 / 10
13.29
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%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 activate_plugin
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2/**
3 * Feature: Related Posts
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 Related Posts module.
20 */
21class Related_Posts extends Module_Product {
22
23    /**
24     * The product slug
25     *
26     * @var string
27     */
28    public static $slug = 'related-posts';
29
30    /**
31     * The slug of the plugin associated with this product.
32     * Related Posts is a feature available as part of the Jetpack plugin.
33     *
34     * @var string
35     */
36    public static $plugin_slug = self::JETPACK_PLUGIN_SLUG;
37
38    /**
39     * The Plugin file associated with stats
40     *
41     * @var string|null
42     */
43    public static $plugin_filename = self::JETPACK_PLUGIN_FILENAME;
44
45    /**
46     * The Jetpack module name associated with this product
47     *
48     * @var string|null
49     */
50    public static $module_name = 'related-posts';
51
52    /**
53     * The category of the product
54     *
55     * @var string
56     */
57    public static $category = 'growth';
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 'Related Posts';
102    }
103
104    /**
105     * Get the product title
106     *
107     * @return string
108     */
109    public static function get_title() {
110        return 'Related Posts';
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 Newsletter 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        return Initializer::resolve_settings_url( self::$module_name, admin_url( 'admin.php?page=jetpack#/traffic?term=related%20posts' ) );
177    }
178
179    /**
180     * Activates the Jetpack plugin
181     *
182     * @return null|WP_Error Null on success, WP_Error on invalid file.
183     */
184    public static function activate_plugin(): ?WP_Error {
185        $plugin_filename = static::get_installed_plugin_filename( self::JETPACK_PLUGIN_SLUG );
186
187        if ( $plugin_filename ) {
188            return activate_plugin( $plugin_filename );
189        }
190    }
191}