How do I set up Debugging?

I use a plugin for this issue. Even if debug is set to false, it still prints error to the screen in red.

It is easy and fast to create the plugin.

  • In your plugins folder in your wordpress install, create a new file and call it anything you like, for instance, debugger-plugin.php.

  • Open up your newly created file, and paste the following code in there and save it. (this code comes from this post on code.tutsplus.com/

    <?php
    /*
    Plugin Name: Debugger Plugin
    */
    function admin_alert_errors($errno, $errstr, $errfile, $errline){
    
        $errorType = array (
             E_ERROR                            => 'ERROR',
             E_CORE_ERROR           => 'CORE ERROR',
             E_COMPILE_ERROR        => 'COMPILE ERROR',
             E_USER_ERROR           => 'USER ERROR',
             E_RECOVERABLE_ERROR  => 'RECOVERABLE ERROR',
             E_WARNING              => 'WARNING',
             E_CORE_WARNING         => 'CORE WARNING',
             E_COMPILE_WARNING      => 'COMPILE WARNING',
             E_USER_WARNING         => 'USER WARNING',
             E_NOTICE               => 'NOTICE',
             E_USER_NOTICE          => 'USER NOTICE',
             E_DEPRECATED                   => 'DEPRECATED',
             E_USER_DEPRECATED      => 'USER_DEPRECATED',
             E_PARSE                => 'PARSING ERROR'
        );
    
        if (array_key_exists($errno, $errorType)) {
            $errname = $errorType[$errno];
        } else {
            $errname="UNKNOWN ERROR";
        }
    ob_start();?>
    <div class="error">
      <p>
        <strong><?php echo $errname; ?> Error: [<?php echo $errno; ?>] </strong><?php echo $errstr; ?><strong> <?php echo $errfile; ?></strong> on line <strong><?php echo $errline; ?></strong>
      <p/>
    </div>
    <?php
    echo ob_get_clean();
    }
    
    set_error_handler("admin_alert_errors", E_ERROR ^ E_CORE_ERROR ^ E_COMPILE_ERROR ^ E_USER_ERROR ^ E_RECOVERABLE_ERROR ^  E_WARNING ^  E_CORE_WARNING ^ E_COMPILE_WARNING ^ E_USER_WARNING ^ E_NOTICE ^  E_USER_NOTICE ^ E_DEPRECATED    ^  E_USER_DEPRECATED    ^  E_PARSE );
    
  • You can now activate your debugger plugin from the back-end whenever you want. No need to make changes to wp-config.php 🙂

Leave a Comment