-
Notifications
You must be signed in to change notification settings - Fork 315
Description
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:
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
- Install the Disable REST API for Real plugin (or any other plugin that disables the REST API)
- 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 constantERROR_API_UNAVAILABLE
and update thecheckHealthChecks
function so that thecatch()
conditionally throws a different error depending on the response:- If the
error.code
isfetch_error
, then throwERROR_FETCH_FAIL
- Otherwise throw
ERROR_API_UNAVAILABLE
- If the
- edit
assets/js/components/setup/CompatibilityChecks/CompatibilityErrorNotice.js
. Import the new constantERROR_API_UNAVAILABLE
and 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 thecreateCompatibilityChecks
function:
return [ checkHostname, checkHealthChecks, registryCheckSetupTag( registry ), checkAMPConnectivity, checkWPVersion, ];
QA Brief
-
Install the Disable REST API for Real plugin (or any other plugin that disables the REST API)
-
Attempt Site Kit setup
-
Now with the REST API disabling plugin deactivated, configure the
wp-json/*
requests to be blocked (e.g. using Chrome Network request blocking) -
Check the splash page again
-
You should now see an alternate message about the staging environment
Changelog entry
- Improve the pre-setup compatibility checks to properly warn if the REST API is disabled instead of failing with an unexpected error.