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
This commit is contained in:
Sergey Biryukov 2019-11-01 00:41:01 +00:00
parent be91e3e1b9
commit 979a526902
2 changed files with 166 additions and 30 deletions

View File

@ -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 <strong>deprecated</strong> 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 <strong>deprecated</strong> 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 <strong>deprecated</strong> since version %2$s with no alternative available.' ), $function, $version ) );
trigger_error(
sprintf(
/* translators: 1: PHP function name, 2: Version number. */
__( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ),
$function,
$version
),
E_USER_DEPRECATED
);
}
} else {
if ( ! is_null( $replacement ) ) {
trigger_error( sprintf( '%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.', $function, $version, $replacement ) );
trigger_error(
sprintf(
'%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.',
$function,
$version,
$replacement
),
E_USER_DEPRECATED
);
} else {
trigger_error( sprintf( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.', $function, $version ) );
trigger_error(
sprintf(
'%1$s is <strong>deprecated</strong> 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,
'<pre>__construct()</pre>'
)
),
E_USER_DEPRECATED
);
} else {
trigger_error(
@ -4655,7 +4688,8 @@ function _deprecated_constructor( $class, $version, $parent_class = '' ) {
$class,
$version,
'<pre>__construct()</pre>'
)
),
E_USER_DEPRECATED
);
}
} else {
@ -4667,7 +4701,8 @@ function _deprecated_constructor( $class, $version, $parent_class = '' ) {
$parent_class,
$version,
'<pre>__construct()</pre>'
)
),
E_USER_DEPRECATED
);
} else {
trigger_error(
@ -4676,7 +4711,8 @@ function _deprecated_constructor( $class, $version, $parent_class = '' ) {
$class,
$version,
'<pre>__construct()</pre>'
)
),
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 <strong>deprecated</strong> 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 <strong>deprecated</strong> 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 <strong>deprecated</strong> 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 <strong>deprecated</strong> 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 <strong>deprecated</strong> since version %2$s! Use %3$s instead.', $file, $version, $replacement ) . $message );
trigger_error(
sprintf(
'%1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.',
$file,
$version,
$replacement
) . $message,
E_USER_DEPRECATED
);
} else {
trigger_error( sprintf( '%1$s is <strong>deprecated</strong> since version %2$s with no alternative available.', $file, $version ) . $message );
trigger_error(
sprintf(
'%1$s is <strong>deprecated</strong> 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 <strong>deprecated</strong> 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 <strong>deprecated</strong> 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 <strong>deprecated</strong> 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 <strong>deprecated</strong> 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 <strong>deprecated</strong> since version %2$s! %3$s', $function, $version, $message ) );
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
);
} else {
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 ) );
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
);
}
}
}
@ -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 <strong>deprecated</strong> 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 <strong>deprecated</strong> 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 <strong>deprecated</strong> 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 <strong>deprecated</strong> 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 <a href="%s">Debugging in WordPress</a> 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 <strong>incorrectly</strong>. %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 <strong>incorrectly</strong>. %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 <a href="%s">Debugging in WordPress</a> for more information.',
'https://wordpress.org/support/article/debugging-in-wordpress/'
);
trigger_error( sprintf( '%1$s was called <strong>incorrectly</strong>. %2$s %3$s', $function, $message, $version ) );
trigger_error(
sprintf(
'%1$s was called <strong>incorrectly</strong>. %2$s %3$s',
$function,
$message,
$version
),
E_USER_NOTICE
);
}
}
}

View File

@ -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.