Last active
July 27, 2024 14:59
-
-
Save wpmudev-sls/030e21db247a47c6d3b61d0d09dee8c1 to your computer and use it in GitHub Desktop.
[Smush Pro] - Convert beaver builder's cropped images to webp
This file contains 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
<?php | |
/** | |
* Plugin Name: Fix local WebP conflict with Beaver Builder | |
* Description: Fix local WebP conflict with Beaver Builder. | |
* Jira: SLS-6298 | |
* Author: Prashant @ WPMUDEV | |
* Author URI: https://wpmudev.com | |
* License: GPLv2 or later | |
* | |
* @package WebP_Beaver_Crop_Fix | |
*/ | |
if ( ! defined( 'ABSPATH' ) ) { | |
exit; // Exit if accessed directly. | |
} | |
/** | |
* Fix Smush WebP beaver crop image issue. | |
* | |
* @param array $file_path Cropped image path. | |
*/ | |
function smush_beaver_image_to_webp_after_crop( $file_path ) { | |
// Check if the cropped image path is present. | |
if ( empty( $file_path['path'] ) ) { | |
return; | |
} | |
// Check if the file exists. | |
if ( ! file_exists( $file_path['path'] ) ) { | |
return; | |
} | |
// Convert the image to WebP. | |
$webp_response = WP_Smush::get_instance()->core()->mod->smush->do_smushit( $file_path['path'], true ); | |
if ( empty( $webp_response ) || is_wp_error( $webp_response ) ) { | |
return; | |
} | |
} | |
// Hook into the 'fl_builder_photo_cropped' action. | |
add_action( 'fl_builder_photo_cropped', 'smush_beaver_image_to_webp_after_crop', 10, 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment