Make WordPress Core

Ticket #51383: 51383.2.diff

File 51383.2.diff, 3.3 KB (added by mcaskill, 13 months ago)

Add filter to preempt printing the .php-error CSS class to make PHP errors visible

  • src/wp-admin/admin-header.php

    diff --git a/src/wp-admin/admin-header.php b/src/wp-admin/admin-header.php
    index 3306c9125b..ab648dec49 100644
    a b if ( $current_screen->is_block_editor() ) { 
    212212$error_get_last = error_get_last();
    213213
    214214// Print a CSS class to make PHP errors visible.
    215 if ( $error_get_last && WP_DEBUG && WP_DEBUG_DISPLAY && ini_get( 'display_errors' )
    216         // Don't print the class for PHP notices in wp-config.php, as they happen before WP_DEBUG takes effect,
    217         // and should not be displayed with the `error_reporting` level previously set in wp-load.php.
    218         && ( E_NOTICE !== $error_get_last['type'] || 'wp-config.php' !== wp_basename( $error_get_last['file'] ) )
    219 ) {
    220         $admin_body_class .= ' php-error';
     215if ( $error_get_last && WP_DEBUG && WP_DEBUG_DISPLAY && ini_get( 'display_errors' ) ) {
     216        /**
     217         * Filters whether to preempt printing the CSS class to make PHP errors visible.
     218         *
     219         * Returning false will NOT print the CSS class.
     220         *
     221         * @param bool  $print Whether to print the CSS class. Default true.
     222         * @param array $error {
     223         *     Error information returned by `error_get_last()`.
     224         *
     225         *     @type int    $type    The error type.
     226         *     @type string $file    The name of the file in which the error occurred.
     227         *     @type int    $line    The line number in which the error occurred.
     228         *     @type string $message The error message.
     229         * }
     230         */
     231        if ( apply_filters( 'pre_admin_php_error_class', true, $error_get_last ) ) {
     232                $admin_body_class .= ' php-error';
     233        }
    221234}
    222235
    223236unset( $error_get_last );
  • src/wp-admin/includes/admin-filters.php

    diff --git a/src/wp-admin/includes/admin-filters.php b/src/wp-admin/includes/admin-filters.php
    index 33354cb073..30ecd0483f 100644
    a b add_action( 'admin_head', 'wp_site_icon' ); 
    5151add_action( 'admin_head', 'wp_admin_viewport_meta' );
    5252add_action( 'customize_controls_head', 'wp_admin_viewport_meta' );
    5353add_filter( 'nav_menu_meta_box_object', '_wp_nav_menu_meta_box_object' );
     54add_filter( 'pre_admin_php_error_class', '_pre_admin_php_error_class', 1, 2 );
    5455
    5556// Prerendering.
    5657if ( ! is_customize_preview() ) {
  • src/wp-admin/includes/misc.php

    diff --git a/src/wp-admin/includes/misc.php b/src/wp-admin/includes/misc.php
    index 78c1aab1c8..27e2534baa 100644
    a b function wp_check_php_version() { 
    16261626
    16271627        return $response;
    16281628}
     1629
     1630/**
     1631 * Checks if the PHP error should be visible.
     1632 *
     1633 * Does not print the CSS class for PHP notices in wp-config.php, as they happen
     1634 * before WP_DEBUG takes effect, and should not be displayed with the `error_reporting`
     1635 * level previously set in wp-load.php.
     1636 *
     1637 * @access private
     1638 *
     1639 * @param bool  $print Whether to print the CSS class.
     1640 * @param array $error {
     1641 *     Error information returned by `error_get_last()`.
     1642 *
     1643 *     @type int    $type    The error type.
     1644 *     @type string $file    The name of the file in which the error occurred.
     1645 *     @type int    $line    The line number in which the error occurred.
     1646 *     @type string $message The error message.
     1647 * }
     1648 * @return bool Array of PHP version data. False on failure.
     1649 */
     1650function _pre_admin_php_error_class( $print, $error ) {
     1651        return ( E_NOTICE !== $error['type'] || 'wp-config.php' !== wp_basename( $error['file'] ) );
     1652}