Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

JITM: Added ability to sideload Jetpack Boost plugin.
38 changes: 38 additions & 0 deletions projects/packages/jitm/src/class-post-connection-jitm.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,40 @@ public static function jitm_jetpack_backup_activate() {
);
}

/**
* A special filter used in the CTA of a JITM offering to install the Jetpack Boost plugin.
*
* @return string The new CTA
*/
public static function jitm_jetpack_boost_install() {
return wp_nonce_url(
add_query_arg(
array(
'jetpack-boost-action' => 'install',
),
admin_url( 'admin.php?page=jetpack' )
),
'jetpack-boost-install'
);
}

/**
* A special filter used in the CTA of a JITM offering to activate the Jetpack Boost plugin.
*
* @return string The new CTA
*/
public static function jitm_jetpack_boost_activate() {
return wp_nonce_url(
add_query_arg(
array(
'jetpack-boost-action' => 'activate',
),
admin_url( 'admin.php?page=jetpack' )
),
'jetpack-boost-install'
);
}

/**
* This is an entire admin notice dedicated to messaging and handling of the case where a user is trying to delete
* the connection owner.
Expand Down Expand Up @@ -404,6 +438,10 @@ public function get_messages( $message_path, $query, $full_jp_logo_exists ) {
add_filter( 'jitm_jetpack_backup_install', array( $this, 'jitm_jetpack_backup_install' ) );
add_filter( 'jitm_jetpack_backup_activate', array( $this, 'jitm_jetpack_backup_activate' ) );

// Jetpack Boost.
add_filter( 'jitm_jetpack_boost_install', array( $this, 'jitm_jetpack_boost_install' ) );
add_filter( 'jitm_jetpack_boost_activate', array( $this, 'jitm_jetpack_boost_activate' ) );

$user = wp_get_current_user();

// Unauthenticated or invalid requests just bail.
Expand Down
1 change: 1 addition & 0 deletions projects/plugins/jetpack/3rd-party/3rd-party.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function load_3rd_party() {
'class-jetpack-modules-overrides.php', // Special case. Tools to be used to override module settings.
'creative-mail.php',
'jetpack-backup.php',
'jetpack-boost.php',
'debug-bar.php',
'class-domain-mapping.php',
'crowdsignal.php',
Expand Down
105 changes: 105 additions & 0 deletions projects/plugins/jetpack/3rd-party/jetpack-boost.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?php
/**
* Compatibility functions for the Jetpack Boost plugin.
* https://wordpress.org/plugins/jetpack-boost/
*
* @since 10.4
*
* @package automattic/jetpack
*/

namespace Automattic\Jetpack\Jetpack_Boost;

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

const PLUGIN_SLUG = 'jetpack-boost';
const PLUGIN_FILE = 'jetpack-boost/jetpack-boost.php';

add_action( 'admin_notices', __NAMESPACE__ . '\error_notice' );
add_action( 'admin_init', __NAMESPACE__ . '\try_install' );

/**
* Verify the intent to install Jetpack Boost, and kick off installation.
*
* This works in tandem with a JITM set up in the JITM package.
*/
function try_install() {
if ( ! isset( $_GET['jetpack-boost-action'] ) ) {
return;
}

check_admin_referer( 'jetpack-boost-install' );

$result = false;
// If the plugin install fails, redirect to plugin install page pre-populated with jetpack-boost search term.
$redirect_on_error = admin_url( 'plugin-install.php?s=jetpack-boost&tab=search&type=term' );

// Attempt to install and activate the plugin.
if ( current_user_can( 'activate_plugins' ) ) {
switch ( $_GET['jetpack-boost-action'] ) {
case 'install':
$result = install_and_activate();
break;
case 'activate':
$result = activate();
break;
}
}

if ( $result ) {
/** This action is already documented in _inc/lib/class.core-rest-api-endpoints.php */
do_action( 'jetpack_activated_plugin', PLUGIN_FILE, 'jitm' );
$redirect = admin_url( 'admin.php?page=jetpack-boost' );
} else {
$redirect = add_query_arg( 'jetpack-boost-install-error', true, $redirect_on_error );
}

wp_safe_redirect( $redirect );

exit;
}

/**
* Install and activate the Jetpack Boost plugin.
*
* @return bool result of installation
*/
function install_and_activate() {
jetpack_require_lib( 'plugins' );
$result = \Jetpack_Plugins::install_and_activate_plugin( PLUGIN_SLUG );

if ( is_wp_error( $result ) ) {
return false;
} else {
return true;
}
}

/**
* Activate the Jetpack Boost plugin.
*
* @return bool result of activation
*/
function activate() {
$result = activate_plugin( PLUGIN_FILE );

// Activate_plugin() returns null on success.
return is_null( $result );
}

/**
* Notify the user that the installation of Jetpack Boost failed.
*/
function error_notice() {
if ( empty( $_GET['jetpack-boost-install-error'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
return;
}

?>
<div class="notice notice-error is-dismissible">
<p><?php esc_html_e( 'There was an error installing Jetpack Boost. Please try again.', 'jetpack' ); ?></p>
</div>
<?php
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: other

JITM: Added ability to sideload Jetpack Boost plugin.