From ce10049fcc486401ea076a00dac708d7cb3d6710 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 24 Aug 2020 10:46:30 +0000 Subject: [PATCH] Administration: Don't print the `.php-error` class in the admin header for PHP notices in `wp-config.php`. Any notices in that file happen before `WP_DEBUG` takes effect, and should not be displayed with the `error_reporting` level previously set in `wp-load.php`. Adding the class when there is no notice displayed results in extra padding under the admin bar, which should be avoided. Follow-up to [20102], [21025], [26620], [47745]. Props akissz, tw2113, laxman-prajapati, sabernhardt, johnbillion, SergeyBiryukov. Fixes #51073. git-svn-id: https://develop.svn.wordpress.org/trunk@48850 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/admin-header.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/wp-admin/admin-header.php b/src/wp-admin/admin-header.php index 34d83d750a..7c59ec0baf 100644 --- a/src/wp-admin/admin-header.php +++ b/src/wp-admin/admin-header.php @@ -198,11 +198,19 @@ if ( $current_screen->is_block_editor() ) { } } +$error = error_get_last(); + // Print a CSS class to make PHP errors visible. -if ( error_get_last() && WP_DEBUG && WP_DEBUG_DISPLAY && ini_get( 'display_errors' ) ) { +if ( $error && WP_DEBUG && WP_DEBUG_DISPLAY && ini_get( 'display_errors' ) + // Don't print the class for PHP notices in wp-config.php, as they happen before WP_DEBUG takes effect, + // and should not be displayed with the `error_reporting` level previously set in wp-load.php. + && ( E_NOTICE !== $error['type'] || 'wp-config.php' !== wp_basename( $error['file'] ) ) +) { $admin_body_class .= ' php-error'; } +unset( $error ); + ?>