Make WordPress Core

Ticket #36561: 36561-3-classify-trigger_error-calls.patch

File 36561-3-classify-trigger_error-calls.patch, 11.7 KB (added by jrf, 8 years ago)

Updated the patch + applied the same logic to the _deprecated_hook() function

  • src/wp-includes/compat.php

    From 807fed793f9c6842baa4eb7e4c5b6d87781fe7d2 Mon Sep 17 00:00:00 2001
    Date: Sun, 18 Jun 2017 15:49:43 +0200
    Subject: [PATCH] Deprecated notices should be classified as
     E_(USER_)DEPRECATED.
    
    ---
     src/wp-includes/compat.php    |  5 +++++
     src/wp-includes/functions.php | 45 ++++++++++++++++++++++++-------------------
     2 files changed, 30 insertions(+), 20 deletions(-)
    
    diff --git a/src/wp-includes/compat.php b/src/wp-includes/compat.php
    index 0ccee2d..24227d2 100644
    a b if ( ! function_exists( 'spl_autoload_register' ) ): 
    578578                return $GLOBALS['_wp_spl_autoloaders'];
    579579        }
    580580endif;
     581
     582// E_USER_DEPRECATED was introduced in PHP 5.3
     583if ( ! defined( 'E_USER_DEPRECATED' ) ) {
     584        define( 'E_USER_DEPRECATED', E_USER_WARNING );
     585}
  • src/wp-includes/functions.php

    diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php
    index 828f123..20f5a24 100644
    a b function absint( $maybeint ) { 
    38003800 * This function is to be used in every function that is deprecated.
    38013801 *
    38023802 * @since 2.5.0
     3803 * @since 4.9.0 The error type is now classified as E_USER_DEPRECATED (used to default to E_USER_NOTICE).
    38033804 * @access private
    38043805 *
    38053806 * @param string $function    The function that was called.
    function _deprecated_function( $function, $version, $replacement = null ) { 
    38303831                if ( function_exists( '__' ) ) {
    38313832                        if ( ! is_null( $replacement ) ) {
    38323833                                /* translators: 1: PHP function name, 2: version number, 3: alternative function name */
    3833                                 trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.'), $function, $version, $replacement ) );
     3834                                trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.'), $function, $version, $replacement ), E_USER_DEPRECATED );
    38343835                        } else {
    38353836                                /* translators: 1: PHP function name, 2: version number */
    3836                                 trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.'), $function, $version ) );
     3837                                trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.'), $function, $version ), E_USER_DEPRECATED );
    38373838                        }
    38383839                } else {
    38393840                        if ( ! is_null( $replacement ) ) {
    3840                                 trigger_error( sprintf( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.', $function, $version, $replacement ) );
     3841                                trigger_error( sprintf( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.', $function, $version, $replacement ), E_USER_DEPRECATED );
    38413842                        } else {
    3842                                 trigger_error( sprintf( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.', $function, $version ) );
     3843                                trigger_error( sprintf( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.', $function, $version ), E_USER_DEPRECATED );
    38433844                        }
    38443845                }
    38453846        }
    function _deprecated_function( $function, $version, $replacement = null ) { 
    38573858 *
    38583859 * @since 4.3.0
    38593860 * @since 4.5.0 Added the `$parent_class` parameter.
     3861 * @since 4.9.0 The error type is now classified as E_USER_DEPRECATED (used to default to E_USER_NOTICE).
    38603862 *
    38613863 * @access private
    38623864 *
    function _deprecated_constructor( $class, $version, $parent_class = '' ) { 
    38933895                        if ( ! empty( $parent_class ) ) {
    38943896                                /* translators: 1: PHP class name, 2: PHP parent class name, 3: version number, 4: __construct() method */
    38953897                                trigger_error( sprintf( __( 'The called constructor method for %1$s in %2$s is <strong>deprecated</strong> since version %3$s! Use %4$s instead.' ),
    3896                                         $class, $parent_class, $version, '<pre>__construct()</pre>' ) );
     3898                                        $class, $parent_class, $version, '<pre>__construct()</pre>' ), E_USER_DEPRECATED );
    38973899                        } else {
    38983900                                /* translators: 1: PHP class name, 2: version number, 3: __construct() method */
    38993901                                trigger_error( sprintf( __( 'The called constructor method for %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ),
    3900                                         $class, $version, '<pre>__construct()</pre>' ) );
     3902                                        $class, $version, '<pre>__construct()</pre>' ), E_USER_DEPRECATED );
    39013903                        }
    39023904                } else {
    39033905                        if ( ! empty( $parent_class ) ) {
    39043906                                trigger_error( sprintf( 'The called constructor method for %1$s in %2$s is <strong>deprecated</strong> since version %3$s! Use %4$s instead.',
    3905                                         $class, $parent_class, $version, '<pre>__construct()</pre>' ) );
     3907                                        $class, $parent_class, $version, '<pre>__construct()</pre>' ), E_USER_DEPRECATED );
    39063908                        } else {
    39073909                                trigger_error( sprintf( 'The called constructor method for %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.',
    3908                                         $class, $version, '<pre>__construct()</pre>' ) );
     3910                                        $class, $version, '<pre>__construct()</pre>' ), E_USER_DEPRECATED );
    39093911                        }
    39103912                }
    39113913        }
    function _deprecated_constructor( $class, $version, $parent_class = '' ) { 
    39243926 * This function is to be used in every file that is deprecated.
    39253927 *
    39263928 * @since 2.5.0
     3929 * @since 4.9.0 The error type is now classified as E_USER_DEPRECATED (used to default to E_USER_NOTICE).
    39273930 * @access private
    39283931 *
    39293932 * @param string $file        The file that was included.
    function _deprecated_file( $file, $version, $replacement = null, $message = '' ) 
    39583961                if ( function_exists( '__' ) ) {
    39593962                        if ( ! is_null( $replacement ) ) {
    39603963                                /* translators: 1: PHP file name, 2: version number, 3: alternative file name */
    3961                                 trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.'), $file, $version, $replacement ) . $message );
     3964                                trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.'), $file, $version, $replacement ) . $message, E_USER_DEPRECATED );
    39623965                        } else {
    39633966                                /* translators: 1: PHP file name, 2: version number */
    3964                                 trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.'), $file, $version ) . $message );
     3967                                trigger_error( sprintf( __('%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.'), $file, $version ) . $message, E_USER_DEPRECATED );
    39653968                        }
    39663969                } else {
    39673970                        if ( ! is_null( $replacement ) ) {
    3968                                 trigger_error( sprintf( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.', $file, $version, $replacement ) . $message );
     3971                                trigger_error( sprintf( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.', $file, $version, $replacement ) . $message, E_USER_DEPRECATED );
    39693972                        } else {
    3970                                 trigger_error( sprintf( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.', $file, $version ) . $message );
     3973                                trigger_error( sprintf( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.', $file, $version ) . $message, E_USER_DEPRECATED );
    39713974                        }
    39723975                }
    39733976        }
    function _deprecated_file( $file, $version, $replacement = null, $message = '' ) 
    39923995 * The current behavior is to trigger a user error if WP_DEBUG is true.
    39933996 *
    39943997 * @since 3.0.0
     3998 * @since 4.9.0 The error type is now classified as E_USER_DEPRECATED (used to default to E_USER_NOTICE).
    39953999 * @access private
    39964000 *
    39974001 * @param string $function The function that was called.
    function _deprecated_argument( $function, $version, $message = null ) { 
    40224026                if ( function_exists( '__' ) ) {
    40234027                        if ( ! is_null( $message ) ) {
    40244028                                /* translators: 1: PHP function name, 2: version number, 3: optional message regarding the change */
    4025                                 trigger_error( sprintf( __('%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s! %3$s'), $function, $version, $message ) );
     4029                                trigger_error( sprintf( __('%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s! %3$s'), $function, $version, $message ), E_USER_DEPRECATED );
    40264030                        } else {
    40274031                                /* translators: 1: PHP function name, 2: version number */
    4028                                 trigger_error( sprintf( __('%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s with no alternative available.'), $function, $version ) );
     4032                                trigger_error( sprintf( __('%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s with no alternative available.'), $function, $version ), E_USER_DEPRECATED );
    40294033                        }
    40304034                } else {
    40314035                        if ( ! is_null( $message ) ) {
    4032                                 trigger_error( sprintf( '%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s! %3$s', $function, $version, $message ) );
     4036                                trigger_error( sprintf( '%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s! %3$s', $function, $version, $message ), E_USER_DEPRECATED );
    40334037                        } else {
    4034                                 trigger_error( sprintf( '%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s with no alternative available.', $function, $version ) );
     4038                                trigger_error( sprintf( '%1$s was called with an argument that is <strong>deprecated</strong> since version %2$s with no alternative available.', $function, $version ), E_USER_DEPRECATED );
    40354039                        }
    40364040                }
    40374041        }
    function _deprecated_argument( $function, $version, $message = null ) { 
    40494053 * functions, and so generally does not need to be called directly.
    40504054 *
    40514055 * @since 4.6.0
     4056 * @since 4.9.0 The error type is now classified as E_USER_DEPRECATED (used to default to E_USER_NOTICE).
    40524057 * @access private
    40534058 *
    40544059 * @param string $hook        The hook that was used.
    function _deprecated_hook( $hook, $version, $replacement = null, $message = null 
    40814086                $message = empty( $message ) ? '' : ' ' . $message;
    40824087                if ( ! is_null( $replacement ) ) {
    40834088                        /* translators: 1: WordPress hook name, 2: version number, 3: alternative hook name */
    4084                         trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ), $hook, $version, $replacement ) . $message );
     4089                        trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ), $hook, $version, $replacement ) . $message, E_USER_DEPRECATED );
    40854090                } else {
    40864091                        /* translators: 1: WordPress hook name, 2: version number */
    4087                         trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ), $hook, $version ) . $message );
     4092                        trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ), $hook, $version ) . $message, E_USER_DEPRECATED );
    40884093                }
    40894094        }
    40904095}
    function _doing_it_wrong( $function, $message, $version ) { 
    41384143                                __( 'https://codex.wordpress.org/Debugging_in_WordPress' )
    41394144                        );
    41404145                        /* translators: Developer debugging message. 1: PHP function name, 2: Explanatory message, 3: Version information message */
    4141                         trigger_error( sprintf( __( '%1$s was called <strong>incorrectly</strong>. %2$s %3$s' ), $function, $message, $version ) );
     4146                        trigger_error( sprintf( __( '%1$s was called <strong>incorrectly</strong>. %2$s %3$s' ), $function, $message, $version ), E_USER_NOTICE );
    41424147                } else {
    41434148                        if ( is_null( $version ) ) {
    41444149                                $version = '';
    function _doing_it_wrong( $function, $message, $version ) { 
    41484153                        $message .= sprintf( ' Please see <a href="%s">Debugging in WordPress</a> for more information.',
    41494154                                'https://codex.wordpress.org/Debugging_in_WordPress'
    41504155                        );
    4151                         trigger_error( sprintf( '%1$s was called <strong>incorrectly</strong>. %2$s %3$s', $function, $message, $version ) );
     4156                        trigger_error( sprintf( '%1$s was called <strong>incorrectly</strong>. %2$s %3$s', $function, $message, $version ), E_USER_NOTICE );
    41524157                }
    41534158        }
    41544159}