debug-bar
4 years ago
3rd-party.php
3 years ago
bbpress.php
4 years ago
beaverbuilder.php
5 years ago
bitly.php
3 years ago
buddypress.php
5 years ago
class-domain-mapping.php
4 years ago
class-jetpack-bbpress-rest-api.php
3 years ago
class-jetpack-crm-data.php
3 years ago
class-jetpack-modules-overrides.php
4 years ago
class-salesforce-lead-form.php
3 years ago
class.jetpack-amp-support.php
3 years ago
creative-mail.php
4 years ago
crowdsignal.php
5 years ago
debug-bar.php
5 years ago
jetpack-backup.php
4 years ago
jetpack-boost.php
4 years ago
qtranslate-x.php
5 years ago
vaultpress.php
5 years ago
web-stories.php
5 years ago
woocommerce-services.php
4 years ago
woocommerce.php
5 years ago
wpml.php
5 years ago
jetpack-boost.php
107 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Compatibility functions for the Jetpack Boost plugin. |
| 4 | * https://wordpress.org/plugins/jetpack-boost/ |
| 5 | * |
| 6 | * @since 10.4 |
| 7 | * |
| 8 | * @package automattic/jetpack |
| 9 | */ |
| 10 | |
| 11 | namespace Automattic\Jetpack\Jetpack_Boost; |
| 12 | |
| 13 | use Automattic\Jetpack\Plugins_Installer; |
| 14 | |
| 15 | if ( ! defined( 'ABSPATH' ) ) { |
| 16 | exit; |
| 17 | } |
| 18 | |
| 19 | const PLUGIN_SLUG = 'jetpack-boost'; |
| 20 | const PLUGIN_FILE = 'jetpack-boost/jetpack-boost.php'; |
| 21 | |
| 22 | add_action( 'admin_notices', __NAMESPACE__ . '\error_notice' ); |
| 23 | add_action( 'admin_init', __NAMESPACE__ . '\try_install' ); |
| 24 | |
| 25 | /** |
| 26 | * Verify the intent to install Jetpack Boost, and kick off installation. |
| 27 | * |
| 28 | * This works in tandem with a JITM set up in the JITM package. |
| 29 | */ |
| 30 | function try_install() { |
| 31 | if ( ! isset( $_GET['jetpack-boost-action'] ) ) { |
| 32 | return; |
| 33 | } |
| 34 | |
| 35 | check_admin_referer( 'jetpack-boost-install' ); |
| 36 | |
| 37 | $result = false; |
| 38 | // If the plugin install fails, redirect to plugin install page pre-populated with jetpack-boost search term. |
| 39 | $redirect_on_error = admin_url( 'plugin-install.php?s=jetpack-boost&tab=search&type=term' ); |
| 40 | |
| 41 | // Attempt to install and activate the plugin. |
| 42 | if ( current_user_can( 'activate_plugins' ) ) { |
| 43 | switch ( $_GET['jetpack-boost-action'] ) { |
| 44 | case 'install': |
| 45 | $result = install_and_activate(); |
| 46 | break; |
| 47 | case 'activate': |
| 48 | $result = activate(); |
| 49 | break; |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | if ( $result ) { |
| 54 | /** This action is already documented in _inc/lib/class.core-rest-api-endpoints.php */ |
| 55 | do_action( 'jetpack_activated_plugin', PLUGIN_FILE, 'jitm' ); |
| 56 | $redirect = admin_url( 'admin.php?page=jetpack-boost' ); |
| 57 | } else { |
| 58 | $redirect = add_query_arg( 'jetpack-boost-install-error', true, $redirect_on_error ); |
| 59 | } |
| 60 | |
| 61 | wp_safe_redirect( $redirect ); |
| 62 | |
| 63 | exit; |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Install and activate the Jetpack Boost plugin. |
| 68 | * |
| 69 | * @return bool result of installation |
| 70 | */ |
| 71 | function install_and_activate() { |
| 72 | $result = Plugins_Installer::install_and_activate_plugin( PLUGIN_SLUG ); |
| 73 | |
| 74 | if ( is_wp_error( $result ) ) { |
| 75 | return false; |
| 76 | } else { |
| 77 | return true; |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Activate the Jetpack Boost plugin. |
| 83 | * |
| 84 | * @return bool result of activation |
| 85 | */ |
| 86 | function activate() { |
| 87 | $result = activate_plugin( PLUGIN_FILE ); |
| 88 | |
| 89 | // Activate_plugin() returns null on success. |
| 90 | return $result === null; |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Notify the user that the installation of Jetpack Boost failed. |
| 95 | */ |
| 96 | function error_notice() { |
| 97 | if ( empty( $_GET['jetpack-boost-install-error'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 98 | return; |
| 99 | } |
| 100 | |
| 101 | ?> |
| 102 | <div class="notice notice-error is-dismissible"> |
| 103 | <p><?php esc_html_e( 'There was an error installing Jetpack Boost. Please try again.', 'jetpack' ); ?></p> |
| 104 | </div> |
| 105 | <?php |
| 106 | } |
| 107 |