From 979a52690290f2134e2ab6129f5c443112c9df2b Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Fri, 1 Nov 2019 00:41:01 +0000 Subject: [PATCH] Code Modernization: Pass an appropriate error level to `trigger_error()` in `_doing_it_wrong()` and related functions: * `_deprecated_function()` * `_deprecated_argument()` * `_deprecated_constructor()` * `_deprecated_file()` The error level passed is `E_USER_DEPRECATED` for the deprecated function group and `E_USER_NOTICE` for `_doing_it_wrong()`. Props jrf. Fixes #36561. Built from https://develop.svn.wordpress.org/trunk@46625 git-svn-id: http://core.svn.wordpress.org/trunk@46422 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/functions.php | 194 ++++++++++++++++++++++++++++++++------ wp-includes/version.php | 2 +- 2 files changed, 166 insertions(+), 30 deletions(-) diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 3a2199bd36..7ef5b63f6f 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -4548,6 +4548,7 @@ function absint( $maybeint ) { * * @since 2.5.0 * @since 5.4.0 This function is no longer marked as "private". + * @since 5.4.0 The error type is now classified as E_USER_DEPRECATED (used to default to E_USER_NOTICE). * * @param string $function The function that was called. * @param string $version The version of WordPress that deprecated the function. @@ -4576,17 +4577,47 @@ function _deprecated_function( $function, $version, $replacement = null ) { if ( WP_DEBUG && apply_filters( 'deprecated_function_trigger_error', true ) ) { if ( function_exists( '__' ) ) { if ( ! is_null( $replacement ) ) { - /* translators: 1: PHP function name, 2: Version number, 3: Alternative function name. */ - trigger_error( sprintf( __( '%1$s is deprecated since version %2$s! Use %3$s instead.' ), $function, $version, $replacement ) ); + trigger_error( + sprintf( + /* translators: 1: PHP function name, 2: Version number, 3: Alternative function name. */ + __( '%1$s is deprecated since version %2$s! Use %3$s instead.' ), + $function, + $version, + $replacement + ), + E_USER_DEPRECATED + ); } else { - /* translators: 1: PHP function name, 2: Version number. */ - trigger_error( sprintf( __( '%1$s is deprecated since version %2$s with no alternative available.' ), $function, $version ) ); + trigger_error( + sprintf( + /* translators: 1: PHP function name, 2: Version number. */ + __( '%1$s is deprecated since version %2$s with no alternative available.' ), + $function, + $version + ), + E_USER_DEPRECATED + ); } } else { if ( ! is_null( $replacement ) ) { - trigger_error( sprintf( '%1$s is deprecated since version %2$s! Use %3$s instead.', $function, $version, $replacement ) ); + trigger_error( + sprintf( + '%1$s is deprecated since version %2$s! Use %3$s instead.', + $function, + $version, + $replacement + ), + E_USER_DEPRECATED + ); } else { - trigger_error( sprintf( '%1$s is deprecated since version %2$s with no alternative available.', $function, $version ) ); + trigger_error( + sprintf( + '%1$s is deprecated since version %2$s with no alternative available.', + $function, + $version + ), + E_USER_DEPRECATED + ); } } } @@ -4605,6 +4636,7 @@ function _deprecated_function( $function, $version, $replacement = null ) { * @since 4.3.0 * @since 4.5.0 Added the `$parent_class` parameter. * @since 5.4.0 This function is no longer marked as "private". + * @since 5.4.0 The error type is now classified as E_USER_DEPRECATED (used to default to E_USER_NOTICE). * * @param string $class The class containing the deprecated constructor. * @param string $version The version of WordPress that deprecated the function. @@ -4645,7 +4677,8 @@ function _deprecated_constructor( $class, $version, $parent_class = '' ) { $parent_class, $version, '
__construct()
' - ) + ), + E_USER_DEPRECATED ); } else { trigger_error( @@ -4655,7 +4688,8 @@ function _deprecated_constructor( $class, $version, $parent_class = '' ) { $class, $version, '
__construct()
' - ) + ), + E_USER_DEPRECATED ); } } else { @@ -4667,7 +4701,8 @@ function _deprecated_constructor( $class, $version, $parent_class = '' ) { $parent_class, $version, '
__construct()
' - ) + ), + E_USER_DEPRECATED ); } else { trigger_error( @@ -4676,7 +4711,8 @@ function _deprecated_constructor( $class, $version, $parent_class = '' ) { $class, $version, '
__construct()
' - ) + ), + E_USER_DEPRECATED ); } } @@ -4697,6 +4733,7 @@ function _deprecated_constructor( $class, $version, $parent_class = '' ) { * * @since 2.5.0 * @since 5.4.0 This function is no longer marked as "private". + * @since 5.4.0 The error type is now classified as E_USER_DEPRECATED (used to default to E_USER_NOTICE). * * @param string $file The file that was included. * @param string $version The version of WordPress that deprecated the file. @@ -4727,19 +4764,50 @@ function _deprecated_file( $file, $version, $replacement = null, $message = '' ) */ if ( WP_DEBUG && apply_filters( 'deprecated_file_trigger_error', true ) ) { $message = empty( $message ) ? '' : ' ' . $message; + if ( function_exists( '__' ) ) { if ( ! is_null( $replacement ) ) { - /* translators: 1: PHP file name, 2: Version number, 3: Alternative file name. */ - trigger_error( sprintf( __( '%1$s is deprecated since version %2$s! Use %3$s instead.' ), $file, $version, $replacement ) . $message ); + trigger_error( + sprintf( + /* translators: 1: PHP file name, 2: Version number, 3: Alternative file name. */ + __( '%1$s is deprecated since version %2$s! Use %3$s instead.' ), + $file, + $version, + $replacement + ) . $message, + E_USER_DEPRECATED + ); } else { - /* translators: 1: PHP file name, 2: Version number. */ - trigger_error( sprintf( __( '%1$s is deprecated since version %2$s with no alternative available.' ), $file, $version ) . $message ); + trigger_error( + sprintf( + /* translators: 1: PHP file name, 2: Version number. */ + __( '%1$s is deprecated since version %2$s with no alternative available.' ), + $file, + $version + ) . $message, + E_USER_DEPRECATED + ); } } else { if ( ! is_null( $replacement ) ) { - trigger_error( sprintf( '%1$s is deprecated since version %2$s! Use %3$s instead.', $file, $version, $replacement ) . $message ); + trigger_error( + sprintf( + '%1$s is deprecated since version %2$s! Use %3$s instead.', + $file, + $version, + $replacement + ) . $message, + E_USER_DEPRECATED + ); } else { - trigger_error( sprintf( '%1$s is deprecated since version %2$s with no alternative available.', $file, $version ) . $message ); + trigger_error( + sprintf( + '%1$s is deprecated since version %2$s with no alternative available.', + $file, + $version + ) . $message, + E_USER_DEPRECATED + ); } } } @@ -4764,6 +4832,7 @@ function _deprecated_file( $file, $version, $replacement = null, $message = '' ) * * @since 3.0.0 * @since 5.4.0 This function is no longer marked as "private". + * @since 5.4.0 The error type is now classified as E_USER_DEPRECATED (used to default to E_USER_NOTICE). * * @param string $function The function that was called. * @param string $version The version of WordPress that deprecated the argument used. @@ -4792,17 +4861,47 @@ function _deprecated_argument( $function, $version, $message = null ) { if ( WP_DEBUG && apply_filters( 'deprecated_argument_trigger_error', true ) ) { if ( function_exists( '__' ) ) { if ( ! is_null( $message ) ) { - /* translators: 1: PHP function name, 2: Version number, 3: Optional message regarding the change. */ - trigger_error( sprintf( __( '%1$s was called with an argument that is deprecated since version %2$s! %3$s' ), $function, $version, $message ) ); + trigger_error( + sprintf( + /* translators: 1: PHP function name, 2: Version number, 3: Optional message regarding the change. */ + __( '%1$s was called with an argument that is deprecated since version %2$s! %3$s' ), + $function, + $version, + $message + ), + E_USER_DEPRECATED + ); } else { - /* translators: 1: PHP function name, 2: Version number. */ - trigger_error( sprintf( __( '%1$s was called with an argument that is deprecated since version %2$s with no alternative available.' ), $function, $version ) ); + trigger_error( + sprintf( + /* translators: 1: PHP function name, 2: Version number. */ + __( '%1$s was called with an argument that is deprecated since version %2$s with no alternative available.' ), + $function, + $version + ), + E_USER_DEPRECATED + ); } } else { if ( ! is_null( $message ) ) { - trigger_error( sprintf( '%1$s was called with an argument that is deprecated since version %2$s! %3$s', $function, $version, $message ) ); + trigger_error( + sprintf( + '%1$s was called with an argument that is deprecated since version %2$s! %3$s', + $function, + $version, + $message + ), + E_USER_DEPRECATED + ); } else { - trigger_error( sprintf( '%1$s was called with an argument that is deprecated since version %2$s with no alternative available.', $function, $version ) ); + trigger_error( + sprintf( + '%1$s was called with an argument that is deprecated since version %2$s with no alternative available.', + $function, + $version + ), + E_USER_DEPRECATED + ); } } } @@ -4820,6 +4919,7 @@ function _deprecated_argument( $function, $version, $message = null ) { * functions, and so generally does not need to be called directly. * * @since 4.6.0 + * @since 5.4.0 The error type is now classified as E_USER_DEPRECATED (used to default to E_USER_NOTICE). * @access private * * @param string $hook The hook that was used. @@ -4850,12 +4950,28 @@ function _deprecated_hook( $hook, $version, $replacement = null, $message = null */ if ( WP_DEBUG && apply_filters( 'deprecated_hook_trigger_error', true ) ) { $message = empty( $message ) ? '' : ' ' . $message; + if ( ! is_null( $replacement ) ) { - /* translators: 1: WordPress hook name, 2: Version number, 3: Alternative hook name. */ - trigger_error( sprintf( __( '%1$s is deprecated since version %2$s! Use %3$s instead.' ), $hook, $version, $replacement ) . $message ); + trigger_error( + sprintf( + /* translators: 1: WordPress hook name, 2: Version number, 3: Alternative hook name. */ + __( '%1$s is deprecated since version %2$s! Use %3$s instead.' ), + $hook, + $version, + $replacement + ) . $message, + E_USER_DEPRECATED + ); } else { - /* translators: 1: WordPress hook name, 2: Version number. */ - trigger_error( sprintf( __( '%1$s is deprecated since version %2$s with no alternative available.' ), $hook, $version ) . $message ); + trigger_error( + sprintf( + /* translators: 1: WordPress hook name, 2: Version number. */ + __( '%1$s is deprecated since version %2$s with no alternative available.' ), + $hook, + $version + ) . $message, + E_USER_DEPRECATED + ); } } } @@ -4908,24 +5024,44 @@ function _doing_it_wrong( $function, $message, $version ) { /* translators: %s: Version number. */ $version = sprintf( __( '(This message was added in version %s.)' ), $version ); } + $message .= ' ' . sprintf( /* translators: %s: Documentation URL. */ __( 'Please see Debugging in WordPress for more information.' ), __( 'https://wordpress.org/support/article/debugging-in-wordpress/' ) ); - /* translators: Developer debugging message. 1: PHP function name, 2: Explanatory message, 3: Version information message. */ - trigger_error( sprintf( __( '%1$s was called incorrectly. %2$s %3$s' ), $function, $message, $version ) ); + + trigger_error( + sprintf( + /* translators: Developer debugging message. 1: PHP function name, 2: Explanatory message, 3: Version information message. */ + __( '%1$s was called incorrectly. %2$s %3$s' ), + $function, + $message, + $version + ), + E_USER_NOTICE + ); } else { if ( is_null( $version ) ) { $version = ''; } else { $version = sprintf( '(This message was added in version %s.)', $version ); } + $message .= sprintf( ' Please see Debugging in WordPress for more information.', 'https://wordpress.org/support/article/debugging-in-wordpress/' ); - trigger_error( sprintf( '%1$s was called incorrectly. %2$s %3$s', $function, $message, $version ) ); + + trigger_error( + sprintf( + '%1$s was called incorrectly. %2$s %3$s', + $function, + $message, + $version + ), + E_USER_NOTICE + ); } } } diff --git a/wp-includes/version.php b/wp-includes/version.php index 53b4edf3e5..00e32399fd 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.4-alpha-46624'; +$wp_version = '5.4-alpha-46625'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.