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

Add generator meta tag for Embed Optimizer #1057

Merged
merged 3 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
16 changes: 16 additions & 0 deletions plugins/embed-optimizer/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,19 @@ function embed_optimizer_trigger_error( string $function_name, string $message,
}
wp_trigger_error( $function_name, $message, $error_level );
}

/**
* Displays the HTML generator tag for the WebP Uploads plugin.
westonruter marked this conversation as resolved.
Show resolved Hide resolved
*
* See {@see 'wp_head'}.
*
* @since 0.1.0
*/
function embed_optimizer_render_generator() {
if (
defined( 'EMBED_OPTIMIZER_VERSION' )
) {
Comment on lines +165 to +167
Copy link
Member Author

Choose a reason for hiding this comment

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

This condition seems pointless if we always define the constant. But it is present in the other plugins.

Copy link
Member

Choose a reason for hiding this comment

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

🤷🏼 very defensive coding

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe we should also check if esc_attr() exists and wrap it in a try/catch block then 😄

echo '<meta name="generator" content="Embed Optimizer ' . esc_attr( EMBED_OPTIMIZER_VERSION ) . '">' . "\n";
}
}
add_action( 'wp_head', 'embed_optimizer_render_generator' );
13 changes: 13 additions & 0 deletions tests/plugins/embed-optimizer/embed-optimizer-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,17 @@ function ( array $attrs, string $javascript ) {
$this->assertStringStartsWith( '<script type="module" nonce="abc123">', $script );
$this->assertStringEndsWith( '</script>', $script );
}

/**
* Test printing the meta generator tag.
*
* @covers ::embed_optimizer_render_generator
*/
public function test_embed_optimizer_render_generator() {
Copy link
Member

Choose a reason for hiding this comment

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

Nice, very thorough!

$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 );
}
}