Skip to content

Instantly share code, notes, and snippets.

@dd32
Last active January 13, 2023 00:52
Show Gist options
  • Save dd32/9ae857a09aa3f9117ece2ddab945041b to your computer and use it in GitHub Desktop.
Save dd32/9ae857a09aa3f9117ece2ddab945041b to your computer and use it in GitHub Desktop.
A quick WordPress 5.1 shutdown handler to disable the plugin/theme pausing features. Install as wp-content/fatal-error-handler.php. This is needed during development, and on sites which have sensitive plugins enabled which must never be deactivated. You should also consider adding a wp-content/php-error.php template. UPDATE: This is replaced by …
<?php
// UPDATE: This can be replaced by `define( 'WP_DISABLE_FATAL_ERROR_HANDLER', true );` in `wp-config.php`.
// See https://core.trac.wordpress.org/changeset/44674
/**
* Shutdown handler to disable WordPress 5.1's plugin/theme pausing features.
*/
class dd32_Fatal_Error_Handler extends WP_Fatal_Error_Handler {
// Do not store errors, this disables the ability for plugins/themes to be marked 'paused'.
protected function store_error( $error ) {
return false;
}
// Bland error page. No need to suggest logging into the backend.
protected function display_default_error_template() {
if ( ! function_exists( '__' ) ) {
wp_load_translations_early();
}
if ( ! function_exists( 'wp_die' ) ) {
require_once ABSPATH . WPINC . '/functions.php';
}
wp_die( __( 'The site is experiencing technical difficulties.' ), array( 'response' => 500 ) );
exit; // implied.
}
}
return new dd32_Fatal_Error_Handler();
@seebeen
Copy link

seebeen commented Jan 12, 2023

Can this be implemented as a MU plugin, or it needs to be placed only in the wp-content/fatal-error-handler.php?

@dd32
Copy link
Author

dd32 commented Jan 13, 2023

@seebeen This MUST be used as wp-content/fatal-error-handler.php as that's how you replace the WP_Fatal_Error_Handler class via https://developer.wordpress.org/reference/functions/wp_register_fatal_error_handler/.

Note however, that this is probably irrelevant now, as things have changed since 5.1's initial release and the introduction of the constants via https://core.trac.wordpress.org/changeset/44674.

I was going to say you could probably use the WP 5.2 wp_should_handle_php_error filter instead, but that for some odd reason doesn't filter the truthful value for fatal errors and only kicks in for non-fatals.. 🤷.

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