Fix bug edits

main
Anthony 2025-08-09 00:52:02 +08:00
parent 0ad8e72652
commit df2eef248e
1 changed files with 13 additions and 3 deletions

View File

@ -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) …"