renakdup/whoops-wordpress-error-handler

Whoops PHP Error handler for WordPress.

1.1.3 2024-09-25 22:00 UTC

This package is auto-updated.

Last update: 2024-10-25 22:15:01 UTC


README

Total Downloads PHP Version Require Latest Stable Version License

Whoops PHP error handler for WordPress with different themes.
It catches fatal errors and exceptions and shows in beautiful format. We can see a stack trace, go through the stack trace to see the called parts in the code.
In the debug information we can find GET, POST, Files, Cookie, Session, Server/Request Data, Environment Variables.

Whoops Error Handler for WordPress

How to install WordPress error handler

  1. Require via Composer

    composer require renakdup/whoops-wordpress-error-handler

    Or if you want to use it just for local environment

    composer require renakdup/whoops-wordpress-error-handler --dev
  2. Create a file of mu-plugin by the address wp-content/mu-plugins/mu-plugins/whoops-error-handler.php:

    mkdir wp-content/mu-plugins
    touch wp-content/mu-plugins/whoops-error-handler.php
  3. Add the calling code to the file

    <?php
    // This checks necessary if you use the package as a dev dependency
    if ( ! class_exists( Renakdup\WhoopsErrorHandler\ErrorHandler::class ) ) {
         return;
    }
    
    $error_handler = new Renakdup\WhoopsErrorHandler\ErrorHandler();
    $error_handler->init();

That's it!

How to configure

Showing conditionals

By the default error handler isn't displayed for wp_get_environment_type() === 'production'.
If you want to exclude additional envs, you should use the filter:

add_filter( 'renakdup/whoops-error-handler/prohibited-envs', function ( $defaults ) {
	return array_merge( $defaults, [ 'staging', 'development' ] );
}, 10, 1);

If you want to disable error handler for some special conditionals then use this filer:

add_filter( 'renakdup/whoops-error-handler/not-enable', function ( $default ) {
	if ( ! WP_DEBUG || ! WP_DEBUG_DISPLAY ) {
		return true;
	}
}, 10, 1);

Themes

To use one of the available themes, you can pass theme's name while instantiating object.

 $error_handler = Renakdup\WhoopsErrorHandler\WhoopsErrorHandler( 'gray' );

Available themes

Smooth material dark

material-dark-smooth.png

$name = 'material-dark-smooth';

Material dark

material-dark-smooth.png

$name = 'material-dark';

Gray

material-dark-smooth.png

$name = 'gray';

Original optimized

material-dark-smooth.png

$name = 'original-optimized';

Original Default

material-dark-smooth.png

$name = 'default-original';