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
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" '
BEGIN{inserted=0}
/\/\* That\x27s all/{
print "\n// Added by wp-search-replace.sh";
if (insert_home == 1) print "define( \"WP_HOME\", \"" url "\" );";
if (insert_siteurl == 1) print "define( \"WP_SITEURL\", \"" url "\" );";
if (insert_hostfix == 1) print "if ( defined( \"WP_CLI\" ) && WP_CLI && ! isset( $_SERVER[\"HTTP_HOST\"] ) ) { $_SERVER[\"HTTP_HOST\"] = \"" host "\"; }";
inserted=1;
INSERT_BLOCK="\n// Added by wp-search-replace.sh\n"
if [[ $needs_home -eq 1 ]]; then
INSERT_BLOCK+="define( 'WP_HOME', '${TARGET_URL}' );\n"
fi
if [[ $needs_siteurl -eq 1 ]]; then
INSERT_BLOCK+="define( 'WP_SITEURL', '${TARGET_URL}' );\n"
fi
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}
END{if(!inserted) exit 1}
{ print }
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"
fi
else