From c036c18139e514fa9e23a4f430f93dabfd6c4bd2 Mon Sep 17 00:00:00 2001 From: Derek Smart Date: Thu, 11 Nov 2021 15:53:16 -0500 Subject: [PATCH 1/9] JITM: New JITM conditions for sideloading Jetpack Backup plugin. --- .../jitm/src/class-post-connection-jitm.php | 38 ++++++ .../plugins/jetpack/3rd-party/3rd-party.php | 1 + .../jetpack/3rd-party/jetpack-backup.php | 128 ++++++++++++++++++ 3 files changed, 167 insertions(+) create mode 100644 projects/plugins/jetpack/3rd-party/jetpack-backup.php diff --git a/projects/packages/jitm/src/class-post-connection-jitm.php b/projects/packages/jitm/src/class-post-connection-jitm.php index 3d2bbc60f194..742491cba5c3 100644 --- a/projects/packages/jitm/src/class-post-connection-jitm.php +++ b/projects/packages/jitm/src/class-post-connection-jitm.php @@ -161,6 +161,40 @@ public static function jitm_jetpack_creative_mail_activate() { ); } + /** + * A special filter used in the CTA of a JITM offering to install the Creative Mail plugin. + * + * @return string The new CTA + */ + public static function jitm_jetpack_backup_install() { + return wp_nonce_url( + add_query_arg( + array( + 'jetpack-backup-action' => 'install', + ), + admin_url( 'admin.php?page=jetpack' ) + ), + 'jetpack-backup-install' + ); + } + + /** + * A special filter used in the CTA of a JITM offering to activate the Creative Mail plugin. + * + * @return string The new CTA + */ + public static function jitm_jetpack_backup_activate() { + return wp_nonce_url( + add_query_arg( + array( + 'jetpack-backup-action' => 'activate', + ), + admin_url( 'admin.php?page=jetpack' ) + ), + 'jetpack-backup-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. @@ -366,6 +400,10 @@ public function get_messages( $message_path, $query, $full_jp_logo_exists ) { add_filter( 'jitm_jetpack_creative_mail_install', array( $this, 'jitm_jetpack_creative_mail_install' ) ); add_filter( 'jitm_jetpack_creative_mail_activate', array( $this, 'jitm_jetpack_creative_mail_activate' ) ); + // Jetpack Backups. + add_filter( 'jitm_jetpack_backup_install', array( $this, 'jitm_jetpack_backup_install' ) ); + add_filter( 'jitm_jetpack_backup_activate', array( $this, 'jitm_jetpack_backup_activate' ) ); + $user = wp_get_current_user(); // Unauthenticated or invalid requests just bail. diff --git a/projects/plugins/jetpack/3rd-party/3rd-party.php b/projects/plugins/jetpack/3rd-party/3rd-party.php index dc84bba3d41b..c8c6dd8d768a 100644 --- a/projects/plugins/jetpack/3rd-party/3rd-party.php +++ b/projects/plugins/jetpack/3rd-party/3rd-party.php @@ -24,6 +24,7 @@ function load_3rd_party() { 'class-jetpack-crm-data.php', 'class-jetpack-modules-overrides.php', // Special case. Tools to be used to override module settings. 'creative-mail.php', + 'jetpack-backup.php', 'debug-bar.php', 'class-domain-mapping.php', 'crowdsignal.php', diff --git a/projects/plugins/jetpack/3rd-party/jetpack-backup.php b/projects/plugins/jetpack/3rd-party/jetpack-backup.php new file mode 100644 index 000000000000..87a91d5b94c7 --- /dev/null +++ b/projects/plugins/jetpack/3rd-party/jetpack-backup.php @@ -0,0 +1,128 @@ + +
+

+
+ 'jetpack', + 'version' => JETPACK__VERSION, + 'time' => time(), + 'source' => esc_attr( $source ), + ); + + update_option( 'jetpack_backup_referred_by', $plugin_info ); +} From a9a85fae64ce1856fb14469ef53ed535234ea939 Mon Sep 17 00:00:00 2001 From: Derek Smart Date: Thu, 11 Nov 2021 16:02:53 -0500 Subject: [PATCH 2/9] Changelogs --- .../packages/jitm/changelog/add-jitm-sideload-backup-plugin | 4 ++++ .../plugins/jetpack/changelog/add-jitm-sideload-backup-plugin | 4 ++++ 2 files changed, 8 insertions(+) create mode 100644 projects/packages/jitm/changelog/add-jitm-sideload-backup-plugin create mode 100644 projects/plugins/jetpack/changelog/add-jitm-sideload-backup-plugin diff --git a/projects/packages/jitm/changelog/add-jitm-sideload-backup-plugin b/projects/packages/jitm/changelog/add-jitm-sideload-backup-plugin new file mode 100644 index 000000000000..cff1da4a8e0b --- /dev/null +++ b/projects/packages/jitm/changelog/add-jitm-sideload-backup-plugin @@ -0,0 +1,4 @@ +Significance: minor +Type: added + +Adds filters to allow sideloading of the Jetpack Backup plugin through JITMs. diff --git a/projects/plugins/jetpack/changelog/add-jitm-sideload-backup-plugin b/projects/plugins/jetpack/changelog/add-jitm-sideload-backup-plugin new file mode 100644 index 000000000000..cd6e1f2b3b34 --- /dev/null +++ b/projects/plugins/jetpack/changelog/add-jitm-sideload-backup-plugin @@ -0,0 +1,4 @@ +Significance: minor +Type: compat + +Jetpack Backup: Add considtions that allow sideloading of Jetpack Backup plugin via JITMs. From 64c46ae1f331cd025f2babf32e879c61ed3b7802 Mon Sep 17 00:00:00 2001 From: Derek Smart Date: Tue, 23 Nov 2021 11:33:29 -0500 Subject: [PATCH 3/9] Fix typos --- projects/packages/jitm/src/class-post-connection-jitm.php | 6 +++--- projects/plugins/jetpack/3rd-party/jetpack-backup.php | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/projects/packages/jitm/src/class-post-connection-jitm.php b/projects/packages/jitm/src/class-post-connection-jitm.php index 742491cba5c3..8a2d1a2684f8 100644 --- a/projects/packages/jitm/src/class-post-connection-jitm.php +++ b/projects/packages/jitm/src/class-post-connection-jitm.php @@ -162,7 +162,7 @@ public static function jitm_jetpack_creative_mail_activate() { } /** - * A special filter used in the CTA of a JITM offering to install the Creative Mail plugin. + * A special filter used in the CTA of a JITM offering to install the Jetpack Backup plugin. * * @return string The new CTA */ @@ -179,7 +179,7 @@ public static function jitm_jetpack_backup_install() { } /** - * A special filter used in the CTA of a JITM offering to activate the Creative Mail plugin. + * A special filter used in the CTA of a JITM offering to activate the Jetpack Backup plugin. * * @return string The new CTA */ @@ -400,7 +400,7 @@ public function get_messages( $message_path, $query, $full_jp_logo_exists ) { add_filter( 'jitm_jetpack_creative_mail_install', array( $this, 'jitm_jetpack_creative_mail_install' ) ); add_filter( 'jitm_jetpack_creative_mail_activate', array( $this, 'jitm_jetpack_creative_mail_activate' ) ); - // Jetpack Backups. + // Jetpack Backup. add_filter( 'jitm_jetpack_backup_install', array( $this, 'jitm_jetpack_backup_install' ) ); add_filter( 'jitm_jetpack_backup_activate', array( $this, 'jitm_jetpack_backup_activate' ) ); diff --git a/projects/plugins/jetpack/3rd-party/jetpack-backup.php b/projects/plugins/jetpack/3rd-party/jetpack-backup.php index 87a91d5b94c7..ea9cfeb306c7 100644 --- a/projects/plugins/jetpack/3rd-party/jetpack-backup.php +++ b/projects/plugins/jetpack/3rd-party/jetpack-backup.php @@ -22,7 +22,7 @@ add_action( 'jetpack_activated_plugin', __NAMESPACE__ . '\configure_plugin', 10, 2 ); /** - * Verify the intent to install Jetpack Backupl, and kick off installation. + * Verify the intent to install Jetpack Backup, and kick off installation. * * This works in tandem with a JITM set up in the JITM package. */ @@ -34,10 +34,10 @@ function try_install() { check_admin_referer( 'jetpack-backup-install' ); $result = false; - $redirect = admin_url( 'edit.php?post_type=feedback' ); + $redirect = admin_url( 'admin.php?page=jetpack' ); // Attempt to install and activate the plugin. - if ( current_user_can( 'activate_plugins' ) ) { + if ( false && current_user_can( 'activate_plugins' ) ) { switch ( $_GET['jetpack-backup-action'] ) { case 'install': $result = install_and_activate(); From 22e87dfe9fe48d2b5c9749aa5209a950997379b0 Mon Sep 17 00:00:00 2001 From: Derek Smart Date: Tue, 23 Nov 2021 11:42:19 -0500 Subject: [PATCH 4/9] Redirect to plugin search if install fails. --- projects/plugins/jetpack/3rd-party/jetpack-backup.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/projects/plugins/jetpack/3rd-party/jetpack-backup.php b/projects/plugins/jetpack/3rd-party/jetpack-backup.php index ea9cfeb306c7..b2b9caa2cb01 100644 --- a/projects/plugins/jetpack/3rd-party/jetpack-backup.php +++ b/projects/plugins/jetpack/3rd-party/jetpack-backup.php @@ -34,10 +34,11 @@ function try_install() { check_admin_referer( 'jetpack-backup-install' ); $result = false; - $redirect = admin_url( 'admin.php?page=jetpack' ); + // 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 ( false && current_user_can( 'activate_plugins' ) ) { + if ( current_user_can( 'activate_plugins' ) ) { switch ( $_GET['jetpack-backup-action'] ) { case 'install': $result = install_and_activate(); @@ -53,7 +54,7 @@ function try_install() { do_action( 'jetpack_activated_plugin', PLUGIN_FILE, 'jitm' ); $redirect = admin_url( 'admin.php?page=jetpack-backup' ); } else { - $redirect = add_query_arg( 'jetpack-backup-install-error', true, $redirect ); + $redirect = add_query_arg( 'jetpack-backup-install-error', true, $redirect_on_error ); } wp_safe_redirect( $redirect ); From dfe72e75052f617fbf8b97f25a9ea31be4a1b392 Mon Sep 17 00:00:00 2001 From: Derek Smart Date: Tue, 23 Nov 2021 12:46:52 -0500 Subject: [PATCH 5/9] Add MC stat bump on install success or failure --- projects/plugins/jetpack/3rd-party/jetpack-backup.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/projects/plugins/jetpack/3rd-party/jetpack-backup.php b/projects/plugins/jetpack/3rd-party/jetpack-backup.php index b2b9caa2cb01..e0c6a3317819 100644 --- a/projects/plugins/jetpack/3rd-party/jetpack-backup.php +++ b/projects/plugins/jetpack/3rd-party/jetpack-backup.php @@ -33,7 +33,7 @@ function try_install() { check_admin_referer( 'jetpack-backup-install' ); - $result = false; + $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' ); @@ -49,11 +49,14 @@ function try_install() { } } + $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 ); } @@ -100,7 +103,7 @@ function error_notice() { ?>
-

+

Date: Tue, 23 Nov 2021 13:03:55 -0500 Subject: [PATCH 6/9] Fix package versions --- projects/packages/jitm/composer.json | 2 +- projects/packages/jitm/src/class-jitm.php | 2 +- .../jetpack/changelog/add-jitm-sideload-backup-plugin#2 | 4 ++++ projects/plugins/jetpack/composer.json | 2 +- projects/plugins/jetpack/composer.lock | 6 +++--- 5 files changed, 10 insertions(+), 6 deletions(-) create mode 100644 projects/plugins/jetpack/changelog/add-jitm-sideload-backup-plugin#2 diff --git a/projects/packages/jitm/composer.json b/projects/packages/jitm/composer.json index 7970580b3afc..05f75e7f3273 100644 --- a/projects/packages/jitm/composer.json +++ b/projects/packages/jitm/composer.json @@ -67,7 +67,7 @@ "link-template": "https://github.com/Automattic/jetpack-jitm/compare/v${old}...v${new}" }, "branch-alias": { - "dev-master": "2.0.x-dev" + "dev-master": "2.1.x-dev" } } } diff --git a/projects/packages/jitm/src/class-jitm.php b/projects/packages/jitm/src/class-jitm.php index d77cc3aae6a6..7f7f6333ea77 100644 --- a/projects/packages/jitm/src/class-jitm.php +++ b/projects/packages/jitm/src/class-jitm.php @@ -20,7 +20,7 @@ */ class JITM { - const PACKAGE_VERSION = '2.0.8'; + const PACKAGE_VERSION = '2.1.0-alpha'; /** * The configuration method that is called from the jetpack-config package. diff --git a/projects/plugins/jetpack/changelog/add-jitm-sideload-backup-plugin#2 b/projects/plugins/jetpack/changelog/add-jitm-sideload-backup-plugin#2 new file mode 100644 index 000000000000..1eaea6a769e8 --- /dev/null +++ b/projects/plugins/jetpack/changelog/add-jitm-sideload-backup-plugin#2 @@ -0,0 +1,4 @@ +Significance: patch +Type: other + +Updated package dependencies. diff --git a/projects/plugins/jetpack/composer.json b/projects/plugins/jetpack/composer.json index 26824bd96412..17986aae2699 100644 --- a/projects/plugins/jetpack/composer.json +++ b/projects/plugins/jetpack/composer.json @@ -26,7 +26,7 @@ "automattic/jetpack-error": "1.3.x-dev", "automattic/jetpack-heartbeat": "1.3.x-dev", "automattic/jetpack-identity-crisis": "0.4.x-dev", - "automattic/jetpack-jitm": "2.0.x-dev", + "automattic/jetpack-jitm": "2.1.x-dev", "automattic/jetpack-lazy-images": "2.0.x-dev", "automattic/jetpack-licensing": "1.5.x-dev", "automattic/jetpack-logo": "1.5.x-dev", diff --git a/projects/plugins/jetpack/composer.lock b/projects/plugins/jetpack/composer.lock index 19d1b1a051f9..69c866b13222 100644 --- a/projects/plugins/jetpack/composer.lock +++ b/projects/plugins/jetpack/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "2145ecdbbd72d981d6667cd908f08e30", + "content-hash": "0be3edf262cfcfe2d899e5a136e8415a", "packages": [ { "name": "automattic/jetpack-a8c-mc-stats", @@ -870,7 +870,7 @@ "dist": { "type": "path", "url": "../../packages/jitm", - "reference": "f72b99550e4c894841a5b070a518e677cd162a1f" + "reference": "54ee594e9f467dd332ed584d435cf2c0d4e42a6b" }, "require": { "automattic/jetpack-a8c-mc-stats": "^1.4", @@ -900,7 +900,7 @@ "link-template": "https://github.com/Automattic/jetpack-jitm/compare/v${old}...v${new}" }, "branch-alias": { - "dev-master": "2.0.x-dev" + "dev-master": "2.1.x-dev" } }, "autoload": { From d3057514403debbb9f16f864f2aea01f1af7de8f Mon Sep 17 00:00:00 2001 From: Derek Smart Date: Tue, 23 Nov 2021 13:10:16 -0500 Subject: [PATCH 7/9] Remove MC stats --- projects/plugins/jetpack/3rd-party/jetpack-backup.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/projects/plugins/jetpack/3rd-party/jetpack-backup.php b/projects/plugins/jetpack/3rd-party/jetpack-backup.php index e0c6a3317819..95adb53690c4 100644 --- a/projects/plugins/jetpack/3rd-party/jetpack-backup.php +++ b/projects/plugins/jetpack/3rd-party/jetpack-backup.php @@ -49,14 +49,11 @@ function try_install() { } } - $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 ); } From f5be24a0b3c70465ac335a3f8f48d4fb1db892fe Mon Sep 17 00:00:00 2001 From: Derek Smart Date: Tue, 23 Nov 2021 13:14:20 -0500 Subject: [PATCH 8/9] Use Jetpack_Options to update the referrer option. --- projects/plugins/jetpack/3rd-party/jetpack-backup.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/plugins/jetpack/3rd-party/jetpack-backup.php b/projects/plugins/jetpack/3rd-party/jetpack-backup.php index 95adb53690c4..3d505723894d 100644 --- a/projects/plugins/jetpack/3rd-party/jetpack-backup.php +++ b/projects/plugins/jetpack/3rd-party/jetpack-backup.php @@ -108,7 +108,7 @@ function error_notice() { /** * Set some options when first activating the plugin via Jetpack. * - * @since 8.9.0 + * @since 10.4.0 * * @param string $plugin_file Plugin file. * @param string $source Where did the plugin installation originate. @@ -125,5 +125,5 @@ function configure_plugin( $plugin_file, $source ) { 'source' => esc_attr( $source ), ); - update_option( 'jetpack_backup_referred_by', $plugin_info ); + \Jetpack_Options::update_option( 'jetpack_backup_referred_by', $plugin_info ); } From ef6af2a5eb9bed9f3967ec34f2338ee52e0e259a Mon Sep 17 00:00:00 2001 From: Derek Smart Date: Tue, 23 Nov 2021 13:21:14 -0500 Subject: [PATCH 9/9] Remove referred option. Probably not needed. --- .../jetpack/3rd-party/jetpack-backup.php | 24 ------------------- 1 file changed, 24 deletions(-) diff --git a/projects/plugins/jetpack/3rd-party/jetpack-backup.php b/projects/plugins/jetpack/3rd-party/jetpack-backup.php index 3d505723894d..ec1880b3a181 100644 --- a/projects/plugins/jetpack/3rd-party/jetpack-backup.php +++ b/projects/plugins/jetpack/3rd-party/jetpack-backup.php @@ -19,7 +19,6 @@ 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. @@ -104,26 +103,3 @@ function error_notice() { 'jetpack', - 'version' => JETPACK__VERSION, - 'time' => time(), - 'source' => esc_attr( $source ), - ); - - \Jetpack_Options::update_option( 'jetpack_backup_referred_by', $plugin_info ); -}