Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions plugins/auto-sizes/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,16 @@ function auto_sizes_update_content_img_tag( $html ) {
return $html;
}
add_filter( 'wp_content_img_tag', 'auto_sizes_update_content_img_tag' );

/**
* Displays the HTML generator tag for the plugin.
*
* See {@see 'wp_head'}.
*
* @since 1.0.1
*/
function auto_sizes_render_generator() {
// Use the plugin slug as it is immutable.
echo '<meta name="generator" content="auto-sizes ' . esc_attr( IMAGE_AUTO_SIZES_VERSION ) . '">' . "\n";
}
add_action( 'wp_head', 'auto_sizes_render_generator' );
1 change: 1 addition & 0 deletions plugins/auto-sizes/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Contributions are always welcome! Learn more about how to get involved in the [C

= 1.0.1 =

* Add auto-sizes generator tag. ([1105](https://github.com/WordPress/performance/pull/1105))
* 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
18 changes: 18 additions & 0 deletions tests/plugins/auto-sizes/auto-sizes-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ public function get_image_tag( $attachment_id ) {
return get_image_tag( $attachment_id, '', '', '', 'large' );
}

public function test_hooks() {
$this->assertSame( 10, has_filter( 'wp_get_attachment_image_attributes', 'auto_sizes_update_image_attributes' ) );
$this->assertSame( 10, has_filter( 'wp_content_img_tag', 'auto_sizes_update_content_img_tag' ) );
$this->assertSame( 10, has_action( 'wp_head', 'auto_sizes_render_generator' ) );
}

/**
* Test generated markup for an image with lazy loading gets auto-sizes.
*
Expand Down Expand Up @@ -87,4 +93,16 @@ public function test_content_image_without_lazy_loading_does_not_have_auto_sizes
wp_filter_content_tags( $this->get_image_tag( self::$image_id ) )
);
}

/**
* Test printing the meta generator tag.
*
* @covers ::auto_sizes_render_generator
*/
public function test_auto_sizes_render_generator() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd be for adding an additional test to ensure this callback is properly hooked to the wp_head action, similar to this example.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fair point, we can add this here. Though then I'd say lets also assert the other hooks in the same test.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Added in 1a70161

$tag = get_echo( 'auto_sizes_render_generator' );
$this->assertStringStartsWith( '<meta', $tag );
$this->assertStringContainsString( 'generator', $tag );
$this->assertStringContainsString( 'auto-sizes ' . IMAGE_AUTO_SIZES_VERSION, $tag );
}
}