WordPress.org

Make WordPress Core

Opened 14 months ago

Closed 8 months ago

Last modified 8 months ago

#50134 closed enhancement (fixed)

wp_fatal_error_handler_enabled doesn't actually do anything

Reported by: programmin Owned by: johnbillion
Milestone: 5.6 Priority: normal
Severity: normal Version: 5.2
Component: Site Health Keywords:
Focuses: docs Cc:

Description

Suppose you want to turn off the error handling... Try this in a mu-plugin:

<?php

function somethingg() { echo 'my code runs'; return false;
}
somethingg();
add_filter( 'wp_fatal_error_handler_enabled', 'somethingg' );

And add this to error-protection.php WP:

<?php
function wp_register_fatal_error_handler() {
        if ( ! wp_is_fatal_error_handler_enabled() ) {
                return;
        }
echo 'FATAL HANDLER = TRUE';

Now if you get an error (eg new NoneClass()) you will get the output:

FATAL HANDLER = TRUEmy code runs

There has been a critical error on your website. Please check your site admin email inbox for instructions.

So the filter apparently never is seen because the handler runs before the add_filter even had a chance to set it.

Change History (6)

#1 follow-up: @johnbillion
14 months ago

  • Component changed from General to Site Health
  • Keywords dev-feedback added
  • Version changed from 5.4.1 to 5.2

I believe the intention of this filter is that it can only be used before WordPress initialises, for example by constructing the $wp_filter array inside wp-config.php. @schlessera might be able to confirm this.

#2 in reply to: ↑ 1 @SergeyBiryukov
14 months ago

  • Focuses docs added

Replying to johnbillion:

I believe the intention of this filter is that it can only be used before WordPress initialises, for example by constructing the $wp_filter array inside wp-config.php.

That's my understanding too, as it runs too early to be used in a "normal" way. If that's the case, it could use a better documentation.

#3 @programmin
11 months ago

add_filter only works if WP is up? So yes if there is a specific way to do this then documentation should really show that the filter doesn't actually work, doesn't work like all the others work.

#4 @johnbillion
8 months ago

  • Keywords dev-feedback removed
  • Milestone changed from Awaiting Review to 5.6
  • Owner set to johnbillion
  • Status changed from new to accepted

#5 @johnbillion
8 months ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 49489:

Docs: Add more information about how to use filters that run before WordPress initialises.

Fixes #50134

#6 @johnbillion
8 months ago

  • Type changed from defect (bug) to enhancement
Note: See TracTickets for help on using tickets.