From 7709c4fc24055af61f43657436d623beb804da2f Mon Sep 17 00:00:00 2001 From: Rodrigo Gomes Date: Sun, 16 Nov 2025 18:44:35 -0300 Subject: [PATCH] fix(clone): Prevents overwriting wp-config.php when cloning a remote site with a custom public directory This change fixes a bug in the copy_site_files() function where the wp-config.php file from the remote site was copied and overwritten the local wp-config.php file when the remote site had a custom public directory. --- src/clone/clone-utils.php | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/clone/clone-utils.php b/src/clone/clone-utils.php index 21e00c64..3e1fdc53 100644 --- a/src/clone/clone-utils.php +++ b/src/clone/clone-utils.php @@ -132,21 +132,34 @@ function copy_site_certs( Site $source, Site $destination ) { function copy_site_files( Site $source, Site $destination, array $sync_type ) { - $exclude = '--exclude \'/wp-config.php\''; - $source_public_path = str_replace( '/var/www/htdocs', '', $source->site_details['site_container_fs_path'] ); - $uploads_path = $source_public_path . '/wp-content/uploads'; - $uploads_path_share = '/shared/wp-content/uploads'; + $source_public_path = str_replace( '/var/www/htdocs', '', $source->site_details['site_container_fs_path'] ); + $destination_public_path = str_replace( '/var/www/htdocs', '', $destination->site_details['site_container_fs_path'] ); + + $exclude = '--exclude \'/wp-config.php\''; + + if ( ! empty( $destination_public_path ) ) { + $exclude .= ' --exclude \'' . $destination_public_path . '/wp-config.php\''; + + $parent_dir = dirname( $destination_public_path ); + if ( $parent_dir !== '.' && $parent_dir !== '/' ) { + $exclude .= ' --exclude \'' . $parent_dir . '/wp-config.php\''; + } + } + + $source_uploads_path = $source_public_path . '/wp-content/uploads'; + $destination_uploads_path = $destination_public_path . '/wp-content/uploads'; + $uploads_path_share = '/shared/wp-content/uploads'; $source_dir = remove_trailing_slash( $source->get_site_root_dir() ); $destination_dir = remove_trailing_slash( $destination->get_site_root_dir() ); if ( $sync_type['uploads'] && ! $sync_type['files'] ) { - $source_dir .= $uploads_path; - $destination_dir .= $uploads_path; + $source_dir .= $source_uploads_path; + $destination_dir .= $destination_uploads_path; } if ( $sync_type['files'] && ! $sync_type['uploads'] ) { - $exclude .= ' --exclude \'' . $uploads_path . '\''; + $exclude .= ' --exclude \'' . $source_uploads_path . '\''; $exclude .= ' --exclude \'' . $uploads_path_share . '\''; }