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 plugin slug for generator tag #1103

Merged
merged 4 commits into from Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion load.php
Expand Up @@ -57,7 +57,8 @@ function perflab_get_generator_content() {
}

return sprintf(
'Performance Lab %1$s; plugins: %2$s',
// Use the plugin slug as it is immutable.
'performance-lab %1$s; plugins: %2$s',
PERFLAB_VERSION,
implode( ', ', $active_plugins )
);
Expand Down
3 changes: 2 additions & 1 deletion plugins/dominant-color-images/hooks.php
Expand Up @@ -178,6 +178,7 @@ function dominant_color_add_inline_style() {
* @since 1.0.0
*/
function dominant_color_render_generator() {
echo '<meta name="generator" content="Image Placeholders ' . esc_attr( DOMINANT_COLOR_IMAGES_VERSION ) . '">' . "\n";
// Use the plugin slug as it is immutable.
echo '<meta name="generator" content="dominant-color-images ' . esc_attr( DOMINANT_COLOR_IMAGES_VERSION ) . '">' . "\n";
}
add_action( 'wp_head', 'dominant_color_render_generator' );
1 change: 1 addition & 0 deletions plugins/dominant-color-images/readme.txt
Expand Up @@ -52,6 +52,7 @@ Contributions are always welcome! Learn more about how to get involved in the [C
= 1.1.0 =

* Rename plugin to "Image Placeholders". ([1101](https://github.com/WordPress/performance/pull/1101))
* Use plugin slug for generator tag. ([1103](https://github.com/WordPress/performance/pull/1103))
* Bump minimum required WP version to 6.4. ([1062](https://github.com/WordPress/performance/pull/1062))
* Update tested WordPress version to 6.5. ([1027](https://github.com/WordPress/performance/pull/1027))

Expand Down
3 changes: 2 additions & 1 deletion plugins/embed-optimizer/hooks.php
Expand Up @@ -162,6 +162,7 @@ function embed_optimizer_trigger_error( string $function_name, string $message,
* @since 0.1.0
*/
function embed_optimizer_render_generator() {
echo '<meta name="generator" content="Embed Optimizer ' . esc_attr( EMBED_OPTIMIZER_VERSION ) . '">' . "\n";
// Use the plugin slug as it is immutable.
echo '<meta name="generator" content="embed-optimizer ' . esc_attr( EMBED_OPTIMIZER_VERSION ) . '">' . "\n";
}
add_action( 'wp_head', 'embed_optimizer_render_generator' );
1 change: 1 addition & 0 deletions plugins/embed-optimizer/readme.txt
Expand Up @@ -51,6 +51,7 @@ The [plugin source code](https://github.com/WordPress/performance/tree/trunk/plu

= 0.1.1 =

* Use plugin slug for generator tag. ([1103](https://github.com/WordPress/performance/pull/1103))
* Bump minimum required WP version to 6.4. ([1076](https://github.com/WordPress/performance/pull/1076))

= 0.1.0 =
Expand Down
3 changes: 2 additions & 1 deletion plugins/optimization-detective/helper.php
Expand Up @@ -18,5 +18,6 @@
* @since 0.1.0
*/
function od_render_generator_meta_tag() {
echo '<meta name="generator" content="Optimization Detective ' . esc_attr( OPTIMIZATION_DETECTIVE_VERSION ) . '">' . "\n";
// Use the plugin slug as it is immutable.
echo '<meta name="generator" content="optimization-detective ' . esc_attr( OPTIMIZATION_DETECTIVE_VERSION ) . '">' . "\n";
}
4 changes: 2 additions & 2 deletions plugins/optimization-detective/load.php
Expand Up @@ -5,7 +5,7 @@
* Description: Uses real user metrics to improve heuristics WordPress applies on the frontend to improve image loading priority.
* Requires at least: 6.4
* Requires PHP: 7.0
* Version: 0.1.0
* Version: 0.1.1
* Author: WordPress Performance Team
* Author URI: https://make.wordpress.org/performance/
* License: GPLv2 or later
Expand Down Expand Up @@ -43,7 +43,7 @@
);
}

define( 'OPTIMIZATION_DETECTIVE_VERSION', '0.1.0' );
define( 'OPTIMIZATION_DETECTIVE_VERSION', '0.1.1' );

require_once __DIR__ . '/helper.php';

Expand Down
6 changes: 5 additions & 1 deletion plugins/optimization-detective/readme.txt
Expand Up @@ -4,7 +4,7 @@ Contributors: wordpressdotorg
Requires at least: 6.4
Tested up to: 6.5
Requires PHP: 7.0
Stable tag: 0.1.0
Stable tag: 0.1.1
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Tags: performance, images
Expand Down Expand Up @@ -137,6 +137,10 @@ The [plugin source code](https://github.com/WordPress/performance/tree/trunk/plu

== Changelog ==

= 0.1.1 =

* Use plugin slug for generator tag. ([1103](https://github.com/WordPress/performance/pull/1103))
felixarntz marked this conversation as resolved.
Show resolved Hide resolved

= 0.1.0 =

* Initial release.
3 changes: 2 additions & 1 deletion plugins/speculation-rules/hooks.php
Expand Up @@ -54,6 +54,7 @@ function plsr_print_speculation_rules() {
* @since 1.1.0
*/
function plsr_render_generator_meta_tag() {
echo '<meta name="generator" content="Speculative Loading ' . esc_attr( SPECULATION_RULES_VERSION ) . '">' . "\n";
// Use the plugin slug as it is immutable.
echo '<meta name="generator" content="speculation-rules ' . esc_attr( SPECULATION_RULES_VERSION ) . '">' . "\n";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably want to bump the plugin version as well, otherwise users won't get this update.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adamsilverstein That version is already bumped (and not published), so this PR doesn't need to bump it again. :)

}
add_action( 'wp_head', 'plsr_render_generator_meta_tag' );
3 changes: 2 additions & 1 deletion plugins/webp-uploads/hooks.php
Expand Up @@ -770,7 +770,8 @@ function webp_uploads_modify_webp_quality( $quality, $mime_type ) {
* @since 1.0.0
*/
function webp_uploads_render_generator() {
echo '<meta name="generator" content="Modern Image Formats ' . esc_attr( WEBP_UPLOADS_VERSION ) . '">' . "\n";
// Use the plugin slug as it is immutable.
echo '<meta name="generator" content="webp-uploads ' . esc_attr( WEBP_UPLOADS_VERSION ) . '">' . "\n";
}
add_action( 'wp_head', 'webp_uploads_render_generator' );

Expand Down
1 change: 1 addition & 0 deletions plugins/webp-uploads/readme.txt
Expand Up @@ -64,6 +64,7 @@ By default, the Modern Image Formats plugin will only generate WebP versions of

* Add link to WebP settings to plugins table. ([1036](https://github.com/WordPress/performance/pull/1036))
* Rename plugin to "Modern Image Formats". ([1101](https://github.com/WordPress/performance/pull/1101))
* Use plugin slug for generator tag. ([1103](https://github.com/WordPress/performance/pull/1103))
* Bump minimum required WP version to 6.4. ([1062](https://github.com/WordPress/performance/pull/1062))
* Update tested WordPress version to 6.5. ([1027](https://github.com/WordPress/performance/pull/1027))

Expand Down
4 changes: 2 additions & 2 deletions tests/load-tests.php
Expand Up @@ -8,13 +8,13 @@
class Load_Tests extends WP_UnitTestCase {

public function test_perflab_get_generator_content() {
$expected = 'Performance Lab ' . PERFLAB_VERSION . '; plugins: ';
$expected = 'performance-lab ' . PERFLAB_VERSION . '; plugins: ';
$content = perflab_get_generator_content();
$this->assertSame( $expected, $content );
}

public function test_perflab_render_generator() {
$expected = '<meta name="generator" content="Performance Lab ' . PERFLAB_VERSION . '; plugins: ">' . "\n";
$expected = '<meta name="generator" content="performance-lab ' . PERFLAB_VERSION . '; plugins: ">' . "\n";
$output = get_echo( 'perflab_render_generator' );
$this->assertSame( $expected, $output );

Expand Down
12 changes: 12 additions & 0 deletions tests/plugins/dominant-color-images/dominant-color-test.php
Expand Up @@ -371,4 +371,16 @@ public function provider_get_hex_color() {
),
);
}

/**
* Test printing the meta generator tag.
*
* @covers ::dominant_color_render_generator
*/
public function test_dominant_color_render_generator() {
$tag = get_echo( 'dominant_color_render_generator' );
$this->assertStringStartsWith( '<meta', $tag );
$this->assertStringContainsString( 'generator', $tag );
$this->assertStringContainsString( 'dominant-color-images ' . DOMINANT_COLOR_IMAGES_VERSION, $tag );
}
}
8 changes: 6 additions & 2 deletions tests/plugins/embed-optimizer/embed-optimizer-test.php
Expand Up @@ -7,6 +7,11 @@

class Embed_Optimizer_Helper_Tests extends WP_UnitTestCase {

public function test_hooks() {
$this->assertSame( 10, has_filter( 'embed_oembed_html', 'embed_optimizer_filter_oembed_html' ) );
$this->assertSame( 10, has_action( 'wp_head', 'embed_optimizer_render_generator' ) );
}

/**
* Test that the oEmbed HTML is filtered.
*
Expand Down Expand Up @@ -163,10 +168,9 @@ function ( array $attrs, string $javascript ) {
* @covers ::embed_optimizer_render_generator
*/
public function test_embed_optimizer_render_generator() {
$this->assertSame( 10, has_action( 'wp_head', 'embed_optimizer_render_generator' ) );
$tag = get_echo( 'embed_optimizer_render_generator' );
$this->assertStringStartsWith( '<meta', $tag );
$this->assertStringContainsString( 'generator', $tag );
$this->assertStringContainsString( EMBED_OPTIMIZER_VERSION, $tag );
$this->assertStringContainsString( 'embed-optimizer ' . EMBED_OPTIMIZER_VERSION, $tag );
}
}
2 changes: 1 addition & 1 deletion tests/plugins/optimization-detective/helper-tests.php
Expand Up @@ -16,6 +16,6 @@ public function test_od_render_generator_meta_tag() {
$tag = get_echo( 'od_render_generator_meta_tag' );
$this->assertStringStartsWith( '<meta', $tag );
$this->assertStringContainsString( 'generator', $tag );
$this->assertStringContainsString( 'Optimization Detective ' . OPTIMIZATION_DETECTIVE_VERSION, $tag );
$this->assertStringContainsString( 'optimization-detective ' . OPTIMIZATION_DETECTIVE_VERSION, $tag );
}
}
17 changes: 17 additions & 0 deletions tests/plugins/speculation-rules/speculation-rules-test.php
Expand Up @@ -19,6 +19,11 @@ public function tear_down() {
parent::tear_down();
}

public function test_hooks() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. I don't think we are validating that hooks are always present for each of the plugins. Should this type of test be added everywhere, since I don't believe we can run tests against the output of wp_head to confirm that these are actually being printed without introducing side effects?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joemcgill I generally like to have this kind of test as it helps prevent accidents with hooks added or removed, but I wouldn't want to mandate it. IMO it's a good practice, but I still think this is something we can leave up to the typical freedom of choice of the respective plugin developers / PR authors and PR reviewers.

I only added this here since the hook check previously was baked into the generator test method, which IMO it shouldn't be since it's a different kind of test.

$this->assertSame( 10, has_action( 'wp_footer', 'plsr_print_speculation_rules' ) );
$this->assertSame( 10, has_action( 'wp_head', 'plsr_render_generator_meta_tag' ) );
}

public function data_provider_to_test_print_speculation_rules(): array {
return array(
'xhtml' => array(
Expand Down Expand Up @@ -56,4 +61,16 @@ public function test_plsr_print_speculation_rules_without_html5_support( bool $h
$this->assertStringContainsString( '/* <![CDATA[ */', wp_get_inline_script_tag( '/*...*/' ) );
}
}

/**
* Test printing the meta generator tag.
*
* @covers ::plsr_render_generator_meta_tag
*/
public function test_plsr_render_generator_meta_tag() {
$tag = get_echo( 'plsr_render_generator_meta_tag' );
$this->assertStringStartsWith( '<meta', $tag );
$this->assertStringContainsString( 'generator', $tag );
$this->assertStringContainsString( 'speculation-rules ' . SPECULATION_RULES_VERSION, $tag );
}
}
12 changes: 12 additions & 0 deletions tests/plugins/webp-uploads/load-tests.php
Expand Up @@ -984,6 +984,18 @@ public function it_should_return_correct_quality_for_mime_types() {
$this->assertSame( 80, webp_uploads_modify_webp_quality( 80, 'image/jpeg' ), 'JPEG image quality should return default quality provided from WP filter wp_editor_set_quality.' );
}

/**
* Test printing the meta generator tag.
*
* @covers ::webp_uploads_render_generator
*/
public function test_webp_uploads_render_generator() {
$tag = get_echo( 'webp_uploads_render_generator' );
$this->assertStringStartsWith( '<meta', $tag );
$this->assertStringContainsString( 'generator', $tag );
$this->assertStringContainsString( 'webp-uploads ' . WEBP_UPLOADS_VERSION, $tag );
}

/**
* Runs (empty) hooks to satisfy webp_uploads_in_frontend_body() conditions.
*/
Expand Down