REST API: Correct the check for `$version` argument in `rest_handle_doing_it_wrong()`.

Move `WP_REST_Response` and `WP_Error` class names out of the translatable string.

Follow-up to [48327], [48361].

See #36271.
Built from https://develop.svn.wordpress.org/trunk@48367


git-svn-id: http://core.svn.wordpress.org/trunk@48136 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2020-07-07 09:56:02 +00:00
parent 371dbf6dcf
commit 24ed3a9a30
3 changed files with 19 additions and 10 deletions

View File

@ -4039,7 +4039,16 @@ function _wp_json_prepare_data( $data ) {
*/
function wp_send_json( $response, $status_code = null ) {
if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
_doing_it_wrong( __FUNCTION__, __( 'Return a WP_REST_Response or WP_Error object from your callback when using the REST API.' ), '5.5.0' );
_doing_it_wrong(
__FUNCTION__,
sprintf(
/* translators: 1: WP_REST_Response, 2: WP_Error */
__( 'Return a %1$s or %2$s object from your callback when using the REST API.' ),
'WP_REST_Response',
'WP_Error'
),
'5.5.0'
);
}
if ( ! headers_sent() ) {
@ -5184,7 +5193,7 @@ function _doing_it_wrong( $function, $message, $version ) {
trigger_error(
sprintf(
/* translators: Developer debugging message. 1: PHP function name, 2: Explanatory message, 3: Version information message. */
/* translators: Developer debugging message. 1: PHP function name, 2: Explanatory message, 3: WordPress version number. */
__( '%1$s was called <strong>incorrectly</strong>. %2$s %3$s' ),
$function,
$message,

View File

@ -588,7 +588,7 @@ function rest_handle_deprecated_argument( $function, $message, $version ) {
if ( ! WP_DEBUG || headers_sent() ) {
return;
}
if ( ! empty( $message ) ) {
if ( $message ) {
/* translators: 1: Function name, 2: WordPress version number, 3: Error message. */
$string = sprintf( __( '%1$s (since %2$s; %3$s)' ), $function, $version, $message );
} else {
@ -613,14 +613,14 @@ function rest_handle_doing_it_wrong( $function, $message, $version ) {
return;
}
if ( is_null( $version ) ) {
/* translators: Developer debugging message. 1: PHP function name, 2: Explanatory message */
$string = __( '%1$s (%2$s)' );
$string = sprintf( $string, $function, $message );
} else {
/* translators: Developer debugging message. 1: PHP function name, 2: Version information message, 3: Explanatory message. */
if ( $version ) {
/* translators: Developer debugging message. 1: PHP function name, 2: WordPress version number, 3: Explanatory message. */
$string = __( '%1$s (since %2$s; %3$s)' );
$string = sprintf( $string, $function, $version, $message );
} else {
/* translators: Developer debugging message. 1: PHP function name, 2: Explanatory message. */
$string = __( '%1$s (%2$s)' );
$string = sprintf( $string, $function, $message );
}
header( sprintf( 'X-WP-DoingItWrong: %s', $string ) );

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.5-alpha-48365';
$wp_version = '5.5-alpha-48367';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.