WP-CLI Toggle WP_DEBUG

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?)

Read More

Thanks.

Related posts

3 comments

  1. 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
    
  2. 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.

Comments are closed.