wp-rocket icon indicating copy to clipboard operation
wp-rocket copied to clipboard

Use meta generator to display options enabled

Open jbma opened this issue 1 year ago • 5 comments

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

jbma avatar Aug 21 '24 07:08 jbma

https://wp-media.slack.com/archives/C06CQPWEJSK/p1724226102206429

MathieuLamiot avatar Aug 21 '24 07:08 MathieuLamiot

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.php in /inc/Engine/MetaGenerator with 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.php in /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

Miraeld avatar Oct 07 '24 14:10 Miraeld

Scope a solution ✅

In each class featuring changes in the front-end (list in the related Notion doc):

  • Update the method hooked on rocket_buffer to add a comment into the HTML if the optimization is applied (<!-- WPR: feature_slug -->), except if the meta is disabled by the filter rocket_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 Meta class as a dependency
  • Add a new callback on rocket_buffer, with a method calling the Meta class method

In Engine\Support\ServiceProvider:

  • Instantiate the new Meta class and update the Subscriber instantiation

Add new tests to cover, update existing ones

Estimate the effort ✅

Effort [M]

remyperona avatar Oct 08 '24 19:10 remyperona

LGTM

Khadreal avatar Oct 10 '24 10:10 Khadreal

Related Notion https://www.notion.so/wpmedia/Use-meta-generator-to-display-options-enabled-053c28b25f2e43c0870b5c2a7eaf157f#11aed22a22f080fa90e4c1a0efe9c125

Mai-Saad avatar Oct 21 '24 08:10 Mai-Saad