Use meta generator to display options enabled
Describe the solution you'd like
We would like to have options enabled of WP Rocket being displayed in a meta generator.
We can use the same system than Elementor :
<meta name="generator" content="Elementor 3.23.4; features: e_optimized_css_loading, e_font_icon_svg, additional_custom_breakpoints, e_optimized_control_loading, e_lazyload; settings: css_print_method-external, google_font-enabled, font_display-swap">
This will allow us to to get useful informations (provided by http archive and queryable with Google studio) and for example :
- Impact of new feature to the CWV score on a large data set
- Distribution of WP Rocket versions
To discuss with product & engineering about how to format the list of features (and maybe exclusion) To note we will use regex then to parse/generate informations
https://wp-media.slack.com/archives/C06CQPWEJSK/p1724226102206429
I am putting back this issue in Needs grooming as I won't have the time to finish the grooming.
However some discussion have happened here about how to get enabled features list.
Also, I'm sharing a beginning of grooming:
Scope a Solution:
- Create a
Subscriber.phpin/inc/Engine/MetaGeneratorwith the following content:
<?php
declare(strict_types=1);
namespace WP_Rocket\Engine\MetaGenerator;
use WP_Rocket\Event_Management\Subscriber_Interface;
class Subscriber implements Subscriber_Interface {
/**
* Return an array of events that this subscriber listens to.
*
* @return array
*/
public static function get_subscribed_events(): array {
return [
'rocket_buffer' => 'add_meta_generator_tag',
];
}
public function add_meta_generator_tag(string $html): string {
return $html;
}
}
- Create a
ServiceProvider.phpin/inc/Engine/MetaGenerator:
<?php
declare(strict_types=1);
namespace WP_Rocket\Engine\MetaGenerator;
use WP_Rocket\Dependencies\League\Container\ServiceProvider\AbstractServiceProvider;
class ServiceProvider extends AbstractServiceProvider {
/**
* Array of services provided by this service provider
*
* @var array
*/
protected $provides = [
'meta_generator_subscriber',
];
/**
* Check if the service provider provides a specific service.
*
* @param string $id The id of the service.
*
* @return bool
*/
public function provides( string $id ): bool {
return in_array( $id, $this->provides, true );
}
/**
* Registers items with the container
*
* @return void
*/
public function register(): void {
$this->getContainer()->addShared('meta_generator_subscriber', Subscriber::class);
}
}
- Don't forget to update
Plugin.php
Scope a solution ✅
In each class featuring changes in the front-end (list in the related Notion doc):
- Update the method hooked on
rocket_bufferto add a comment into the HTML if the optimization is applied (<!-- WPR: feature_slug -->), except if the meta is disabled by the filterrocket_disable_meta_generator
In Engine\Support: add a new class Meta, with a dependency on the Data class and the Mobile Detect class
In Engine\Support\Meta:
- add a method to add the meta tag to the HTML, and remove the HTML comments, except if matching the conditions defined in the Notion doc
- add a method to generate the meta tag based on the HTML comments added, and also use the value of
do_rocket_generate_caching_files, and the type of caching (mobile or desktop) with the mobile detect
In Engine\Support\Subscriber:
- Add the new
Metaclass as a dependency - Add a new callback on
rocket_buffer, with a method calling theMetaclass method
In Engine\Support\ServiceProvider:
- Instantiate the new
Metaclass and update theSubscriberinstantiation
Add new tests to cover, update existing ones
Estimate the effort ✅
Effort [M]
LGTM
Related Notion https://www.notion.so/wpmedia/Use-meta-generator-to-display-options-enabled-053c28b25f2e43c0870b5c2a7eaf157f#11aed22a22f080fa90e4c1a0efe9c125