Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 33
0.00% covered (danger)
0.00%
0 / 10
CRAP
0.00% covered (danger)
0.00%
0 / 1
Plugins
0.00% covered (danger)
0.00%
0 / 33
0.00% covered (danger)
0.00%
0 / 10
132
0.00% covered (danger)
0.00%
0 / 1
 get_wp_slugs
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 get_urls
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 get_domains
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 get_status_codes
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 get
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
2
 get_squashed
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 get_approved
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
2
 check_approved
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 wc_prevent_redirect_on_activation
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 toggle_jetpack_module
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2namespace NewfoldLabs\WP\Module\Installer\Data;
3
4/**
5 * List of Plugin Slugs/URLs/Domains
6 */
7final class Plugins {
8    /**
9     * A value of true indicates that the slug/url/domain has been approved.
10     * A value of null indicates that the slug/url/domain has not been approved
11     * (or) has been temporarily deactivated.
12     *
13     * @var array
14     */
15    protected static $wp_slugs = array(
16        'jetpack'                           => array(
17            'approved' => true,
18            'path'     => 'jetpack/jetpack.php',
19        ),
20        'jetpack-boost'                     => array(
21            'approved' => true,
22            'path'     => 'jetpack-boost/jetpack-boost.php',
23        ),
24        'jetpack-protect'                   => array(
25            'approved' => true,
26            'path'     => 'jetpack-protect/jetpack-protect.php',
27        ),
28        'woocommerce'                       => array(
29            'approved'              => true,
30            'path'                  => 'woocommerce/woocommerce.php',
31            'post_install_callback' => array( __CLASS__, 'wc_prevent_redirect_on_activation' ),
32        ),
33        'wordpress-seo'                     => array(
34            'approved' => true,
35            'path'     => 'wordpress-seo/wp-seo.php',
36        ),
37        'wpforms-lite'                      => array(
38            'approved' => true,
39            'path'     => 'wpforms-lite/wpforms.php',
40        ),
41        'google-analytics-for-wordpress'    => array(
42            'approved' => true,
43            'path'     => 'google-analytics-for-wordpress/googleanalytics.php',
44        ),
45        'optinmonster'                      => array(
46            'approved' => true,
47            'path'     => 'optinmonster/optin-monster-wp-api.php',
48        ),
49        'yith-woocommerce-ajax-search'      => array(
50            'approved' => true,
51            'path'     => 'yith-woocommerce-ajax-search/init.php',
52        ),
53        'creative-mail-by-constant-contact' => array(
54            'approved' => true,
55            'path'     => 'creative-mail-by-constant-contact/creative-mail-plugin.php',
56        ),
57    );
58
59    /**
60     * Contains a list of zip url's with a unique "nfd_slug" for each.
61     *
62     * @var array
63     */
64    protected static $nfd_slugs = array(
65        'nfd_slug_endurance_page_cache'                  => array(
66            'approved' => true,
67            'url'      => 'https://raw.githubusercontent.com/bluehost/endurance-page-cache/production/endurance-page-cache.php',
68            'path'     => WP_CONTENT_DIR . '/mu-plugins/endurance-page-cache.php',
69        ),
70        'nfd_slug_yith_woocommerce_customize_myaccount_page' => array(
71            'approved' => true,
72            'url'      => 'https://hiive.cloud/workers/plugin-downloads/yith-woocommerce-customize-myaccount-page',
73            'path'     => 'yith-woocommerce-customize-myaccount-page-extended/init.php',
74        ),
75        'nfd_slug_yith_woocommerce_gift_cards'           => array(
76            'approved' => true,
77            'url'      => 'https://hiive.cloud/workers/plugin-downloads/yith-woocommerce-gift-cards',
78            'path'     => 'yith-woocommerce-gift-cards-extended/init.php',
79        ),
80        'nfd_slug_ecomdash_wordpress_plugin'             => array(
81            'approved' => true,
82            'url'      => 'https://hiive.cloud/workers/plugin-downloads/ecomdash-wordpress-plugin',
83            'path'     => 'ecomdash-wordpress-plugin/ecomdash-plugin.php',
84        ),
85        'nfd_slug_yith_paypal_payments_for_woocommerce'  => array(
86            'approved' => true,
87            'url'      => 'https://hiive.cloud/workers/plugin-downloads/yith-paypal-payments-for-woocommerce',
88            'path'     => 'yith-paypal-payments-for-woocommerce-extended/init.php',
89        ),
90        'nfd_slug_yith_shippo_shippings_for_woocommerce' => array(
91            'approved' => true,
92            'url'      => 'https://hiive.cloud/workers/plugin-downloads/yith-shippo-shippings-for-woocommerce',
93            'path'     => 'yith-shippo-shippings-for-woocommerce-extended/init.php',
94        ),
95        'nfd_slug_yith_woocommerce_ajax_product_filter'  => array(
96            'approved' => true,
97            'url'      => 'https://hiive.cloud/workers/plugin-downloads/yith-woocommerce-ajax-product-filter',
98            'path'     => 'yith-woocommerce-ajax-product-filter-extended/init.php',
99        ),
100        'nfd_slug_yith_woocommerce_booking'              => array(
101            'approved' => true,
102            'url'      => 'https://hiive.cloud/workers/plugin-downloads/yith-woocommerce-booking',
103            'path'     => 'yith-woocommerce-booking-extended/init.php',
104        ),
105        'nfd_slug_yith_woocommerce_wishlist'             => array(
106            'approved' => true,
107            'url'      => 'https://hiive.cloud/workers/plugin-downloads/yith-woocommerce-wishlist',
108            'path'     => 'yith-woocommerce-wishlist-extended/init.php',
109        ),
110        'nfd_slug_woo_razorpay'                          => array(
111            'approved' => true,
112            'url'      => 'https://hiive.cloud/workers/plugin-downloads/razorpay',
113            'path'     => 'woo-razorpay/woo-razorpay.php',
114        ),
115        'nfd_slug_wonder_cart'                           => array(
116            'approved' => true,
117            'url'      => 'https://hiive.cloud/workers/plugin-downloads/wonder-cart',
118            'path'     => 'wonder-cart/init.php',
119        ),
120        'nfd_slug_yith_stripe_payments_for_woocommerce'  => array(
121            'approved' => true,
122            'url'      => 'https://hiive.cloud/workers/plugin-downloads/yith-stripe-payments-for-woocommerce',
123            'path'     => 'yith-stripe-payments-for-woocommerce-extended/init.php',
124        ),
125    );
126
127    // [TODO] Think about deprecating this approach and move to nfd_slugs for url based installs.
128    /**
129     * Contains a whitelist of zip url's.
130     *
131     * @var array
132     */
133    protected static $urls = array(
134        'https://downloads.wordpress.org/plugin/google-analytics-for-wordpress.8.5.3.zip' => true,
135    );
136    /**
137     * Contains a list of approved domains for zip based installs.
138     *
139     * @var array
140     */
141    protected static $domains = array(
142        'downloads.wordpress.org' => true,
143        'nonapproveddomain.com'   => null,
144        'hiive.cloud'             => true,
145    );
146    /**
147     * Holds the possible status codes for a plugin.
148     *
149     * @var array $status_codes Possible plugin status codes including:
150     *     'unknown'       - The plugin's status cannot be determined.
151     *     'installed'     - The plugin is installed but not activated.
152     *     'active'        - The plugin is installed and active.
153     *     'not_installed' - The plugin is not installed on the system.
154     */
155    protected static $status_codes = array(
156        'unknown'       => 'unknown',
157        'installed'     => 'installed',
158        'active'        => 'active',
159        'not_installed' => 'not_installed',
160    );
161
162    /**
163     * Returns a list of whitelisted WordPress Plugin slugs.
164     *
165     * @return array
166     */
167    public static function get_wp_slugs() {
168        return self::$wp_slugs;
169    }
170
171    /**
172     * Returns a list of whitelisted Plugin URL's.
173     *
174     * @return array
175     */
176    public static function get_urls() {
177        return self::$urls;
178    }
179
180    /**
181     * Returns a list of whitelisted Plugin URL domains.
182     *
183     * @return array
184     */
185    public static function get_domains() {
186        return self::$domains;
187    }
188
189    /**
190     * Retrieves the array of plugin status codes.
191     *
192     * @return array
193     */
194    public static function get_status_codes() {
195        return self::$status_codes;
196    }
197
198    /**
199     * Use this return value for a faster search of slug/url/domain.
200     *
201     * @return array
202     */
203    public static function get() {
204        return array(
205            'wp_slugs'     => self::$wp_slugs,
206            'nfd_slugs'    => self::$nfd_slugs,
207            'urls'         => self::$urls,
208            'domains'      => self::$domains,
209            'status_codes' => self::$status_codes,
210        );
211    }
212
213    /**
214     * Use this for finding the path for installed plugins.
215     *
216     * @return array
217     */
218    public static function get_squashed() {
219        return array_merge(
220            array_filter( self::$wp_slugs, array( __CLASS__, 'check_approved' ) ),
221            array_filter( self::$nfd_slugs, array( __CLASS__, 'check_approved' ) )
222        );
223    }
224
225    /**
226     * Get approved slugs/urls/domains
227     *
228     * @return array
229     */
230    public static function get_approved() {
231        return array(
232            'wp_slugs'  => array_keys( array_filter( self::$wp_slugs, array( __CLASS__, 'check_approved' ) ) ),
233            'nfd_slugs' => array_keys( array_filter( self::$nfd_slugs, array( __CLASS__, 'check_approved' ) ) ),
234            'urls'      => array_keys( self::$urls, true, true ),
235            'domains'   => array_keys( self::$domains, true, true ),
236        );
237    }
238
239    /**
240     * Checks if a Plugin slug has been approved.
241     *
242     * @param array $value The Plugin slug that will be checked.
243     * @return boolean
244     */
245    private static function check_approved( $value ) {
246        return true === $value['approved'];
247    }
248
249    /**
250     * Prevent redirect to woo wizard after activation of woocommerce.
251     *
252     * @return void
253     */
254    public static function wc_prevent_redirect_on_activation() {
255        delete_transient( '_wc_activation_redirect' );
256    }
257
258    /**
259     * Activate or Deactivate Jetpack modules.
260     *
261     * @param string $module the name of the module to activate
262     * @param string $active the status of the module, pass true to activate and false to deactivate
263     *
264     * @return boolean
265     */
266    public static function toggle_jetpack_module( $module, $active = true ) {
267        $request = new \WP_REST_Request(
268            'POST',
269            '/jetpack/v4/settings'
270        );
271        $request->set_header( 'Content-Type', 'application/json' );
272        $request->set_body( wp_json_encode( array( $module => $active ) ) );
273        $response = rest_do_request( $request );
274
275        if ( 200 !== $response->status ) {
276            return false;
277        }
278        return true;
279    }
280}