Fix bug edits

main
Anthony 2025-08-09 01:06:32 +08:00
parent df2eef248e
commit c7668bee46
1 changed files with 18 additions and 10 deletions

View File

@ -249,17 +249,25 @@ sed -i -E "s|define\([[:space:]]*['\"]WP_HOME['\"][[:space:]]*,[[:space:]]*['\"]
if [[ $needs_home -eq 1 || $needs_siteurl -eq 1 || $needs_http_host -eq 1 ]]; then 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) …" info "Inserting missing wp-config.php directives (WP_HOME/WP_SITEURL/HTTP_HOST) …"
awk -v url="$TARGET_URL" -v host="$HOST_ONLY" -v insert_home="$needs_home" -v insert_siteurl="$needs_siteurl" -v insert_hostfix="$needs_http_host" ' INSERT_BLOCK="\n// Added by wp-search-replace.sh\n"
BEGIN{inserted=0} if [[ $needs_home -eq 1 ]]; then
/\/\* That\x27s all/{ INSERT_BLOCK+="define( 'WP_HOME', '${TARGET_URL}' );\n"
print "\n// Added by wp-search-replace.sh"; fi
if (insert_home == 1) print "define( \"WP_HOME\", \"" url "\" );"; if [[ $needs_siteurl -eq 1 ]]; then
if (insert_siteurl == 1) print "define( \"WP_SITEURL\", \"" url "\" );"; INSERT_BLOCK+="define( 'WP_SITEURL', '${TARGET_URL}' );\n"
if (insert_hostfix == 1) print "if ( defined( \"WP_CLI\" ) && WP_CLI && ! isset( $_SERVER[\"HTTP_HOST\"] ) ) { $_SERVER[\"HTTP_HOST\"] = \"" host "\"; }"; fi
inserted=1; if [[ $needs_http_host -eq 1 ]]; then
INSERT_BLOCK+="if ( defined( 'WP_CLI' ) && WP_CLI && ! isset( $_SERVER['HTTP_HOST'] ) ) { $_SERVER['HTTP_HOST'] = '${HOST_ONLY}'; }\n"
fi
awk -v block="$INSERT_BLOCK" '
BEGIN { inserted=0 }
/\/\* That/ {
printf "%s", block
inserted=1
} }
{print} { print }
END{if(!inserted) exit 1} END { if (!inserted) exit 1 }
' "$CONFIG_FILE" > "$CONFIG_FILE.tmp" && mv "$CONFIG_FILE.tmp" "$CONFIG_FILE" || warning "Could not insert directives into wp-config.php" ' "$CONFIG_FILE" > "$CONFIG_FILE.tmp" && mv "$CONFIG_FILE.tmp" "$CONFIG_FILE" || warning "Could not insert directives into wp-config.php"
fi fi
else else