Make WordPress Core

Opened 4 years ago

Last modified 4 years ago

#51336 new enhancement

Support php-error.php outside of WP_CONTENT_DIR

Reported by: brookedot's profile brookedot Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.2
Component: Site Health Keywords: reporter-feedback
Focuses: Cc:


Since 5.2 WordPress has supported a php-error.php drop-in which overwrites the error template:

This is happening in class-wp-fatal-error-handler.php on 143

// Load custom PHP error template, if present.
$php_error_pluggable = WP_CONTENT_DIR . '/php-error.php';

In some cases, WP_CONTENT_DIR is read-only which means that this file cannot be used to customize the message. I'm open to other solutions but at the moment, I would like to propose we add an additional constant here instead.

if ( defined( 'WP_CONTENT_DIR' ) ) {
        // Load custom PHP error template, if present.
        if ( defined( WP_ERROR_TEMPLATE_DIR ) {
                $php_error_pluggable_dir = WP_ERROR_TEMPLATE_DIR;
        } else {
                $php_error_pluggable_dir = WP_CONTENT_DIR;
        $php_error_pluggable = $php_error_pluggable_dir . '/php-error.php';
        if ( is_readable( $php_error_pluggable ) ) {
                require_once $php_error_pluggable;

That conditional could probably be simplified too :)

Change History (3)

#1 @knutsp
4 years ago

Hello, and welcome to Trac.

Is there a sane reason to set wp-content to read-only?

It's the location for all drop-ins, not just this one. It also used for uploads (by default) and often for cache. Everything else, but wp-content, set to read-only seems more sane.

#2 @johnbillion
4 years ago

  • Keywords close added

Also the read-ability of this directory shouldn't be a concern. php-error.php is not a file that WordPress dynamically creates, it just exists in the same way that plugin and theme files exist.

#3 @johnbillion
4 years ago

  • Keywords reporter-feedback added; close removed
Note: See TracTickets for help on using tickets.