Repository navigation
JITM: Sideload Jetpack Backup #21719
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
c036c18
JITM: New JITM conditions for sideloading Jetpack Backup plugin.
dereksmart a9a85fa
Changelogs
dereksmart 64c46ae
Fix typos
dereksmart 22e87df
Redirect to plugin search if install fails.
dereksmart dfe72e7
Add MC stat bump on install success or failure
dereksmart a746a73
Merge branch 'master' into add/jitm-sideload-backup-plugin
dereksmart 8029aca
Merge branch 'master' into add/jitm-sideload-backup-plugin
dereksmart 6b49755
Fix package versions
dereksmart d305751
Remove MC stats
dereksmart f5be24a
Use Jetpack_Options to update the referrer option.
dereksmart ef6af2a
Remove referred option. Probably not needed.
dereksmart 734ddab
Merge branch 'master' into add/jitm-sideload-backup-plugin
dereksmart File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
projects/packages/jitm/changelog/add-jitm-sideload-backup-plugin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| Significance: minor | ||
| Type: added | ||
|
|
||
| Adds filters to allow sideloading of the Jetpack Backup plugin through JITMs. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| <?php | ||
| /** | ||
| * Compatibility functions for the Jetpack Backup plugin. | ||
| * https://wordpress.org/plugins/jetpack-backup/ | ||
| * | ||
| * @since 10.4 | ||
| * | ||
| * @package automattic/jetpack | ||
| */ | ||
|
|
||
| namespace Automattic\Jetpack\Jetpack_Backup; | ||
|
|
||
| if ( ! defined( 'ABSPATH' ) ) { | ||
| exit; | ||
| } | ||
|
|
||
| const PLUGIN_SLUG = 'jetpack-backup'; | ||
| const PLUGIN_FILE = 'jetpack-backup/jetpack-backup.php'; | ||
|
|
||
| add_action( 'admin_notices', __NAMESPACE__ . '\error_notice' ); | ||
| add_action( 'admin_init', __NAMESPACE__ . '\try_install' ); | ||
| add_action( 'jetpack_activated_plugin', __NAMESPACE__ . '\configure_plugin', 10, 2 ); | ||
|
|
||
| /** | ||
| * Verify the intent to install Jetpack Backup, and kick off installation. | ||
| * | ||
| * This works in tandem with a JITM set up in the JITM package. | ||
| */ | ||
| function try_install() { | ||
| if ( ! isset( $_GET['jetpack-backup-action'] ) ) { | ||
| return; | ||
| } | ||
|
|
||
| check_admin_referer( 'jetpack-backup-install' ); | ||
|
|
||
| $result = false; | ||
| // If the plugin install fails, redirect to plugin install page pre-populated with jetpack-backup search term. | ||
| $redirect_on_error = admin_url( 'plugin-install.php?s=jetpack-backup&tab=search&type=term' ); | ||
|
|
||
| // Attempt to install and activate the plugin. | ||
| if ( current_user_can( 'activate_plugins' ) ) { | ||
| switch ( $_GET['jetpack-backup-action'] ) { | ||
| case 'install': | ||
| $result = install_and_activate(); | ||
| break; | ||
| case 'activate': | ||
| $result = activate(); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| $jetpack = \Jetpack::init(); | ||
| if ( $result ) { | ||
| /** This action is already documented in _inc/lib/class.core-rest-api-endpoints.php */ | ||
| do_action( 'jetpack_activated_plugin', PLUGIN_FILE, 'jitm' ); | ||
| $jetpack->stat( 'jitm-plugin-install', 'jetpack-backup-success' ); | ||
| $redirect = admin_url( 'admin.php?page=jetpack-backup' ); | ||
| } else { | ||
| $jetpack->stat( 'jitm-plugin-install', 'jetpack-backup-fail' ); | ||
| $redirect = add_query_arg( 'jetpack-backup-install-error', true, $redirect_on_error ); | ||
| } | ||
|
|
||
| wp_safe_redirect( $redirect ); | ||
|
|
||
| exit; | ||
| } | ||
|
|
||
| /** | ||
| * Install and activate the Jetpack Backup 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 Backup 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 Backup failed. | ||
| */ | ||
| function error_notice() { | ||
| if ( empty( $_GET['jetpack-backup-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 Backup. Please try again.', 'jetpack' ); ?></p> | ||
| </div> | ||
| <?php | ||
| } | ||
|
|
||
| /** | ||
| * Set some options when first activating the plugin via Jetpack. | ||
| * | ||
| * @since 8.9.0 | ||
| * | ||
| * @param string $plugin_file Plugin file. | ||
| * @param string $source Where did the plugin installation originate. | ||
| */ | ||
| function configure_plugin( $plugin_file, $source ) { | ||
| if ( PLUGIN_FILE !== $plugin_file ) { | ||
| return; | ||
| } | ||
|
|
||
| $plugin_info = array( | ||
| 'plugin' => 'jetpack', | ||
| 'version' => JETPACK__VERSION, | ||
| 'time' => time(), | ||
| 'source' => esc_attr( $source ), | ||
| ); | ||
|
|
||
| update_option( 'jetpack_backup_referred_by', $plugin_info ); | ||
|
dereksmart marked this conversation as resolved.
Resolved
|
||
| } | ||
4 changes: 4 additions & 0 deletions
4
projects/plugins/jetpack/changelog/add-jitm-sideload-backup-plugin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| Significance: minor | ||
| Type: compat | ||
|
|
||
| Jetpack Backup: Add considtions that allow sideloading of Jetpack Backup plugin via JITMs. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.