Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ svn
/WARP.md
/AGENTS.md
/tsconfig.tsbuildinfo
.agents
/CLAUDE.md
13 changes: 13 additions & 0 deletions modules/wordpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,13 @@ public function get_canonical_target() {
* @return void
*/
public function canonical_domain() {
// In a plain PHP CLI bootstrap (e.g. a cron script that loads wp-load.php)
// there is no real HTTP request to redirect. Running die() here would
// silently terminate the CLI process before user code can execute.
if ( red_is_cli() ) {
return;
}

$target = $this->get_canonical_target();

if ( $target !== false ) {
Expand All @@ -323,6 +330,12 @@ public function init() {
return;
}

// Skip the redirect loop in a plain PHP CLI bootstrap. A matched rule
// would call wp_redirect()+die() and silently terminate the CLI process.
if ( red_is_cli() ) {
return;
}

$request = new Red_Url_Request( Redirection_Request::get_request_url() );

// Make sure we don't try and redirect something essential
Expand Down
12 changes: 12 additions & 0 deletions redirection.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,18 @@ function red_is_wpcli() {
return false;
}

/**
* Detect a plain PHP CLI context (e.g., a cron script that loads wp-load.php
* directly). Distinct from red_is_wpcli(), which is only true under WP-CLI.
* Used to skip front-end redirect enforcement that would otherwise call die()
* and silently terminate the CLI process.
*
* @return bool
*/
function red_is_cli() {
return PHP_SAPI === 'cli';
}

/**
* @return bool
*/
Expand Down
Loading