Add a Site Health section for consent mode
Add a section to the Site Kit Site Health to show if a user has enabled consent mode on their site. If possible, we could also display if Site Kit has detected the WP Consent API.
Sections to add:
- Consent mode: enabled/disabled
- WP Consent API: Detected/Not detected
Acceptance criteria
- Site Kit Site Health should show a new field labelled "Consent Mode", with the text "Enabled" or "Disabled" based on whether or not the site has Consent Mode enabled.
- Site Kit Site Health should show a new field labelled "WP Consent API", with the text "Detected" or "Not detected" based on whether or not the WP Consent API functionality is available on this site.
Implementation Brief
- [ ] In
includes/Core/Site_Health/Debug_Data.php:- [ ] Add a new
get_consent_mode_fieldsmethod. In this method:- [ ] It should return an associative multidimensional array with the named keys:
consent_modearrayconsent_api. Each key should have another associative array assigned as its value which should have the named keys:label,value, anddebug. The structure should follow as described below:- [ ]
consent_mode=>- [ ]
label=>Consent Mode(translatable). - [ ]
value=> This should either beEnabledorDisabled(translatable) based on whether Site Kit has Consent Mode enabled. - [ ]
debug=> This should either beenabledordisabledbased on whether Site Kit has Consent Mode enabled.
- [ ]
- [ ]
consent_api=>- [ ]
label=>WP Consent API(translatable). - [ ]
value=> This should either beDetectedorNot detected(translatable) based on whether WP Consent API functionality is available on the site. - [ ]
debug=> This should either bedetectedornot-detectedbased on whether WP Consent API functionality is available on the site.
- [ ]
- [ ]
- [ ] In order to determine if Site Kit has Consent Mode enabled, instantiate a new instance of the
Core\Consent_Mode\Consent_Mode_Settingsclass passing$this->optionsto its constructor, and call itsis_consent_mode_enabledmethod. - [ ] In order to determine if WP Consent API functionality is available on the site, check if the
wp_set_consentfunction exists (usingfunction_exists).
- [ ] It should return an associative multidimensional array with the named keys:
- [ ] Update the
get_fieldsmethod:- [ ] Right after the definition of the
$fieldsarray, update it by merging the array returned by theget_consent_mode_fieldsmethod to it.
- [ ] Right after the definition of the
- [ ] Add a new
Test Coverage
- [ ] In
tests/phpunit/integration/Core/Site_Health/Debug_DataTest.php:- [ ] Add a new test case verifying that the debug fields include the new Consent Mode keys with appropriate values.
QA Brief
Changelog entry
- In order to determine if Site Kit has Consent Mode enabled, instantiate a new instance of the
Core\Consent_Mode\Consent_Mode_Settingsclass passing$this->optionsto its constructor, and call itsis_consent_mode_enabledmethod.
@nfmohit this is not really how it should be done. Instead of creating a new instance, we need to either add a new filter that will allow us to add new fields in the consent class or add a filter that will indicate wether needed settings are enabled.
- In order to determine if Site Kit has Consent Mode enabled, instantiate a new instance of the
Core\Consent_Mode\Consent_Mode_Settingsclass passing$this->optionsto its constructor, and call itsis_consent_mode_enabledmethod.@nfmohit this is not really how it should be done. Instead of creating a new instance, we need to either add a new filter that will allow us to add new fields in the consent class or add a filter that will indicate wether needed settings are enabled.
I've updated the IB to add a new googlesitekit_is_consent_mode_enabled filter. Please let me know if it looks good now, thanks @eugene-manuilov!
I've updated the IB to add a new
googlesitekit_is_consent_mode_enabledfilter. Please let me know if it looks good now,
Yes, that is better, thanks, @nfmohit. But let's rename it to be googlesitekit_consent_mode_state or googlesitekit_consent_mode_status and make it return either enabled or disabled values that we can use for the debug property.
I've updated the IB to add a new
googlesitekit_is_consent_mode_enabledfilter. Please let me know if it looks good now,Yes, that is better, thanks, @nfmohit. But let's rename it to be
googlesitekit_consent_mode_stateorgooglesitekit_consent_mode_statusand make it return eitherenabledordisabledvalues that we can use for thedebugproperty.
Updated, thanks @eugene-manuilov!
IB ✔️
QA Update: ✅
Verified:
- The Consent Mode fields appear in the Site health info list.
- Tested turning on and off Consent Mode and the status changes.
- Tested activating and deactivating the WP Consent API plugin and the API status changes.
Screenshots