Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Feb 2, 2026

WP-CLI was logging to /wp-content/debug.log even when users defined a custom path via WP_DEBUG_LOG constant in wp-config.php. The wp_debug_mode() function accessed WordPress debug constants without checking if they were defined, causing the logging setup block to be skipped or fail.

Changes

  • Added defined() checks before accessing WP_DEBUG, WP_DEBUG_DISPLAY, and WP_DEBUG_LOG constants in php/utils-wp.php
  • Fixed logic for WP_DEBUG_DISPLAY to properly handle explicit false value (changed from null !== to === false)
  • Wrapped WP_DEBUG_LOG setup in conditional to only execute when constant is defined
  • Added test scenario in features/utils-wp.feature to verify custom log paths work correctly

Example

// Before: Undefined constant error or skipped block
if ( WP_DEBUG ) {  // No check if defined
    if ( is_string( WP_DEBUG_LOG ) ) {
        $log_path = WP_DEBUG_LOG;  // Never reached
    }
}

// After: Properly checks and respects custom path
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
    if ( defined( 'WP_DEBUG_LOG' ) ) {
        if ( is_string( WP_DEBUG_LOG ) ) {
            $log_path = WP_DEBUG_LOG;  // Now works correctly
        }
    }
}

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • example.com
    • Triggering command: /usr/bin/php php vendor/bin/phpunit --color=always --bootstrap ./vendor/wp-cli/wp-cli-tests/tests/bootstrap.php mcp-server-playwright --viewport-size '1280, 720' --output-dir /-n g=Off ng=E_ALL (dns block)
  • nosuchhost_asdf_asdf_asdf.com
    • Triggering command: /usr/bin/php php vendor/bin/phpunit --color=always --bootstrap ./vendor/wp-cli/wp-cli-tests/tests/bootstrap.php mcp-server-playwright --viewport-size '1280, 720' --output-dir /-n g=Off ng=E_ALL (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>WP-CLI does not log errors to the path set in WP_DEBUG_LOG</issue_title>
<issue_description>## Bug Report

Describe the current, buggy behavior

I have this set in my wp-config.php file:

define('WP_DEBUG', true);
define('WP_DEBUG_DISPLAY', false);
define('WP_DEBUG_LOG', '/tmp/debug_staging.log');

I have experienced that when I do error_log() through WP-CLI, the log goes to the standard log path of /wp-content/debug.log. This does not happen when errors are triggered by visiting pages and running functions from the browser.

Describe how other contributors can replicate this bug

  1. Register the following command for use through WP-CLI:
public function check_debug()
{
    error_log(WP_DEBUG_LOG);
}
  1. Define WP_DEBUG as true and set a specific path for WP_DEBUG_LOG in wp-config.php

  2. Run check_debug() through WP-CLI

You will see your path from WP_DEBUG_LOG be logged in /wp-content/debug.log

Describe what you expect as the correct outcome

I expect the path of WP_DEBUG_LOG to be logged in the path set in WP_DEBUG_LOG.

Let us know what environment you are running this on

OS:     Linux 5.4.72 wp-cli/wp-cli#3 SMP Sun Oct 25 11:14:45 UTC 2020 x86_64
Shell:  /bin/sh
PHP binary:     /usr/app/php/7.4.22/bin/php
PHP version:    7.4.22
php.ini used:   /etc/app/php/php.ini
WP-CLI root dir:        phar://wp-cli.phar/vendor/wp-cli/wp-cli
WP-CLI vendor dir:      phar://wp-cli.phar/vendor
WP_CLI phar path:       [REDACTED]
WP-CLI packages dir:
WP-CLI global config:
WP-CLI project config:
WP-CLI version: 2.4.0

Provide additional context

I have looked through the code here:

function wp_debug_mode() {

If I paste the function wp_debug_mode() into check_debug() and then error_log $log_path on line 64, I get '/tmp/debug_staging.log' in the log file on the default location. I get nothing in /tmp/debug_staging.log.

I, therefore, do not know where this goes wrong and I have no idea how to fix it.
</issue_description>

Comments on the Issue (you are @copilot in this section)

@ernilambar Some how, the value of `WP_DEBUG` is always false. https://github.com/wp-cli/wp-cli/blob/0b22dee2eabcfc9f9f84671003900155b0722543/php/utils-wp.php#L51

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix WP-CLI error logging to correct path Fix WP_DEBUG_LOG custom paths not being respected Feb 2, 2026
Copilot AI requested a review from swissspidy February 2, 2026 01:35
@codecov
Copy link

codecov bot commented Feb 2, 2026

Codecov Report

❌ Patch coverage is 83.33333% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
php/utils-wp.php 83.33% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
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

This PR fixes WP-CLI’s handling of WordPress debug constants so that WP_DEBUG_LOG custom paths are respected and undefined constants don’t cause incorrect behavior, and adds a regression test to lock this in.

Changes:

  • Updated wp_debug_mode() to wrap uses of WP_DEBUG, WP_DEBUG_DISPLAY, and WP_DEBUG_LOG in defined() checks, preventing notices and mis-evaluation when constants are not defined.
  • Adjusted the WP_DEBUG_DISPLAY logic to explicitly handle false values and only act when the constant is defined.
  • Added a Behat feature scenario to verify that when WP_DEBUG_LOG is set to a custom path, WP-CLI logs errors to that path.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
php/utils-wp.php Tightens wp_debug_mode()’s use of WP debug constants, ensuring WP_DEBUG_LOG custom paths and WP_DEBUG_DISPLAY are only used when defined and handled with clearer logic.
features/utils-wp.feature Adds an end-to-end scenario that configures WP_DEBUG_LOG to /tmp/custom_debug.log and verifies that WP-CLI writes errors to this custom log file.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WP-CLI does not log errors to the path set in WP_DEBUG_LOG

2 participants