Don’t run redirect code on CLI usage#4211
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a guard so that Redirection's front-end redirect logic does not execute when WordPress is bootstrapped from a plain PHP CLI context (e.g. cron scripts that load wp-load.php directly). Without the guard, a matched rule or canonical redirect would invoke wp_redirect() followed by die(), silently terminating the CLI process.
Changes:
- Add new
red_is_cli()helper that returns true whenPHP_SAPI === 'cli'(distinct from WP-CLI detection). - Early-return from
WordPress_Module::canonical_domain()andWordPress_Module::init()when running under plain PHP CLI. - Add
.agentsand/CLAUDE.mdto.gitignore.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| redirection.php | Introduces red_is_cli() SAPI-based helper with docblock. |
| modules/wordpress.php | Skips canonical and main redirect loops when in plain PHP CLI to avoid die() terminating cron scripts. |
| .gitignore | Ignores local .agents directory and CLAUDE.md notes file. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Redirects are still processed when used via cron script, causing problems depending on settings. This PR doesn't run the redirect code in those cases