Repository navigation
Add WebP for uploads module #32
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
2cdbd52
Add a webp-default module, first pass
adamsilverstein 087fb18
Fixes for phpcs
adamsilverstein 1d613b8
separate file doc header to please phpcs
adamsilverstein 6c434c1
Move functionality to load.php
adamsilverstein 9429e06
Revert temporary changes to root load.php
adamsilverstein f0e8fec
update description
adamsilverstein 4c17af6
Merge branch 'trunk' into add/webp-default-module
adamsilverstein ad35694
Add test validating filter added as expected
adamsilverstein 336da5e
Formatting for phpcs
adamsilverstein fe536d2
move cap check into folter callback.
adamsilverstein 2620b57
Cleanup
adamsilverstein aa753c0
Add tests that mock WebP support enabled/disabled
adamsilverstein f2cc640
Remove `.` after name
adamsilverstein 4b60267
move testdata into module folder
adamsilverstein da4a30c
Simplify WebP Uploads module header to only contain module name once …
5133658
Merge branch 'trunk' into add/webp-default-module
8ad877e
Update tests/modules/webp-uploads/webp-uploads-test.php
adamsilverstein b1e0a67
Update tests/modules/webp-uploads/webp-uploads-test.php
adamsilverstein 45ad216
Update tests/modules/webp-uploads/webp-uploads-test.php
adamsilverstein 331e540
Update tests/modules/webp-uploads/webp-uploads-test.php
adamsilverstein f8c9e2f
remove unnecessary filter cleanup
adamsilverstein File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
Add a webp-default module, first pass
- Loading branch information
commit 2cdbd5290358c2c8d7079df2a362cdf882f67cc0
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| <?php | ||
| /** | ||
| * WebP-Default Module | ||
| * | ||
| * @package performance-lab | ||
| * @since 1.0.0 | ||
| */ | ||
|
|
||
| /** | ||
| * WebP-Default Module | ||
| * | ||
| * Switches the default sub sized output format for images to WebP when supported. | ||
| * | ||
| * @since 1.0.0 | ||
| */ | ||
| class WebP_Default { | ||
|
adamsilverstein marked this conversation as resolved.
Outdated
|
||
|
|
||
| /** | ||
| * Constructor | ||
| * | ||
| * @since 1.0.0 | ||
| */ | ||
| function __construct() { | ||
|
|
||
| // Only enable if the server supports WebP. | ||
| if ( ! wp_image_editor_supports( array( 'mime_type' => 'image/webp' ) ) ) { | ||
| return; | ||
| } | ||
| add_filter( 'image_editor_output_format', array( $this, 'webp_default_filter_image_editor_output_format' ), 10, 3 ); | ||
| } | ||
|
|
||
| /** | ||
| * Filter the image editor default output format mapping. | ||
| * | ||
| * For uploaded JPEG images, map the default output format to WebP. | ||
| * | ||
| * @since 1.0.0 | ||
| * | ||
| * @param string $format The image editor default output format mapping. | ||
| * @return string The new output format mapping. | ||
| */ | ||
| public function webp_default_filter_image_editor_output_format( $output_format, $filename, $mime_type ) { | ||
|
|
||
| // WebP lossless support is still limited on servers, so only apply to JPEGs. | ||
| if ( 'image/jpeg' !== $mime_type) { | ||
| return $output_format; | ||
| } | ||
|
|
||
| $output_format['image/jpeg'] = 'image/webp'; | ||
|
|
||
| return $output_format; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| <?php | ||
| /** | ||
| * Module Name: WebP default. | ||
| * Description: Use WebP as the default sub sized image format. | ||
| * This module changes the default format WordPress uses for | ||
| * generating sub sized images from JPEG to WebP. Requires that the | ||
| * server supports WebP and only acts on JPEG image uploads. | ||
| * Focus: images | ||
| * Experimental: No | ||
| * | ||
| * @package performance-lab | ||
| */ | ||
| require_once( plugin_dir_path( __FILE__ ) . 'class-webp-default.php' ); | ||
|
|
||
| new WebP_Default(); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.