General: Use wp_trigger_error() in _doing_it_wrong() and _deprecated_*().

Uses `wp_trigger_error()` in `_doing_it_wrong()` and each `_deprecated_*()` function, i.e. instead of `trigger_error()`.

To avoid redundancy, uses `wp_trigger_error()` once. How? Saves each message to `$message` variable and then passes it to `wp_trigger_error()` at the end of the function.

Functions:
* _doing_it_wrong()
* _deprecated_function()
* _deprecated_constructor()
* _deprecated_class()
* _deprecated_file()
* _deprecated_argument()
* _deprecated_hook()

Follow-up to [56530].

Props azaozz, costdev, flixos90, hellofromTonya, peterwilsoncc.
See #57686.
Built from https://develop.svn.wordpress.org/trunk@56705


git-svn-id: http://core.svn.wordpress.org/trunk@56217 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
hellofromTonya 2023-09-26 11:51:19 +00:00
parent eeefd48208
commit c8aea02b38
2 changed files with 146 additions and 204 deletions

View File

@ -5468,49 +5468,39 @@ function _deprecated_function( $function_name, $version, $replacement = '' ) {
if ( WP_DEBUG && apply_filters( 'deprecated_function_trigger_error', true ) ) { if ( WP_DEBUG && apply_filters( 'deprecated_function_trigger_error', true ) ) {
if ( function_exists( '__' ) ) { if ( function_exists( '__' ) ) {
if ( $replacement ) { if ( $replacement ) {
trigger_error( $message = sprintf(
sprintf( /* translators: 1: PHP function name, 2: Version number, 3: Alternative function name. */
/* translators: 1: PHP function name, 2: Version number, 3: Alternative function name. */ __( 'Function %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ),
__( 'Function %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ), $function_name,
$function_name, $version,
$version, $replacement
$replacement
),
E_USER_DEPRECATED
); );
} else { } else {
trigger_error( $message = sprintf(
sprintf( /* translators: 1: PHP function name, 2: Version number. */
/* translators: 1: PHP function name, 2: Version number. */ __( 'Function %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ),
__( 'Function %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ), $function_name,
$function_name, $version
$version
),
E_USER_DEPRECATED
); );
} }
} else { } else {
if ( $replacement ) { if ( $replacement ) {
trigger_error( $message = sprintf(
sprintf( 'Function %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.',
'Function %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.', $function_name,
$function_name, $version,
$version, $replacement
$replacement
),
E_USER_DEPRECATED
); );
} else { } else {
trigger_error( $message = sprintf(
sprintf( 'Function %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.',
'Function %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.', $function_name,
$function_name, $version
$version
),
E_USER_DEPRECATED
); );
} }
} }
wp_trigger_error( '', $message, E_USER_DEPRECATED );
} }
} }
@ -5560,53 +5550,43 @@ function _deprecated_constructor( $class_name, $version, $parent_class = '' ) {
if ( WP_DEBUG && apply_filters( 'deprecated_constructor_trigger_error', true ) ) { if ( WP_DEBUG && apply_filters( 'deprecated_constructor_trigger_error', true ) ) {
if ( function_exists( '__' ) ) { if ( function_exists( '__' ) ) {
if ( $parent_class ) { if ( $parent_class ) {
trigger_error( $message = sprintf(
sprintf( /* translators: 1: PHP class name, 2: PHP parent class name, 3: Version number, 4: __construct() method. */
/* translators: 1: PHP class name, 2: PHP parent class name, 3: Version number, 4: __construct() method. */ __( 'The called constructor method for %1$s class in %2$s is <strong>deprecated</strong> since version %3$s! Use %4$s instead.' ),
__( 'The called constructor method for %1$s class in %2$s is <strong>deprecated</strong> since version %3$s! Use %4$s instead.' ), $class_name,
$class_name, $parent_class,
$parent_class, $version,
$version, '<code>__construct()</code>'
'<code>__construct()</code>'
),
E_USER_DEPRECATED
); );
} else { } else {
trigger_error( $message = sprintf(
sprintf( /* translators: 1: PHP class name, 2: Version number, 3: __construct() method. */
/* translators: 1: PHP class name, 2: Version number, 3: __construct() method. */ __( 'The called constructor method for %1$s class is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ),
__( 'The called constructor method for %1$s class is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ), $class_name,
$class_name, $version,
$version, '<code>__construct()</code>'
'<code>__construct()</code>'
),
E_USER_DEPRECATED
); );
} }
} else { } else {
if ( $parent_class ) { if ( $parent_class ) {
trigger_error( $message = sprintf(
sprintf( 'The called constructor method for %1$s class in %2$s is <strong>deprecated</strong> since version %3$s! Use %4$s instead.',
'The called constructor method for %1$s class in %2$s is <strong>deprecated</strong> since version %3$s! Use %4$s instead.', $class_name,
$class_name, $parent_class,
$parent_class, $version,
$version, '<code>__construct()</code>'
'<code>__construct()</code>'
),
E_USER_DEPRECATED
); );
} else { } else {
trigger_error( $message = sprintf(
sprintf( 'The called constructor method for %1$s class is <strong>deprecated</strong> since version %2$s! Use %3$s instead.',
'The called constructor method for %1$s class is <strong>deprecated</strong> since version %2$s! Use %3$s instead.', $class_name,
$class_name, $version,
$version, '<code>__construct()</code>'
'<code>__construct()</code>'
),
E_USER_DEPRECATED
); );
} }
} }
wp_trigger_error( '', $message, E_USER_DEPRECATED );
} }
} }
@ -5651,49 +5631,39 @@ function _deprecated_class( $class_name, $version, $replacement = '' ) {
if ( WP_DEBUG && apply_filters( 'deprecated_class_trigger_error', true ) ) { if ( WP_DEBUG && apply_filters( 'deprecated_class_trigger_error', true ) ) {
if ( function_exists( '__' ) ) { if ( function_exists( '__' ) ) {
if ( $replacement ) { if ( $replacement ) {
trigger_error( $message = sprintf(
sprintf( /* translators: 1: PHP class name, 2: Version number, 3: Alternative class or function name. */
/* translators: 1: PHP class name, 2: Version number, 3: Alternative class or function name. */ __( 'Class %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ),
__( 'Class %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ), $class_name,
$class_name, $version,
$version, $replacement
$replacement
),
E_USER_DEPRECATED
); );
} else { } else {
trigger_error( $message = sprintf(
sprintf( /* translators: 1: PHP class name, 2: Version number. */
/* translators: 1: PHP class name, 2: Version number. */ __( 'Class %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ),
__( 'Class %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ), $class_name,
$class_name, $version
$version
),
E_USER_DEPRECATED
); );
} }
} else { } else {
if ( $replacement ) { if ( $replacement ) {
trigger_error( $message = sprintf(
sprintf( 'Class %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.',
'Class %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.', $class_name,
$class_name, $version,
$version, $replacement
$replacement
),
E_USER_DEPRECATED
); );
} else { } else {
trigger_error( $message = sprintf(
sprintf( 'Class %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.',
'Class %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.', $class_name,
$class_name, $version
$version
),
E_USER_DEPRECATED
); );
} }
} }
wp_trigger_error( '', $message, E_USER_DEPRECATED );
} }
} }
@ -5743,49 +5713,39 @@ function _deprecated_file( $file, $version, $replacement = '', $message = '' ) {
if ( function_exists( '__' ) ) { if ( function_exists( '__' ) ) {
if ( $replacement ) { if ( $replacement ) {
trigger_error( $message = sprintf(
sprintf( /* translators: 1: PHP file name, 2: Version number, 3: Alternative file name. */
/* translators: 1: PHP file name, 2: Version number, 3: Alternative file name. */ __( 'File %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ),
__( 'File %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ), $file,
$file, $version,
$version, $replacement
$replacement ) . $message;
) . $message,
E_USER_DEPRECATED
);
} else { } else {
trigger_error( $message = sprintf(
sprintf( /* translators: 1: PHP file name, 2: Version number. */
/* translators: 1: PHP file name, 2: Version number. */ __( 'File %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ),
__( 'File %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ), $file,
$file, $version
$version ) . $message;
) . $message,
E_USER_DEPRECATED
);
} }
} else { } else {
if ( $replacement ) { if ( $replacement ) {
trigger_error( $message = sprintf(
sprintf( 'File %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.',
'File %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.', $file,
$file, $version,
$version, $replacement
$replacement
) . $message,
E_USER_DEPRECATED
); );
} else { } else {
trigger_error( $message = sprintf(
sprintf( 'File %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.',
'File %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.', $file,
$file, $version
$version ) . $message;
) . $message,
E_USER_DEPRECATED
);
} }
} }
wp_trigger_error( '', $message, E_USER_DEPRECATED );
} }
} }
/** /**
@ -5837,49 +5797,39 @@ function _deprecated_argument( $function_name, $version, $message = '' ) {
if ( WP_DEBUG && apply_filters( 'deprecated_argument_trigger_error', true ) ) { if ( WP_DEBUG && apply_filters( 'deprecated_argument_trigger_error', true ) ) {
if ( function_exists( '__' ) ) { if ( function_exists( '__' ) ) {
if ( $message ) { if ( $message ) {
trigger_error( $message = sprintf(
sprintf( /* translators: 1: PHP function name, 2: Version number, 3: Optional message regarding the change. */
/* translators: 1: PHP function name, 2: Version number, 3: Optional message regarding the change. */ __( 'Function %1$s was called with an argument that is <strong>deprecated</strong> since version %2$s! %3$s' ),
__( 'Function %1$s was called with an argument that is <strong>deprecated</strong> since version %2$s! %3$s' ), $function_name,
$function_name, $version,
$version, $message
$message
),
E_USER_DEPRECATED
); );
} else { } else {
trigger_error( $message = sprintf(
sprintf( /* translators: 1: PHP function name, 2: Version number. */
/* translators: 1: PHP function name, 2: Version number. */ __( 'Function %1$s was called with an argument that is <strong>deprecated</strong> since version %2$s with no alternative available.' ),
__( 'Function %1$s was called with an argument that is <strong>deprecated</strong> since version %2$s with no alternative available.' ), $function_name,
$function_name, $version
$version
),
E_USER_DEPRECATED
); );
} }
} else { } else {
if ( $message ) { if ( $message ) {
trigger_error( $message = sprintf(
sprintf( 'Function %1$s was called with an argument that is <strong>deprecated</strong> since version %2$s! %3$s',
'Function %1$s was called with an argument that is <strong>deprecated</strong> since version %2$s! %3$s', $function_name,
$function_name, $version,
$version, $message
$message
),
E_USER_DEPRECATED
); );
} else { } else {
trigger_error( $message = sprintf(
sprintf( 'Function %1$s was called with an argument that is <strong>deprecated</strong> since version %2$s with no alternative available.',
'Function %1$s was called with an argument that is <strong>deprecated</strong> since version %2$s with no alternative available.', $function_name,
$function_name, $version
$version
),
E_USER_DEPRECATED
); );
} }
} }
wp_trigger_error( '', $message, E_USER_DEPRECATED );
} }
} }
@ -5928,27 +5878,23 @@ function _deprecated_hook( $hook, $version, $replacement = '', $message = '' ) {
$message = empty( $message ) ? '' : ' ' . $message; $message = empty( $message ) ? '' : ' ' . $message;
if ( $replacement ) { if ( $replacement ) {
trigger_error( $message = sprintf(
sprintf( /* translators: 1: WordPress hook name, 2: Version number, 3: Alternative hook name. */
/* translators: 1: WordPress hook name, 2: Version number, 3: Alternative hook name. */ __( 'Hook %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ),
__( 'Hook %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ), $hook,
$hook, $version,
$version, $replacement
$replacement ) . $message;
) . $message,
E_USER_DEPRECATED
);
} else { } else {
trigger_error( $message = sprintf(
sprintf( /* translators: 1: WordPress hook name, 2: Version number. */
/* translators: 1: WordPress hook name, 2: Version number. */ __( 'Hook %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ),
__( 'Hook %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ), $hook,
$hook, $version
$version ) . $message;
) . $message,
E_USER_DEPRECATED
);
} }
wp_trigger_error( '', $message, E_USER_DEPRECATED );
} }
} }
@ -6004,15 +5950,12 @@ function _doing_it_wrong( $function_name, $message, $version ) {
__( 'https://wordpress.org/documentation/article/debugging-in-wordpress/' ) __( 'https://wordpress.org/documentation/article/debugging-in-wordpress/' )
); );
trigger_error( $message = sprintf(
sprintf( /* translators: Developer debugging message. 1: PHP function name, 2: Explanatory message, 3: WordPress version number. */
/* translators: Developer debugging message. 1: PHP function name, 2: Explanatory message, 3: WordPress version number. */ __( 'Function %1$s was called <strong>incorrectly</strong>. %2$s %3$s' ),
__( 'Function %1$s was called <strong>incorrectly</strong>. %2$s %3$s' ), $function_name,
$function_name, $message,
$message, $version
$version
),
E_USER_NOTICE
); );
} else { } else {
if ( $version ) { if ( $version ) {
@ -6024,16 +5967,15 @@ function _doing_it_wrong( $function_name, $message, $version ) {
'https://wordpress.org/documentation/article/debugging-in-wordpress/' 'https://wordpress.org/documentation/article/debugging-in-wordpress/'
); );
trigger_error( $message = sprintf(
sprintf( 'Function %1$s was called <strong>incorrectly</strong>. %2$s %3$s',
'Function %1$s was called <strong>incorrectly</strong>. %2$s %3$s', $function_name,
$function_name, $message,
$message, $version
$version
),
E_USER_NOTICE
); );
} }
wp_trigger_error( '', $message );
} }
} }

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '6.4-alpha-56704'; $wp_version = '6.4-alpha-56705';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.