Site Health: Improve the details provided by the REST API checks.

The descriptions provided whenever a REST API check failed lacked details that would help in troubleshooting any issues, most notably the actual REST API endpoint that was being tested.

Adding this vital piece of detail, along with a revamp of the error messages shown, where previously there was a risk that the markup of your website was included as an error message, improves the overall user experience, and gives more accurate details that can be looked when looking up how to fix or improve the behavior of the REST API.

Props dingo_d, shetheliving.
Fixes #54617.
Built from https://develop.svn.wordpress.org/trunk@54205


git-svn-id: http://core.svn.wordpress.org/trunk@53764 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Clorith 2022-09-19 15:30:09 +00:00
parent 94ae52c079
commit f277e8c168
2 changed files with 23 additions and 15 deletions

View File

@ -2052,7 +2052,7 @@ class WP_Site_Health {
),
'description' => sprintf(
'<p>%s</p>',
__( 'The REST API is one way WordPress, and other applications, communicate with the server. One example is the block editor screen, which relies on this to display, and save, your posts and pages.' )
__( 'The REST API is one way that WordPress and other applications communicate with the server. For example, the block editor screen relies on the REST API to display and save your posts and pages.' )
),
'actions' => '',
'test' => 'rest_availability',
@ -2090,16 +2090,18 @@ class WP_Site_Health {
$result['label'] = __( 'The REST API encountered an error' );
$result['description'] .= sprintf(
'<p>%s</p>',
'<p>%s</p><p>%s<br>%s</p>',
__( 'When testing the REST API, an error was encountered:' ),
sprintf(
'%s<br>%s',
__( 'The REST API request failed due to an error.' ),
sprintf(
/* translators: 1: The WordPress error message. 2: The WordPress error code. */
__( 'Error: %1$s (%2$s)' ),
$r->get_error_message(),
$r->get_error_code()
)
// translators: %s: The REST API URL.
__( 'REST API Endpoint: %s' ),
$url
),
sprintf(
// translators: 1: The WordPress error code. 2: The WordPress error message.
__( 'REST API Response: (%1$s) %2$s' ),
$r->get_error_code(),
$r->get_error_message()
)
);
} elseif ( 200 !== wp_remote_retrieve_response_code( $r ) ) {
@ -2108,12 +2110,18 @@ class WP_Site_Health {
$result['label'] = __( 'The REST API encountered an unexpected result' );
$result['description'] .= sprintf(
'<p>%s</p>',
'<p>%s</p><p>%s<br>%s</p>',
__( 'When testing the REST API, an unexpected result was returned:' ),
sprintf(
/* translators: 1: The HTTP error code. 2: The HTTP error message. */
__( 'The REST API call gave the following unexpected result: (%1$d) %2$s.' ),
// translators: %s: The REST API URL.
__( 'REST API Endpoint: %s' ),
$url
),
sprintf(
// translators: 1: The WordPress error code. 2: The HTTP status code error message.
__( 'REST API Response: (%1$s) %2$s' ),
wp_remote_retrieve_response_code( $r ),
esc_html( wp_remote_retrieve_body( $r ) )
wp_remote_retrieve_response_message( $r )
)
);
} else {

View File

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