Skip to content
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

HG: Add locale to migration redirect #72

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
38 changes: 27 additions & 11 deletions includes/Services/InstaMigrateService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';

Expand All @@ -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();
Expand All @@ -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(
Expand All @@ -61,7 +62,7 @@ public function install_instawp_connect() {
),
);
$installer = new Installer( $params );
$response = $installer->start();
$installer->start();
}

// Connect the website with InstaWP server
Expand All @@ -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
Expand All @@ -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 )
);
}
Expand Down
Loading