Compare commits

..

No commits in common. "77a645bb040515d5ec6572b48ef46f296522499d" and "f671993002b1954b0483d0bc3d0d15247e983efa" have entirely different histories.

1 changed files with 2 additions and 25 deletions

View File

@ -217,33 +217,10 @@ success "All search-replace tasks completed successfully."
CONFIG_FILE="$WP_ROOT/wp-config.php" CONFIG_FILE="$WP_ROOT/wp-config.php"
if [[ -f "$CONFIG_FILE" && -w "$CONFIG_FILE" ]]; then if [[ -f "$CONFIG_FILE" && -w "$CONFIG_FILE" ]]; then
info "Updating WP_HOME and WP_SITEURL in wp-config.php …" info "Updating WP_HOME and WP_SITEURL in wp-config.php …"
# Use the new URL without trailing slash, ensure it has https:// # Use the new URL without trailing slash
TARGET_URL="$NEW_NORMAL" TARGET_URL="$NEW_NORMAL"
# Ensure URL starts with https://
if [[ ! "$TARGET_URL" =~ ^https:// ]]; then
TARGET_URL="https://$TARGET_URL"
info "Added https:// prefix to URL: $TARGET_URL"
fi
# shellcheck disable=SC2016 # we want literal single quotes inside sed replacement # shellcheck disable=SC2016 # we want literal single quotes inside sed replacement
# Replace existing definitions if they exist sed -i -E "s|define\(\s*'WP_HOME',\s*'[^']*'\s*\);|define( 'WP_HOME', '${TARGET_URL}' );|; s|define\(\s*'WP_SITEURL',\s*'[^']*'\s*\);|define( 'WP_SITEURL', '${TARGET_URL}' );|" "$CONFIG_FILE" || warning "Failed to update wp-config.php"
sed -i -E "s|define\(\s*'WP_HOME'\s*,\s*'[^']*'\s*\);|define( 'WP_HOME', '${TARGET_URL}' );|; s|define\(\s*'WP_SITEURL'\s*,\s*'[^']*'\s*\);|define( 'WP_SITEURL', '${TARGET_URL}' );|; s|\$_SERVER\['HTTP_HOST'\]\s*=\s*'[^']*';|\$_SERVER['HTTP_HOST'] = '${HOST_ONLY}';|" "$CONFIG_FILE" || warning "Failed to update wp-config.php"
# If WP_HOME wasn't present, insert block above /* That's all */
if ! grep -q "WP_HOME" "$CONFIG_FILE"; then
info "Inserting WP_HOME and WP_SITEURL constants into wp-config.php …"
awk -v url="$TARGET_URL" -v host="$HOST_ONLY" '
BEGIN{inserted=0}
/\/\* That\x27s all/{
print "\n// Added by wp-search-replace.sh";
print "define( \"WP_HOME\", \"" url "\" );";
print "define( \"WP_SITEURL\", \"" url "\" );";
print "if ( defined( \"WP_CLI\" ) && WP_CLI && ! isset( $_SERVER[\"HTTP_HOST\"] ) ) { $_SERVER[\"HTTP_HOST\"] = \"" host "\"; }";
inserted=1;
}
{print}
END{if(!inserted) exit 1}
' "$CONFIG_FILE" > "$CONFIG_FILE.tmp" && mv "$CONFIG_FILE.tmp" "$CONFIG_FILE"
fi
else else
warning "wp-config.php not found or not writable; skipped WP_HOME / WP_SITEURL update." warning "wp-config.php not found or not writable; skipped WP_HOME / WP_SITEURL update."
fi fi