Make WordPress Core

Changeset 54205


Ignore:
Timestamp:
09/19/2022 03:28:33 PM (2 years ago)
Author:
Clorith
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-site-health.php

    r54196 r54205  
    20532053            'description' => sprintf(
    20542054                '<p>%s</p>',
    2055                 __( '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.' )
     2055                __( '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.' )
    20562056            ),
    20572057            'actions'     => '',
     
    20912091
    20922092            $result['description'] .= sprintf(
    2093                 '<p>%s</p>',
     2093                '<p>%s</p><p>%s<br>%s</p>',
     2094                __( 'When testing the REST API, an error was encountered:' ),
    20942095                sprintf(
    2095                     '%s<br>%s',
    2096                     __( 'The REST API request failed due to an error.' ),
    2097                     sprintf(
    2098                         /* translators: 1: The WordPress error message. 2: The WordPress error code. */
    2099                         __( 'Error: %1$s (%2$s)' ),
    2100                         $r->get_error_message(),
    2101                         $r->get_error_code()
    2102                     )
     2096                    // translators: %s: The REST API URL.
     2097                    __( 'REST API Endpoint: %s' ),
     2098                    $url
     2099                ),
     2100                sprintf(
     2101                    // translators: 1: The WordPress error code. 2: The WordPress error message.
     2102                    __( 'REST API Response: (%1$s) %2$s' ),
     2103                    $r->get_error_code(),
     2104                    $r->get_error_message()
    21032105                )
    21042106            );
     
    21092111
    21102112            $result['description'] .= sprintf(
    2111                 '<p>%s</p>',
     2113                '<p>%s</p><p>%s<br>%s</p>',
     2114                __( 'When testing the REST API, an unexpected result was returned:' ),
    21122115                sprintf(
    2113                     /* translators: 1: The HTTP error code. 2: The HTTP error message. */
    2114                     __( 'The REST API call gave the following unexpected result: (%1$d) %2$s.' ),
     2116                    // translators: %s: The REST API URL.
     2117                    __( 'REST API Endpoint: %s' ),
     2118                    $url
     2119                ),
     2120                sprintf(
     2121                    // translators: 1: The WordPress error code. 2: The HTTP status code error message.
     2122                    __( 'REST API Response: (%1$s) %2$s' ),
    21152123                    wp_remote_retrieve_response_code( $r ),
    2116                     esc_html( wp_remote_retrieve_body( $r ) )
     2124                    wp_remote_retrieve_response_message( $r )
    21172125                )
    21182126            );
Note: See TracChangeset for help on using the changeset viewer.