From 3d888cea6e1a9c9eed6aa8aa92a91c58a412168e Mon Sep 17 00:00:00 2001 From: thanghv Date: Tue, 10 Dec 2024 19:55:36 +0700 Subject: [PATCH] Fixed: stagging compatible update issue Fixed: file size error for some host Added: reconnect with user pw --- class/class-mainwp-child-staging.php | 24 ++++++++++++++++++++ class/class-mainwp-child-stats.php | 6 ++++- class/class-mainwp-connect.php | 34 +++++++++++++++------------- phpcs.xml | 15 ++++++------ readme.txt | 5 ++++ 5 files changed, 60 insertions(+), 24 deletions(-) diff --git a/class/class-mainwp-child-staging.php b/class/class-mainwp-child-staging.php index 6c781ef..e569eb0 100644 --- a/class/class-mainwp-child-staging.php +++ b/class/class-mainwp-child-staging.php @@ -440,6 +440,8 @@ class MainWP_Child_Staging { //phpcs:ignore -- NOSONAR - multi methods. } } + $result = array(); + if ( file_exists( WPSTG_PLUGIN_DIR . 'app/Backend/views/clone/ajax/start.php' ) ) { ob_start(); require_once WPSTG_PLUGIN_DIR . 'app/Backend/views/clone/ajax/start.php'; // NOSONAR - WP compatible. @@ -468,6 +470,22 @@ class MainWP_Child_Staging { //phpcs:ignore -- NOSONAR - multi methods. require_once WPSTG_PLUGIN_DIR . 'Backend/views/clone/ajax/start.php'; // NOSONAR - WP compatible. $result = ob_get_clean(); } + } elseif ( defined( 'WPSTG_VIEWS_DIR' ) && file_exists( WPSTG_VIEWS_DIR . 'clone/ajax/scan.php' ) ) { // new version >= 3.8.4. + if ( file_exists( WPSTG_PLUGIN_DIR . 'Core/WPStaging.php' ) ) { + include_once WPSTG_PLUGIN_DIR . 'Core/WPStaging.php'; // NOSONAR -- WP compatible. + $this->assets = \WPStaging\Core\WPStaging::make( \WPStaging\Framework\Assets\Assets::class ); // to fix error since ver 3.1.3. + + $subDirectory = str_replace( get_home_path(), '', ABSPATH ); + $urlsHelper = \WPStaging\Core\WPStaging::make( \WPStaging\Framework\Utils\Urls::class ); + $url = $urlsHelper->getHomeUrl() . str_replace( '/', '', $subDirectory ); + $result = array( + 'url' => $url, + 'blog_name' => get_bloginfo( 'name' ), + 'clone' => $cloning->getOptions()->clone, + 'img_src' => $this->assets->getAssetsUrl( 'img/admin_dashboard.png' ), + 'version3' => 1, + ); + } } return $result; } @@ -631,6 +649,12 @@ class MainWP_Child_Staging { //phpcs:ignore -- NOSONAR - multi methods. require_once WPSTG_PLUGIN_DIR . 'Backend/views/clone/ajax/update.php'; // NOSONAR - WP compatible. $result = ob_get_clean(); } + } elseif ( defined( 'WPSTG_VIEWS_DIR' ) && file_exists( WPSTG_VIEWS_DIR . 'clone/ajax/scan.php' ) ) { // new version >= 3.8.4. + $result = array( + 'clone' => $cloning->getOptions()->clone, + 'mainJob' => $cloning->getOptions()->mainJob, + 'version3' => 1, + ); } return $result; diff --git a/class/class-mainwp-child-stats.php b/class/class-mainwp-child-stats.php index c726c5b..2dcdc22 100644 --- a/class/class-mainwp-child-stats.php +++ b/class/class-mainwp-child-stats.php @@ -879,7 +879,11 @@ class MainWP_Child_Stats { //phpcs:ignore -- NOSONAR - multi methods. if ( class_exists( '\RecursiveIteratorIterator' ) ) { $size = 0; foreach ( new \RecursiveIteratorIterator( new \RecursiveDirectoryIterator( $directory ) ) as $file ) { - $size += $file->getSize(); + try { + $size += $file->getSize(); + } catch ( \Exception $e ) { + // prevent error some hosts. + } } if ( $size && MainWP_Helper::ctype_digit( $size ) ) { return $size / 1024 / 1024; diff --git a/class/class-mainwp-connect.php b/class/class-mainwp-connect.php index 9260f26..a459d3a 100644 --- a/class/class-mainwp-connect.php +++ b/class/class-mainwp-connect.php @@ -86,51 +86,53 @@ class MainWP_Connect { //phpcs:ignore -- NOSONAR - multi methods. // phpcs:disable WordPress.Security.NonceVerification, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized // Check if the user is valid & login. if ( ! isset( $_POST['user'] ) || ! isset( $_POST['pubkey'] ) ) { - MainWP_Helper::instance()->error( sprintf( esc_html__( 'Public key could not be set. Please make sure that the OpenSSL library has been configured correctly on your MainWP Dashboard. For additional help, please check this %1$shelp document%2$s.', 'mainwp-child' ), '', '' ) ); + MainWP_Helper::instance()->error( sprintf( esc_html__( 'Public key could not be set. Please make sure that the OpenSSL library has been configured correctly on your MainWP Dashboard. For additional help, please check this %1$shelp document%2$s.', 'mainwp-child' ), '', '' ), 'REG_ERROR1' ); } // Already added - can't readd. Deactivate plugin. if ( get_option( 'mainwp_child_pubkey' ) ) { - - // Set disconnect status to yes here, it will empty after reconnected. - MainWP_Child_Branding::instance()->save_branding_options( 'branding_disconnected', 'yes' ); - MainWP_Helper::instance()->error( esc_html__( 'Public key already set. Please deactivate & reactivate the MainWP Child plugin on the child site and try again.', 'mainwp-child' ) ); + // if register verified, then go to next step. + if ( ! $this->is_verified_register( wp_unslash( $_POST['user'] ) ) ) { + // Set disconnect status to yes here, it will empty after reconnected. + MainWP_Child_Branding::instance()->save_branding_options( 'branding_disconnected', 'yes' ); + MainWP_Helper::instance()->error( esc_html__( 'Public key already set. Please deactivate & reactivate the MainWP Child plugin on the child site and try again.', 'mainwp-child' ), 'REG_ERROR2' ); + } } $uniqueId = MainWP_Helper::get_site_unique_id(); // Check the Unique Security ID. if ( '' !== $uniqueId ) { if ( ! isset( $_POST['uniqueId'] ) || ( '' === $_POST['uniqueId'] ) ) { - MainWP_Helper::instance()->error( esc_html__( 'This child site is set to require a unique security ID. Please enter it before the connection can be established.', 'mainwp-child' ) ); + MainWP_Helper::instance()->error( esc_html__( 'This child site is set to require a unique security ID. Please enter it before the connection can be established.', 'mainwp-child' ), 'REG_ERROR3' ); } elseif ( $uniqueId !== $_POST['uniqueId'] ) { - MainWP_Helper::instance()->error( esc_html__( 'The unique security ID mismatch! Please correct it before the connection can be established.', 'mainwp-child' ) ); + MainWP_Helper::instance()->error( esc_html__( 'The unique security ID mismatch! Please correct it before the connection can be established.', 'mainwp-child' ), 'REG_ERROR4' ); } } // Check SSL Requirement. if ( ! MainWP_Helper::is_ssl_enabled() && ( ! defined( 'MAINWP_ALLOW_NOSSL_CONNECT' ) || ! MAINWP_ALLOW_NOSSL_CONNECT ) ) { - MainWP_Helper::instance()->error( esc_html__( 'OpenSSL library is required on the child site to set up a secure connection.', 'mainwp-child' ) ); + MainWP_Helper::instance()->error( esc_html__( 'OpenSSL library is required on the child site to set up a secure connection.', 'mainwp-child' ), 'REG_ERROR5' ); } // Check Curl SSL Requirement. if ( ! MainWP_Child_Server_Information_Base::get_curl_support() ) { - MainWP_Helper::instance()->error( esc_html__( 'cURL Extension not enabled on the child site server. Please contact your host support and have them enabled it for you.', 'mainwp-child' ) ); + MainWP_Helper::instance()->error( esc_html__( 'cURL Extension not enabled on the child site server. Please contact your host support and have them enabled it for you.', 'mainwp-child' ), 'REG_ERROR6' ); } if ( ! empty( $_POST['user'] ) && ! $this->is_verified_register( wp_unslash( $_POST['user'] ) ) ) { if ( isset( $_POST['regverify'] ) ) { MainWP_Helper::instance()->error( esc_html__( 'Failed to reconnect to the site. Please remove the site and add it again.', 'mainwp-child' ), 'reconnect_failed' ); } else { - MainWP_Helper::instance()->error( esc_html__( 'Unable to connect to the site. Please verify that your Admin Username and Password are correct and try again.', 'mainwp-child' ) ); + MainWP_Helper::instance()->error( esc_html__( 'Unable to connect to the site. Please verify that your Admin Username and Password are correct and try again.', 'mainwp-child' ), 'REG_ERROR7' ); } } // Check if the user exists and if yes, check if it's administartor user. if ( empty( $_POST['user'] ) || ! $this->login( wp_unslash( $_POST['user'] ) ) ) { - MainWP_Helper::instance()->error( esc_html__( 'Administrator user does not exist. Please verify that the user is an existing administrator.', 'mainwp-child' ) ); + MainWP_Helper::instance()->error( esc_html__( 'Administrator user does not exist. Please verify that the user is an existing administrator.', 'mainwp-child' ), 'REG_ERROR8' ); } if ( ! MainWP_Helper::is_admin() ) { - MainWP_Helper::instance()->error( esc_html__( 'User is not an administrator. Please use an administrator user to establish the connection.', 'mainwp-child' ) ); + MainWP_Helper::instance()->error( esc_html__( 'User is not an administrator. Please use an administrator user to establish the connection.', 'mainwp-child' ), 'REG_ERROR9' ); } // Update the mainwp_child_pubkey option. @@ -396,7 +398,7 @@ class MainWP_Connect { //phpcs:ignore -- NOSONAR - multi methods. public function parse_init_auth( $auth = false ) { // phpcs:ignore -- NOSONAR - Current complexity is the only way to achieve desired results, pull request solutions appreciated. // phpcs:disable WordPress.Security.NonceVerification if ( ! $auth && isset( $_POST['mainwpsignature'] ) ) { // with 'mainwpsignature' then need to callable functions. - MainWP_Helper::instance()->error( esc_html__( 'Authentication failed! Please deactivate & re-activate the MainWP Child plugin on this child site and try again.', 'mainwp-child' ) ); + MainWP_Helper::instance()->error( esc_html__( 'Authentication failed! Please deactivate & re-activate the MainWP Child plugin on this child site and try again.', 'mainwp-child' ), 'PARSE_ERROR1' ); } if ( ! $auth && isset( $_POST['function'] ) ) { @@ -405,7 +407,7 @@ class MainWP_Connect { //phpcs:ignore -- NOSONAR - multi methods. $callable_no_auth = MainWP_Child_Callable::get_instance()->is_callable_function_no_auth( $func ); if ( $callable && ! $callable_no_auth && isset( $_POST['mainwpsignature'] ) ) { - MainWP_Helper::instance()->error( esc_html__( 'Authentication failed! Please deactivate & re-activate the MainWP Child plugin on this site and try again.', 'mainwp-child' ) ); + MainWP_Helper::instance()->error( esc_html__( 'Authentication failed! Please deactivate & re-activate the MainWP Child plugin on this site and try again.', 'mainwp-child' ), 'PARSE_ERROR2' ); } } @@ -433,11 +435,11 @@ class MainWP_Connect { //phpcs:ignore -- NOSONAR - multi methods. } if ( ! $user ) { - MainWP_Helper::instance()->error( esc_html__( 'Unexisting administrator user. Please verify that it is an existing administrator.', 'mainwp-child' ) ); + MainWP_Helper::instance()->error( esc_html__( 'Unexisting administrator user. Please verify that it is an existing administrator.', 'mainwp-child' ), 'PARSE_ERROR3' ); } if ( ! MainWP_Helper::is_admin( $user ) ) { - MainWP_Helper::instance()->error( esc_html__( 'User not administrator. Please use an administrator user to establish the connection.', 'mainwp-child' ) ); + MainWP_Helper::instance()->error( esc_html__( 'User not administrator. Please use an administrator user to establish the connection.', 'mainwp-child' ), 'PARSE_ERROR4' ); } // try to login. diff --git a/phpcs.xml b/phpcs.xml index c08e560..dcd5058 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -4,7 +4,7 @@ . - + */vendor/* */bin/* */.github/* @@ -23,8 +23,8 @@ - - + + @@ -38,20 +38,21 @@ - + + - + - + - + diff --git a/readme.txt b/readme.txt index 9921e54..9cf6c0c 100644 --- a/readme.txt +++ b/readme.txt @@ -125,3 +125,8 @@ We have an extensive FAQ with more questions and answers [here](https://mainwp.c [See Video Changelog](https://youtu.be/DF0vC1RiCVI) [See changelog for all versions.](https://mainwp.com/mainwp-child-changelog.txt) + += 5.2.1 - 11-20-2024 = + +* Added: After activating the MainWP plugin, users are now redirected to the MainWP Settings page for a smoother onboarding experience. +* Updated: The Unique Security ID option is now enabled by default to enhance security for all MainWP installations. \ No newline at end of file