Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
95.65% covered (success)
95.65%
22 / 23
100.00% covered (success)
100.00%
9 / 9
CRAP
100.00% covered (success)
100.00%
1 / 1
Jetpack_Forms
100.00% covered (success)
100.00%
21 / 21
100.00% covered (success)
100.00%
9 / 9
11
100.00% covered (success)
100.00%
1 / 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_pricing_for_ui
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 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%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
 activate_plugin
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2/**
3 * Forms product
4 *
5 * @package my-jetpack
6 */
7
8namespace Automattic\Jetpack\My_Jetpack\Products;
9
10use Automattic\Jetpack\My_Jetpack\Module_Product;
11use WP_Error;
12
13if ( ! defined( 'ABSPATH' ) ) {
14    exit( 0 );
15}
16
17/**
18 * Class responsible for handling the Jetpack Forms product.
19 *
20 * Forms is a feature available as part of the Jetpack plugin, backed by the
21 * `contact-form` module.
22 */
23class Jetpack_Forms extends Module_Product {
24
25    /**
26     * The product slug
27     *
28     * @var string
29     */
30    public static $slug = 'jetpack-forms';
31
32    /**
33     * The slug of the plugin associated with this product.
34     * Forms is a feature available as part of the Jetpack plugin.
35     *
36     * @var string
37     */
38    public static $plugin_slug = self::JETPACK_PLUGIN_SLUG;
39
40    /**
41     * The Plugin file associated with Forms.
42     *
43     * @var string|null
44     */
45    public static $plugin_filename = self::JETPACK_PLUGIN_FILENAME;
46
47    /**
48     * The Jetpack module name associated with this product.
49     *
50     * @var string|null
51     */
52    public static $module_name = 'contact-form';
53
54    /**
55     * The category of the product
56     *
57     * @var string
58     */
59    public static $category = 'growth';
60
61    /**
62     * Whether this module is a Jetpack feature
63     *
64     * @var boolean
65     */
66    public static $is_feature = true;
67
68    /**
69     * Whether this product requires a user connection
70     *
71     * @var boolean
72     */
73    public static $requires_user_connection = false;
74
75    /**
76     * Whether this product has a standalone plugin
77     *
78     * @var bool
79     */
80    public static $has_standalone_plugin = false;
81
82    /**
83     * Whether this product has a free offering
84     *
85     * @var bool
86     */
87    public static $has_free_offering = true;
88
89    /**
90     * Whether the product requires a plan to run.
91     * The plan could be paid or free.
92     *
93     * @var bool
94     */
95    public static $requires_plan = false;
96
97    /**
98     * Get the product name
99     *
100     * @return string
101     */
102    public static function get_name() {
103        return 'Forms';
104    }
105
106    /**
107     * Get the product title
108     *
109     * @return string
110     */
111    public static function get_title() {
112        return 'Jetpack Forms';
113    }
114
115    /**
116     * Get the internationalized product description
117     *
118     * @return string
119     */
120    public static function get_description() {
121        return __( 'Build and share forms to collect leads, feedback, and payments.', 'jetpack-my-jetpack' );
122    }
123
124    /**
125     * Get the internationalized product long description
126     *
127     * @return string
128     */
129    public static function get_long_description() {
130        return __( 'Create contact forms, surveys, and registration forms in minutes — then manage every response right from your dashboard, no third-party tools required.', 'jetpack-my-jetpack' );
131    }
132
133    /**
134     * Get the internationalized feature list
135     *
136     * @return array Forms features list
137     */
138    public static function get_features() {
139        return array(
140            __( 'Spam protection with Akismet', 'jetpack-my-jetpack' ),
141            __( 'Export your data anytime', 'jetpack-my-jetpack' ),
142            __( 'Manage all your responses in one place', 'jetpack-my-jetpack' ),
143        );
144    }
145
146    /**
147     * Get the product pricing details
148     *
149     * @return array Pricing details
150     */
151    public static function get_pricing_for_ui() {
152        return array(
153            'available' => true,
154            'is_free'   => true,
155        );
156    }
157
158    /**
159     * Checks whether the plugin is installed
160     *
161     * @return boolean
162     */
163    public static function is_plugin_installed() {
164        return static::is_jetpack_plugin_installed();
165    }
166
167    /**
168     * Get the URL where the user manages the product
169     *
170     * @return ?string
171     */
172    public static function get_manage_url() {
173        // Defer to the Forms package for the canonical admin URL when it's available
174        // (it accounts for the responses dashboard variant and the admin URL filter).
175        $dashboard = 'Automattic\Jetpack\Forms\Dashboard\Dashboard';
176        if ( method_exists( $dashboard, 'get_forms_admin_url' ) ) {
177            return $dashboard::get_forms_admin_url();
178        }
179
180        return admin_url( 'admin.php?page=jetpack-forms-admin' );
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}