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