Skip to content
Merged
Show file tree
Hide file tree
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 Dec 2, 2021
087fb18
Fixes for phpcs
adamsilverstein Dec 2, 2021
1d613b8
separate file doc header to please phpcs
adamsilverstein Dec 2, 2021
6c434c1
Move functionality to load.php
adamsilverstein Dec 3, 2021
9429e06
Revert temporary changes to root load.php
adamsilverstein Dec 3, 2021
f0e8fec
update description
adamsilverstein Dec 3, 2021
4c17af6
Merge branch 'trunk' into add/webp-default-module
adamsilverstein Dec 3, 2021
ad35694
Add test validating filter added as expected
adamsilverstein Dec 3, 2021
336da5e
Formatting for phpcs
adamsilverstein Dec 3, 2021
fe536d2
move cap check into folter callback.
adamsilverstein Dec 3, 2021
2620b57
Cleanup
adamsilverstein Dec 3, 2021
aa753c0
Add tests that mock WebP support enabled/disabled
adamsilverstein Dec 3, 2021
f2cc640
Remove `.` after name
adamsilverstein Dec 3, 2021
4b60267
move testdata into module folder
adamsilverstein Dec 3, 2021
da4a30c
Simplify WebP Uploads module header to only contain module name once …
Dec 6, 2021
5133658
Merge branch 'trunk' into add/webp-default-module
Dec 6, 2021
8ad877e
Update tests/modules/webp-uploads/webp-uploads-test.php
adamsilverstein Dec 7, 2021
b1e0a67
Update tests/modules/webp-uploads/webp-uploads-test.php
adamsilverstein Dec 7, 2021
45ad216
Update tests/modules/webp-uploads/webp-uploads-test.php
adamsilverstein Dec 7, 2021
331e540
Update tests/modules/webp-uploads/webp-uploads-test.php
adamsilverstein Dec 7, 2021
f8c9e2f
remove unnecessary filter cleanup
adamsilverstein Dec 7, 2021
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
Next Next commit
Add a webp-default module, first pass
  • Loading branch information
adamsilverstein committed Dec 2, 2021
commit 2cdbd5290358c2c8d7079df2a362cdf882f67cc0
6 changes: 5 additions & 1 deletion load.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ function perflab_sanitize_modules_setting( $value ) {
* @return array Associative array of module settings keyed by module slug.
*/
function perflab_get_module_settings() {
return (array) get_option( PERFLAB_MODULES_SETTING, array() );
return (array) get_option( PERFLAB_MODULES_SETTING, array(
'webp-default' => array(
'enabled' => true,
)
) );
}
Comment thread
adamsilverstein marked this conversation as resolved.

/**
Expand Down
53 changes: 53 additions & 0 deletions modules/webp-default/class-webp-default.php
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 {
Comment thread
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;
}
}
15 changes: 15 additions & 0 deletions modules/webp-default/load.php
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();