site-kit-wp
site-kit-wp copied to clipboard
Install/activate the WP Consent API plugin in the background.
Feature Description
As discussed on Slack, we should install and/or activate the WP Consent API plugin in the background, rather than opening the WP plugins page in a new tab to facilitate the installation/activation.
This will improve both the general UX and our capability for tracking the WP Consent API activation state, which will help to further inform how to improve the feature.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
- When the user clicks the install button in the Consent Mode "Install WP Consent API" panel in the Admin Settings, the WP Consent API plugin should:
- Be installed without redirecting the user to
wp-admin/update.php. - Be activated without redirecting the user to
wp-admin/plugins.php.
- Be installed without redirecting the user to
- The user should see an appropriate loading state, such as a spinner button, while backend requests are taking place in the background.
- If the plugin installation or activation fails, the user should see an appropriate warning message from the backend and allow the user to retry it.
Implementation Brief
- [ ] Update
includes/Core/Consent_Mode/Consent_Mode.php:- [ ] Define a new endpoint
POST:install-activate-wp-consent-api, by implementing theget_datapoint_definitionsmethod. - [ ] Implement the new endpoint by implementing the
create_data_requestmethod. When this endpoint is called:- [ ] Install the plugin using this approach: https://github.com/WordPress/WordPress/blob/master/wp-admin/update.php#L110-L125 https://github.com/WordPress/WordPress/blob/master/wp-admin/update.php#L142-L145
- [ ] Activate the plugin using the
activate_pluginfunction, throwing aWP_Errorif activation fails.
- [ ] Define a new endpoint
- [ ] Create a new fetch store to call the API, based on many examples here in the Analytics module, with the base name of
installActivateWPConsentAPI. - [ ] Update
assets/js/components/consent-mode/WPConsentAPIRequirements.js:- [ ] Update the "Install" button to use the
SpinnerButtoncomponent. - [ ] Update the onClick action to dispatch the new
installActivateWPConsentAPIaction.- [ ] While the action is resolving, show the spinner on the button
- [ ] If an error is returned, show the error message above the button styled as in the
ErrorNotice, see this comment. - [ ] If the plugin is installed and updated the existing success state should show
- [ ] Update the "Install" button to use the
Test Coverage
- No additional test coverage required.
QA Brief
Changelog entry
The ACs say we should enable the WP Consent API plugin, but they don't say when/under what conditions.
Enabling it automatically when it isn't enabled seems like a fine idea, but we shouldn't do it constantly, because then a user that explicitly disables it (for whatever reason) after we enabled it will return to the plugins page to see it "randomly" enabled again by us.
So we probably want to specify the conditions to enable it, and also a mechanism to only do so once.
Thanks, this makes sense 👍🏻
Moving to IB 👍🏻
Hey @benbowler, actually the AC for this needs a revision.
It's not the case that we want the WP Consent API plugin to be installed in direct response to the user enabling Consent Mode via the switch in settings.
We still want the trigger to be a click of the Install (or Activate) button, so the user is making an informed and deliberate choice to install the plugin.
At present when the Install/Activate button is clicked, the plugins page is navigated to, taking the user away from Site Kit. What this issue should accomplish is to install/activate the plugin in the background when the button is clicked, showing an in-progress state while doing so (i.e. a spinner in the button).
Please can you update the AC accordingly?
Hi @benbowler, thanks for updating the AC.
- It looks like the point about the
como_enableevent is now redundant and can be removed. - Also, it would be good to give some direction on how errors should be handled.
@benbowler thanks for the update. Please note I made a small change to tweak the proposed error text and fix a couple of typos.
That said - while I like the proposed error handling, I do have some reservations; for one, handling an error with "warning" styling is a bit out of step with other errors which tend to be displayed inline using the "error" red colour.
Also by showing a fixed error message, the underlying error we receive from the WP API is hidden and this might contain some valuable information as to why the plugin couldn't be installed.
Lastly the proposed message doesn't handle the activation case where the more appropriate guidance would be to navigate to the plugins page on the current WP instance and try activating there.
To be honest, I think we might be better off initially taking a simple approach where we display the error received inline using the usual error styling (as seen in ErrorNotice). This is what I had imagined when writing my previous feedback, I just wanted the AC to be a bit more explicit about it.
We can then iterate on it in a subsequent issue to provide more detailed error handling along the lines of what you have specced, but looking further into the possible errors received by the WP plugin API rather than having a single fixed message.
How does that sound?
Agreed @techanvil, I've simplified the AC removing implementation detail which can code in the IB based on the comments above.
Great, thanks @benbowler!
AC :white_check_mark:
Incidentally I don't think we'll need an explicit Retry button as the Install/Activate buttons will allow retrying...
IB ✅
QA Update ❌
- Tested on dev environment.
Issue- I use the Tweak extension to show error but error not reproduced for me. So, I use inspect element> Network settings to create error state.
- @zutigrm I noticed that if the internet is not available and the user clicks on the 'Install' button, the process gets stuck in a continuous loading state. This issue does not occur when the user clicks on the 'Activate' button without internet; instead, a backend error is displayed with a Retry button. Can we implement the same behavior for the 'Install' button?
Install Plugin: Gets stuck in a loading state-
Activate Plugin :
PASS CASES
- Verified when the user clicks the install button in the Consent Mode "Install WP Consent API" panel in the Admin Settings, the WP Consent API plugin : -- Gets installed without redirecting the user to wp-admin/update.php. -- Gets activated without redirecting the user to wp-admin/plugins.php.
- Verified the user see an appropriate loading state, such as a spinner button, while backend requests are taking place in the background.
https://github.com/user-attachments/assets/ff11fcd9-a282-4a70-9883-97993cc1efd7
QA Update ✅
- Tested on main environment.
- Verified continuous loading issue in offline mode is resolve now.
- Verified when the user clicks the install button in the Consent Mode "Install WP Consent API" panel in the Admin Settings, the WP Consent API plugin gets:
- Installed without redirecting the user to wp-admin/update.php.
- Gets activated without redirecting the user to wp-admin/plugins.php.
- Verified an appropriate loading state appears, such as a spinner button, while backend requests are taking place in the background.
- Verified if the plugin installation or activation fails, the user should sees an appropriate warning message from the backend and allow the user to retry it.
https://github.com/user-attachments/assets/5a14e712-17a6-4e7e-8fc0-e4d4c2609c86