From df2eef248ed8d3680076e188aba8e9ad042a1d08 Mon Sep 17 00:00:00 2001 From: Anthony Date: Sat, 9 Aug 2025 00:52:02 +0800 Subject: [PATCH] Fix bug edits --- scripts/wp-search-replace.sh | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/scripts/wp-search-replace.sh b/scripts/wp-search-replace.sh index f233599..56e53de 100644 --- a/scripts/wp-search-replace.sh +++ b/scripts/wp-search-replace.sh @@ -233,9 +233,19 @@ if [[ -f "$CONFIG_FILE" && -w "$CONFIG_FILE" ]]; then 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" # Determine which entries are missing to avoid duplicates - needs_home=1; grep -Eq "define\([[:space:]]*['\"]WP_HOME['\"]" "$CONFIG_FILE" && needs_home=0 || true - needs_siteurl=1; grep -Eq "define\([[:space:]]*['\"]WP_SITEURL['\"]" "$CONFIG_FILE" && needs_siteurl=0 || true - needs_http_host=1; grep -Eq "\$_SERVER\[(\"|')HTTP_HOST\1\][[:space:]]*=" "$CONFIG_FILE" && needs_http_host=0 || true + needs_home=1 + needs_siteurl=1 + needs_http_host=1 + + if grep -Eq "define[[:space:]]*\([[:space:]]*['\"]WP_HOME['\"]" "$CONFIG_FILE"; then + needs_home=0 + fi + 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 + needs_http_host=0 + fi if [[ $needs_home -eq 1 || $needs_siteurl -eq 1 || $needs_http_host -eq 1 ]]; then info "Inserting missing wp-config.php directives (WP_HOME/WP_SITEURL/HTTP_HOST) …"