Auto-set permalink structure during setup if plain/default detected#13
Open
coleplx wants to merge 6 commits intoWordPress:trunkfrom
Open
Auto-set permalink structure during setup if plain/default detected#13coleplx wants to merge 6 commits intoWordPress:trunkfrom
coleplx wants to merge 6 commits intoWordPress:trunkfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the setup flow in rtc-test.sh to reduce failures caused by WordPress installs using “Plain” permalinks and to prevent set -e from aborting setup when SAVEQUERIES is not defined in wp-config.php.
Changes:
- Auto-detect “Plain/default” permalink structure and attempt to switch to
/%postname%/during WP-CLI setup. - Prevent
wp config get SAVEQUERIESfrom aborting the script when the constant is unset by appending|| true. - Update manual setup instructions to include enabling pretty permalinks and renumber the steps.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Comment on lines
+840
to
+857
| if [ -n "${site_url}" ] && curl -fsS -o /dev/null "${rest_url}" >/dev/null 2>&1; then | ||
| printf 'Permalinks: set to /%%postname%%/\n' | ||
| # Re-check the REST API after changing permalinks. Updating the option | ||
| # alone is not enough if server rewrite rules are still misconfigured. | ||
| site_url="$(wp "${WP_FLAGS[@]}" option get siteurl 2>/dev/null)" || site_url="" | ||
| rest_probe_url="${site_url%/}/wp-json/" | ||
| rest_probe_code="$(curl -sS -L -o /dev/null -w '%{http_code}' "${rest_probe_url}" 2>/dev/null)" || rest_probe_code="" | ||
| case "${rest_probe_code}" in | ||
| 2*) | ||
| printf 'REST API: %s (OK after permalink update)\n' "${rest_probe_url}" | ||
| ;; | ||
| *) | ||
| die "Permalinks were updated, but ${rest_probe_url} is still unreachable (HTTP ${rest_probe_code:-request failed}). Check web server rewrite rules and try again." | ||
| ;; | ||
| esac | ||
| else | ||
| die "Could not make REST API reachable after setting permalink structure. Check permalinks/web server config and verify ${rest_url:-/wp-json/}." | ||
| fi |
| case "${rest_probe_code}" in | ||
| 2*) | ||
| printf 'REST API: %s (OK after permalink update)\n' "${rest_probe_url}" | ||
| ;; |
Comment on lines
+840
to
+846
| if [ -n "${site_url}" ] && curl -fsS -o /dev/null "${rest_url}" >/dev/null 2>&1; then | ||
| printf 'Permalinks: set to /%%postname%%/\n' | ||
| # Re-check the REST API after changing permalinks. Updating the option | ||
| # alone is not enough if server rewrite rules are still misconfigured. | ||
| site_url="$(wp "${WP_FLAGS[@]}" option get siteurl 2>/dev/null)" || site_url="" | ||
| rest_probe_url="${site_url%/}/wp-json/" | ||
| rest_probe_code="$(curl -sS -L -o /dev/null -w '%{http_code}' "${rest_probe_url}" 2>/dev/null)" || rest_probe_code="" |
Comment on lines
+838
to
+840
| site_url="$(wp "${WP_FLAGS[@]}" option get siteurl 2>/dev/null)" || site_url="" | ||
| rest_url="${site_url%/}/wp-json/" | ||
| if [ -n "${site_url}" ] && curl -fsS -o /dev/null "${rest_url}" >/dev/null 2>&1; then |
Comment on lines
+835
to
+837
| wp "${WP_FLAGS[@]}" rewrite flush >/dev/null 2>&1 \ | ||
| || die "Could not flush rewrite rules after setting permalink structure." | ||
| fi |
Comment on lines
+827
to
+833
| local site_url rest_probe_url rest_probe_code | ||
| printf 'Permalinks: default (query-string) -- setting to /%%postname%%/\n' | ||
| if wp "${WP_FLAGS[@]}" rewrite structure '/%postname%/' --hard >/dev/null 2>&1; then | ||
| : | ||
| else | ||
| printf 'Permalinks: hard rewrite failed; retrying without --hard\n' | ||
| wp "${WP_FLAGS[@]}" rewrite structure '/%postname%/' >/dev/null 2>&1 \ |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Also, on line 895, added
|| trueto prevent the script from failing and exiting silently whenwp config get SAVEQUERIESreturns false.Motivation:
The script kept failing on
single-idledue to permalinks being disabled. The requested path returned WordPress' default 404 HTML. 😞