diff --git a/scripts/wp-search-replace.sh b/scripts/wp-search-replace.sh index 285a2cd..b48b5d4 100644 --- a/scripts/wp-search-replace.sh +++ b/scripts/wp-search-replace.sh @@ -230,7 +230,14 @@ if [[ -f "$CONFIG_FILE" && -w "$CONFIG_FILE" ]]; then [[ -z "$HOST_ONLY" ]] && HOST_ONLY="$TARGET_URL" # shellcheck disable=SC2016 # we want literal quotes inside sed replacement # Replace existing definitions (handle both single and double quotes) -sed -i -E "s|define\([[:space:]]*['\"]WP_HOME['\"][[:space:]]*,[[:space:]]*['\"][^'\"]*['\"][[:space:]]*\);|define( 'WP_HOME', '${TARGET_URL}' );|; s|define\([[:space:]]*['\"]WP_SITEURL['\"][[:space:]]*,[[:space:]]*['\"][^'\"]*['\"][[:space:]]*\);|define( 'WP_SITEURL', '${TARGET_URL}' );|; s|\$_SERVER\[(\"|')HTTP_HOST\1\][[:space:]]*=[[:space:]]*(\"|')[^"']*\2;|\$_SERVER['HTTP_HOST'] = '${HOST_ONLY}';|" "$CONFIG_FILE" || warning "Failed to update wp-config.php" + # Update WP_HOME if it exists + sed -i -E "s|define[[:space:]]*\([[:space:]]*['\"]WP_HOME['\"][[:space:]]*,[[:space:]]*['\"][^'\"]*['\"][[:space:]]*\)|define( 'WP_HOME', '${TARGET_URL}' )|g" "$CONFIG_FILE" + + # Update WP_SITEURL if it exists + sed -i -E "s|define[[:space:]]*\([[:space:]]*['\"]WP_SITEURL['\"][[:space:]]*,[[:space:]]*['\"][^'\"]*['\"][[:space:]]*\)|define( 'WP_SITEURL', '${TARGET_URL}' )|g" "$CONFIG_FILE" + + # Update HTTP_HOST if it exists + sed -i -E "s|(\\\$_SERVER\[['\"]HTTP_HOST['\"]\][[:space:]]*=[[:space:]]*['\"])[^'\"]*(['\"];)|\1${HOST_ONLY}\2|g" "$CONFIG_FILE" # Determine which entries are missing to avoid duplicates needs_home=1 @@ -243,7 +250,7 @@ sed -i -E "s|define\([[:space:]]*['\"]WP_HOME['\"][[:space:]]*,[[:space:]]*['\"] if grep -Eq "define[[:space:]]*\([[:space:]]*['\"]WP_SITEURL['\"]" "$CONFIG_FILE"; then needs_siteurl=0 fi - if grep -Eq "\$_SERVER\[(\"|')HTTP_HOST\1\][[:space:]]*=" "$CONFIG_FILE"; then + if grep -Eq '\$_SERVER\[["\x27]HTTP_HOST["\x27]\][[:space:]]*=' "$CONFIG_FILE"; then needs_http_host=0 fi