Skip to content

Don’t run redirect code on CLI usage#4211

Merged
johngodley merged 1 commit into
trunkfrom
update/cli-usage
May 31, 2026
Merged

Don’t run redirect code on CLI usage#4211
johngodley merged 1 commit into
trunkfrom
update/cli-usage

Conversation

@johngodley
Copy link
Copy Markdown
Owner

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

Copilot AI review requested due to automatic review settings May 31, 2026 14:49
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 when PHP_SAPI === 'cli' (distinct from WP-CLI detection).
  • Early-return from WordPress_Module::canonical_domain() and WordPress_Module::init() when running under plain PHP CLI.
  • Add .agents and /CLAUDE.md to .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.

@johngodley johngodley merged commit 6b15bc5 into trunk May 31, 2026
9 checks passed
@johngodley johngodley deleted the update/cli-usage branch May 31, 2026 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants