From 03fe5557825c02f8c084cee5e31bba86a99e242a Mon Sep 17 00:00:00 2001 From: Ramya krishna Date: Thu, 22 Aug 2024 12:56:01 +0530 Subject: [PATCH 1/2] removing nested if statements --- includes/Services/InstaMigrateService.php | 37 +++++++++++------------ 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/includes/Services/InstaMigrateService.php b/includes/Services/InstaMigrateService.php index 53944ba..40c41e7 100644 --- a/includes/Services/InstaMigrateService.php +++ b/includes/Services/InstaMigrateService.php @@ -48,6 +48,7 @@ public function __construct() { * Install InstaWP plugin */ public function install_instawp_connect() { + if ( ! function_exists( 'get_plugins' ) || ! function_exists( 'get_mu_plugins' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } @@ -65,10 +66,8 @@ public function install_instawp_connect() { } // Connect the website with InstaWP server - if ( empty( Helper::get_api_key() ) || empty( Helper::get_connect_id() ) ) { - $api_key = Helper::get_api_key( false, $this->insta_api_key ); - $connect_response = Helper::instawp_generate_api_key( $api_key ); - + if ( empty( Helper::get_connect_id() ) ) { + $connect_response = Helper::instawp_generate_api_key( $this->insta_api_key ); if ( ! $connect_response ) { return new \WP_Error( 'Bad request', @@ -80,22 +79,22 @@ public function install_instawp_connect() { // Ready to start the migration if ( function_exists( 'instawp' ) ) { // Check if there is a connect ID - if ( empty( Helper::get_connect_id() ) ) { - if ( $this->count < 3 ) { - ++$this->count; - delete_option( 'instawp_api_options' ); // delete the connection to plugin and website - 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 ) ); - } + if ( ! empty( Helper::get_connect_id() ) ) { + return array( + 'message' => esc_html__( 'Connect plugin is installed and ready to start the migration.' ), + 'response' => true, + 'redirect_url' => esc_url( NFD_MIGRATION_PROXY_WORKER . '/' . INSTAWP_MIGRATE_ENDPOINT . '?d_id=' . Helper::get_connect_uuid() ), + ); + } + + if ( $this->count < 3 ) { + ++$this->count; + delete_option( 'instawp_api_options' ); // delete the connection to plugin and website + 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 array( - 'message' => esc_html__( 'Connect plugin is installed and ready to start the migration.' ), - 'response' => true, - 'redirect_url' => esc_url( NFD_MIGRATION_PROXY_WORKER . '/' . INSTAWP_MIGRATE_ENDPOINT . '?d_id=' . Helper::get_connect_uuid() ), - ); } return new \WP_Error( From 4d194efc0aeaf240e3d909f0d3a7c1543fbe46f5 Mon Sep 17 00:00:00 2001 From: Ramya krishna Date: Thu, 22 Aug 2024 12:58:24 +0530 Subject: [PATCH 2/2] linting --- includes/Services/InstaMigrateService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/Services/InstaMigrateService.php b/includes/Services/InstaMigrateService.php index 40c41e7..cd9ffb4 100644 --- a/includes/Services/InstaMigrateService.php +++ b/includes/Services/InstaMigrateService.php @@ -86,7 +86,7 @@ public function install_instawp_connect() { 'redirect_url' => esc_url( NFD_MIGRATION_PROXY_WORKER . '/' . INSTAWP_MIGRATE_ENDPOINT . '?d_id=' . Helper::get_connect_uuid() ), ); } - + if ( $this->count < 3 ) { ++$this->count; delete_option( 'instawp_api_options' ); // delete the connection to plugin and website