WP-CLI Toggle WP_DEBUG
Asked Answered
U

3

8

I'm looking to toggle the WP_DEBUG value within a WP-CLI script. Is there any option doing so AFTER the wp-config.php file was created?

(I know we can add extra PHP when creating the wp-config.php file, but once that's done, is there a way to turn off the WP_DEBUG state during the script?)

Thanks.

Unequivocal answered 29/2, 2016 at 22:28 Comment(1)
Good question, I just keep it set to true, and comment / un-comment when needed - not a huge deal if you're quick with vi but still not a great solution. hoping someone has the real answer.Vinny
U
11

Woohoo! Native support added since WP-CLI version 1.5 -

https://developer.wordpress.org/cli/commands/config/set/

Example:

# Set the WP_DEBUG constant to true.
$ wp config set WP_DEBUG true --raw
Unequivocal answered 5/3, 2018 at 8:10 Comment(1)
Note, this only works if you already have the WP_DEBUG variable in your config file. By default a WP CLI wp config create setup doesn't include this var so unfortunately you'd have to add define('WP_DEBUG', false); to the file before you can then use this command. Which kind of defeats the purpose. Bummer!Akeyla
G
10

To extend on @tlt2w answer posted above, I'm using this combo:

wp config set --raw WP_DEBUG true
wp config set --raw WP_DEBUG_LOG true
wp config set --raw WP_DEBUG_DISPLAY false

# show logs:
# clear; tail -f wp-content/debug.log -n0
Gdynia answered 9/9, 2019 at 16:12 Comment(0)
C
0

You could use wp config get to determine if debug is enabled or not, however today there is no way to set that value via WP-CLI.

That said, just wrote a bash command that can toggle the value for you.

You can run it in the same directory you have your wp-config.php:

data=`egrep "'WP_DEBUG'" wp-config.php | egrep -o "(true|false)"`; [[ $data == true ]] && newdata=false || newdata=true; sed -i "s/'WP_DEBUG'.*/'WP_DEBUG', $newdata\)\;/g" wp-config.php

Every time you run it, the WP_DEBUG constant value will switch from true to false or vice-versa.

Unfortunately there is no way to toggle the WP_DEBUG value during the script execution, since the value was already defined in wp-config.php file.

Cultism answered 4/9, 2017 at 14:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.