From 98f1b9a822e163c875f063b08ba09dca50de72ab Mon Sep 17 00:00:00 2001 From: arunshenoy99 Date: Tue, 14 Jan 2025 22:37:16 +0530 Subject: [PATCH] Add locale to migration redirect --- includes/Services/InstaMigrateService.php | 38 ++++++++++++++++------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/includes/Services/InstaMigrateService.php b/includes/Services/InstaMigrateService.php index 53944ba..a69b871 100644 --- a/includes/Services/InstaMigrateService.php +++ b/includes/Services/InstaMigrateService.php @@ -14,14 +14,14 @@ class InstaMigrateService { /** * InstaWP Connect plugin slug used for installing the instaWP plugin once * - * @var $connect_plugin_slug + * @var string $connect_plugin_slug */ private $connect_plugin_slug = 'instawp-connect'; /** * InstaWP Connect plugin API key used for connecting the instaWP plugin * - * @var $insta_api_key + * @var string $insta_api_key */ private $insta_api_key = ''; @@ -33,7 +33,7 @@ class InstaMigrateService { private $count = 0; /** - * Set required api keys for insta to initiate the migration + * Set required API keys for insta to initiate the migration */ public function __construct() { $encrypt = new Encryption(); @@ -51,6 +51,7 @@ public function install_instawp_connect() { if ( ! function_exists( 'get_plugins' ) || ! function_exists( 'get_mu_plugins' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } + // Install and activate the plugin if ( ! is_plugin_active( sprintf( '%1$s/%1$s.php', $this->connect_plugin_slug ) ) ) { $params = array( @@ -61,7 +62,7 @@ public function install_instawp_connect() { ), ); $installer = new Installer( $params ); - $response = $installer->start(); + $installer->start(); } // Connect the website with InstaWP server @@ -71,12 +72,13 @@ public function install_instawp_connect() { if ( ! $connect_response ) { return new \WP_Error( - 'Bad request', - esc_html__( 'Website could not connect successfully.' ), + 'bad_request', + __( 'Website could not connect successfully.', 'wp-module-migrations' ), array( 'status' => 400 ) ); } } + // Ready to start the migration if ( function_exists( 'instawp' ) ) { // Check if there is a connect ID @@ -87,20 +89,34 @@ public function install_instawp_connect() { sleep( 1 ); self::install_instawp_connect(); } else { - return new \WP_Error( 'Bad request', esc_html__( 'Connect plugin is installed but no connect ID.' ), array( 'status' => 400 ) ); + return new \WP_Error( + 'bad_request', + __( 'Connect plugin is installed but no connect ID.', 'wp-module-migrations' ), + array( 'status' => 400 ) + ); } } + // Add the current WordPress locale to the redirect URL + $locale = get_locale(); return array( - 'message' => esc_html__( 'Connect plugin is installed and ready to start the migration.' ), + 'message' => __( 'Connect plugin is installed and ready to start the migration.', 'wp-module-migrations' ), 'response' => true, - 'redirect_url' => esc_url( NFD_MIGRATION_PROXY_WORKER . '/' . INSTAWP_MIGRATE_ENDPOINT . '?d_id=' . Helper::get_connect_uuid() ), + 'redirect_url' => esc_url_raw( + sprintf( + '%s/%s?d_id=%s&locale=%s', + NFD_MIGRATION_PROXY_WORKER, + INSTAWP_MIGRATE_ENDPOINT, + Helper::get_connect_uuid(), + $locale + ) + ), ); } return new \WP_Error( - 'Bad request', - esc_html__( 'Migration might be finished.' ), + 'bad_request', + __( 'Migration might be finished.', 'wp-module-migrations' ), array( 'status' => 400 ) ); }