这是indexloc提供的服务,不要输入任何密码
Skip to content

Improve setup compatibility check when REST API disabled #2101

@jamesozzie

Description

@jamesozzie

Bug Description

Some users have plugins enabled which disable the WP REST API. While in most cases these plugins disable for non authenticated users only there are some plugins that perform this across the board. When this is identified there could be a notice during the compatibility check to inform users of this incompatibility.

Example experience of trying to activate Site Kit with the REST API disable. The "Checking compatibility" bar remains in a loading stage:

restapi

Console errors below:

/site1/wp-json/googl…-tag?_locale=user:1 Failed to load resource: the server responded with a status of 404 (Not Found)
googlesitekit-api.da…6da1ee23aecb8c.js:1 Google Site Kit API Error 
Object
additional_errors: []
code: "wp_die"
data: {status: 404}
message: "Page not found."
__proto__: Object
/site1/wp-json/googl…gin/?_locale=user:1 Failed to load resource: the server responded with a status of 404 (Not Found)
googlesitekit-api.da…6da1ee23aecb8c.js:1 Google Site Kit API Error 
Object
additional_errors: []
code: "wp_die"
data: {status: 404}
message: "Page not found."
__proto__: Object
googlesitekit-vendor…f97beee5846d93.js:1 Uncaught (in promise) 
Object
additional_errors: []
code: "wp_die"
data: {status: 404}
message: "Page not found."
__proto__: Object
  1. Install the Disable REST API for Real plugin (or any other plugin that disables the REST API)
  2. Attempt SK setup (or even try view the dashboards if already connected)

Additional Context

  • We have had support topics open whereby users has such plugins installed
  • Most of these plugins don't impact SK reporting, only restricting access for non authenticated users
  • Happy to share a login if required for testing site

Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

  • When the WordPress REST API is disabled or for some other reason unreachable from the client, it shouldn't block the Site Kit compatibility checks before setup.
  • Instead a warning should be shown "Site Kit cannot access the WordPress REST API. Please ensure it is enabled on your site."

Implementation Brief

  • edit assets/js/components/setup/CompatibilityChecks/constants.js and add a new constant:
    export const ERROR_API_UNAVAILABLE = 'check_api_unavailable';
  • edit assets/js/components/setup/CompatibilityChecks/checks.js. Import the new constant ERROR_API_UNAVAILABLE and update the checkHealthChecks function so that the catch() conditionally throws a different error depending on the response:
    • If the error.code is fetch_error, then throw ERROR_FETCH_FAIL
    • Otherwise throw ERROR_API_UNAVAILABLE
  • edit assets/js/components/setup/CompatibilityChecks/CompatibilityErrorNotice.js. Import the new constant ERROR_API_UNAVAILABLEand add a case to the CompatibilityErrorNotice function for the new error message:
    case ERROR_API_UNAVAILABLE: return ( <p> { __( 'Site Kit cannot access the WordPress REST API. Please ensure it is enabled on your site.', 'google-site-kit' ) } </p> );
  • edit assets/js/components/setup/CompatibilityChecks/index.js and change the order of the checks array returned by the createCompatibilityChecks function:
    return [ checkHostname, checkHealthChecks, registryCheckSetupTag( registry ), checkAMPConnectivity, checkWPVersion, ];

QA Brief

  1. Install the Disable REST API for Real plugin (or any other plugin that disables the REST API)

  2. Attempt Site Kit setup

  3. See warning about REST API disabled
    image

  4. Now with the REST API disabling plugin deactivated, configure the wp-json/* requests to be blocked (e.g. using Chrome Network request blocking)

  5. Check the splash page again

  6. You should now see an alternate message about the staging environment
    image

Changelog entry

  • Improve the pre-setup compatibility checks to properly warn if the REST API is disabled instead of failing with an unexpected error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Good First IssueGood first issue for new engineersP1Medium priorityType: EnhancementImprovement of an existing featureType: SupportSupport request

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions