Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use meta generator to display options enabled #6879

Closed
jbma opened this issue Aug 21, 2024 · 5 comments · Fixed by #7034
Closed

Use meta generator to display options enabled #6879

jbma opened this issue Aug 21, 2024 · 5 comments · Fixed by #7034
Assignees
Labels
effort: [M] 3-5 days of estimated development time needs: documentation Issues which need to create or update a documentation type: enhancement Improvements that slightly enhance existing functionality and are fast to implement
Milestone

Comments

@jbma
Copy link
Contributor

jbma commented Aug 21, 2024

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

@MathieuLamiot
Copy link
Contributor

@piotrbak piotrbak added this to the 3.17.1 milestone Aug 21, 2024
@piotrbak piotrbak added type: enhancement Improvements that slightly enhance existing functionality and are fast to implement needs: grooming labels Sep 26, 2024
@piotrbak piotrbak modified the milestones: 3.17.1, 3.17.2 Oct 6, 2024
@Miraeld Miraeld self-assigned this Oct 7, 2024
@Miraeld
Copy link
Contributor

Miraeld commented Oct 7, 2024

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 Miraeld removed their assignment Oct 7, 2024
@remyperona
Copy link
Contributor

remyperona commented Oct 8, 2024

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 remyperona self-assigned this Oct 8, 2024
@remyperona remyperona added effort: [S] 1-2 days of estimated development time and removed needs: grooming labels Oct 8, 2024
@remyperona remyperona added the effort: [M] 3-5 days of estimated development time label Oct 9, 2024
@Khadreal
Copy link
Contributor

LGTM

@piotrbak piotrbak added the needs: documentation Issues which need to create or update a documentation label Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort: [M] 3-5 days of estimated development time needs: documentation Issues which need to create or update a documentation type: enhancement Improvements that slightly enhance existing functionality and are fast to implement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants