As a customer, I want to control the display of Rocket Insights column view from WP Rocket website
GIVEN I'm a WP Rocket customer with valid license WHEN Related option on the website is deactivated THEN Rocket Insights column view will not be available for all users
GIVEN I'm a WP Rocket customer with valid license WHEN Related option on the website is activated THEN Rocket Insights column view will be available for all users like it is now
We will depend on the website API to enable/disable rocket insights column in post listing page (all post types) Even without knowing exactly the payload formats, we can have everything implemented, and simply finalize the payload parsing when it's completely defined. Starting with: Request:
GET api.wp-rocket.me/api/wp-rocket/plugin-settings.php
{
"email": "string", // same as in the user agent
"key": "string", // same as in the user agent
"domain": "string", // same as in the user agent
"wp_rocket_version": "string", // same as in the user agent
}
Response (200 case):
{
"success": boolean, // true
"data": {
"rocket_insights_display_post_column": boolean
}
}
Response (error case):
{
"success": boolean, // false
"error": {
"code": integer,
"message": string,
"details": {...}
}
}
We will deal with this API exactly as we deal with user endpoint so it'll be in a transient for a day and so on
Scope a Solution
1. Create API Client for Plugin Settings
New file: inc/Engine/License/API/PluginSettingsClient.php
- Follow same pattern as
UserClient.php(extend AbstractSafeAPIClient) - API endpoint:
https://api.wp-rocket.me/api/wp-rocket/plugin-settings.php - Request: POST with email, key, domain, version (same auth as user endpoint)
- Response: Returns
rocket_insights_display_post_columnboolean setting - Cache in transient for 24 hours
- Methods needed: get settings, flush cache, check if column display enabled
- Important: Default to
true(enabled) on any API error or missing data
2. Update Rocket Insights Context
Modify: inc/Engine/Admin/RocketInsights/Context/Context.php
- Inject the new PluginSettingsClient via constructor
- In
is_allowed()method, add check for the API setting - If API returns false, column should not display
- Keep existing checks (license, reseller, live site) as-is
3. Wire Dependencies in ServiceProvider
Modify: inc/Engine/Admin/RocketInsights/ServiceProvider.php
- Register PluginSettingsClient as shared service
- Update Context registration to inject the new client
- Follow existing service registration patterns in the file
4. Refresh Account Integration
Modify: inc/Engine/Admin/Settings/Settings.php (or relevant subscriber)
- When "Refresh Account" button is clicked, flush plugin settings cache
- This ensures users see updated settings immediately
@piotrbak
- How will it work for the reseller?
- This story applies to both free/paid RI?
- Will it be possible to control the display/hide column using the filter from the plugin side?
- If the WPR license has expired, then how will it work? i.e, if the related option was on /off before being expired.. and will the user be able to change the option from the website after being expired?
@Mai-Saad
- Reseller plugins have the Rocket Insights deactivated, no impact there
- It applies for both plans
- Yes
- Yes
In is_allowed() method, add check for the API setting
@Miraeld is_allowed method is used for context checking in every part of RI including the RI column, should we be adding this check for the API settings there? Given that this API settings is related to just RI column
@jeawhanlee This setting will be also used for other acqusition topics related to Rocket Insights in the future, not only column. The naming should consider that
@piotrbak With this new API Settings, when we disable it remotely on WPR website, do we also want to disable everything related to RI on every user site?
@jeawhanlee Only the column, Rocket Insights needs to be functional. But in the future, we'll introduce things that are similar to the column, and they'll be also deactivated with this setting
Initial test plan https://wpmediaqa.testrail.io/index.php?/runs/view/1167&group_by=cases:section_id&group_order=asc&display=tree (needs to be revisited after code implementation and may be updated accordingly)
@jeawhanlee Thanks for raising this point.
Here is an updated grooming, the update resides mostly in 3. Update Rocket Insights Context
Scope a Solution
1. Create API Client for Plugin Settings
New file: inc/Engine/License/API/PluginSettingsClient.php
- Follow same pattern as
UserClient.php(extend AbstractSafeAPIClient) - API endpoint:
https://api.wp-rocket.me/api/wp-rocket/plugin-settings.php - Request: POST with email, key, domain, version (same auth as user endpoint)
- Response: Returns
rocket_insights_display_post_columnboolean setting - Cache in transient for 24 hours
- Methods needed: get settings, flush cache, check if column display enabled
- Important: Default to
true(enabled) on any API error or missing data
2. Register Service in License Module
Modify: inc/Engine/License/ServiceProvider.php
- Add
PluginSettingsClientto imports and$providesarray - Register service:
$this->getContainer()->add( 'plugin_settings_client', PluginSettingsClient::class )->addArgument( 'options' );
3. Update Rocket Insights Context
Modify: inc/Engine/Admin/RocketInsights/Context/Context.php
- Inject
PluginSettingsClientvia constructor - Add NEW method
web_api_is_allowed()(do NOT modifyis_allowed()) - Method should check
is_allowed()first, then callplugin_settings_client->web_api_is_allowed() - Add filter
rocket_insights_column_display_allowedto allow plugin-side override
4. Update Post Listing Subscriber
Modify: inc/Engine/Admin/RocketInsights/PostListing/Subscriber.php
- Replace
$this->context->is_allowed()with$this->context->web_api_is_allowed()in:add_rocket_insights_column()should_enqueue_assets()render_rocket_insights_column()
5. Wire Dependencies in ServiceProvider
Modify: inc/Engine/Admin/RocketInsights/ServiceProvider.php
- Update Context registration to inject
plugin_settings_client
6. Refresh Account Integration
Modify: inc/Engine/Admin/RocketInsights/Managers/Plan.php
- In
remove_customer_data_cache()method, also flush plugin settings cache - Call
$plugin_settings_client->flush_cache()(get from container)
Add filter rocket_insights_column_display_allowed to allow plugin-side override
Don't think we'll need this as I believe we don't want this kind of freedom on the user part.
Other than that, LGTM