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

Enable end user opt-in to generate all sizes in fallback format #1689

Open
wants to merge 8 commits into
base: trunk
Choose a base branch
from

Conversation

b1ink0
Copy link
Contributor

@b1ink0 b1ink0 commented Nov 21, 2024

Summary

Fixes #1513

Relevant technical choices

This PR adds a checkbox users can check right below the "generate fallback images" checkbox (and it would only be enabled when "generate fallback images" checkbox is checked).

When users enable this feature it is notate in the Generator tag so we can later discover how many sites opt into generating all image sizes.

Settings Page Screenshots

Screenshot 2024-11-21 at 6 14 24 PM
Screenshot 2024-11-21 at 6 14 53 PM

Sample outputs for the below custom sizes

add_image_size( 'custom_size_1', 400, 400, true );
add_image_size( 'custom_size_2', 800, 800, true );
add_image_size( 'custom_size_3', 1200, 1200, true );
  • When the new option is off
    Screenshot 2024-11-21 at 6 19 03 PM

  • When the new option is on

Screenshot 2024-11-21 at 6 20 51 PM

@b1ink0 b1ink0 marked this pull request as ready for review November 21, 2024 13:01
Copy link

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: b1ink0 <[email protected]>
Co-authored-by: felixarntz <[email protected]>
Co-authored-by: adamsilverstein <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

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

@b1ink0 A bit of feedback here, but overall this looks great!

*
* @return bool True if the option is enabled, false otherwise.
*/
function webp_uploads_is_fallback_all_sizes_enabled(): bool {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe a better name would be something like webp_uploads_should_generate_all_fallback_sizes()?

Comment on lines 722 to 728
$allowed_sizes[ $size ] = ! empty( $size_details['provide_additional_mime_types'] );
if ( isset( $size_details['provide_additional_mime_types'] ) ) {
// Give priority to the 'provide_additional_mime_types' property.
$allowed_sizes[ $size ] = (bool) $size_details['provide_additional_mime_types'];
} else {
// If 'provide_additional_mime_types' is not set, use the fallback all sizes setting.
$allowed_sizes[ $size ] = webp_uploads_is_fallback_all_sizes_enabled();
}
Copy link
Member

Choose a reason for hiding this comment

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

Rather than doing this here, I think a more elegant solution would be to decouple the UI control and option from the main logic, by using the webp_uploads_image_sizes_with_additional_mime_type_support filter below. So I think this would be better separately implemented.

It would also allow the code to be a bit more efficient: We should only need to call webp_uploads_is_fallback_all_sizes_enabled() once, not for every size available. If false we can immediately return without changing anything. If true, we go through the array of sizes and set them to true.

I think it's okay not to check the provide_additional_mime_types value directly to see if it's false. It's primary purpose it to enable (not disable) this behavior anyway, and since the setting explicitly says "all", it's fine to do it for all sizes, regardless of what other configuration may be present.

Comment on lines 774 to 776
if ( webp_uploads_is_fallback_all_sizes_enabled() ) {
echo '<meta name="generator" content="webp-uploads-fallback-all-sizes ' . esc_attr( WEBP_UPLOADS_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.

Why is that being added? We shouldn't have an extra generator tag for this feature specifically. If we need feature-specific indicators in the frontend, let's discuss that in a separate issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the #1513 there is mention of the adding the generator tag thats why I added it.

Ideally when users enable this feature we should notate that in the Generator tag so we can later discover how many sites opt into generating all image sizes.

Should I remove the generator tag code from this PR?

Copy link
Member

@felixarntz felixarntz Nov 23, 2024

Choose a reason for hiding this comment

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

Yeah, I think so, let's not do it in this PR, as it needs further discussion.

Maybe worth opening an issue to discuss whether/how we want to make more specific features discoverable in the frontend? Such an issue could link to that comment as one example reference.

// Add a setting to generate fallback images in all sizes including custom sizes.
register_setting(
'media',
'perflab_generate_fallback_all_sizes',
Copy link
Member

Choose a reason for hiding this comment

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

Maybe rename this to perflab_generate_all_fallback_sizes, that reads a bit better.

*
* @since n.e.x.t
*/
function webp_uploads_generate_fallback_all_sizes_callback(): void {
Copy link
Member

Choose a reason for hiding this comment

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

See above in terms of naming.

// Add setting field for generating fallback images in all sizes including custom sizes.
add_settings_field(
'perflab_generate_fallback_all_sizes',
__( 'Output all fallback images', 'webp-uploads' ),
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
__( 'Output all fallback images', 'webp-uploads' ),
__( 'Generate all fallback image sizes', 'webp-uploads' ),

@felixarntz felixarntz added this to the webp-uploads n.e.x.t milestone Nov 21, 2024
@felixarntz felixarntz added [Type] Enhancement A suggestion for improvement of an existing feature [Plugin] Modern Image Formats Issues for the Modern Image Formats plugin (formerly WebP Uploads) labels Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Plugin] Modern Image Formats Issues for the Modern Image Formats plugin (formerly WebP Uploads) [Type] Enhancement A suggestion for improvement of an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable end user opt-in to generate all sizes in fallback format
2 participants