/> getImageAlphaChannel(); if ($hasTransparency) { return $file; } $image->setImageFormat('webp'); $image->setImageCompressionQuality($compression_quality); $image->stripImage(); $image->writeImage($webp_file_path); $image->clear(); $image->destroy(); } catch (Exception $e) { return $file; } $backup_dir = $wp_upload_dir['path'] . '/backup'; if (!file_exists($backup_dir)) { mkdir($backup_dir, 0755, true); } $backup_file_path = $backup_dir . '/' . basename($original_file_path); rename($original_file_path, $backup_file_path); $metadata = wp_generate_attachment_metadata(attachment_url_to_postid($file['url']), $webp_file_path); wp_update_attachment_metadata(attachment_url_to_postid($file['url']), $metadata); return [ 'file' => $webp_file_path, 'url' => $wp_upload_dir['url'] . '/' . basename($webp_file_path), 'type' => 'image/webp', ]; } add_filter('wp_handle_upload', 'convert_images_to_webp'); // function rl_before_update( $upgrader_object, $options ) { // log_to_file("rl_before_update - Options: ", $options); // } // function rl_after_update( $upgrader_object, $options ) { // log_to_file("rl_after_update - Options: ", $options); // } // add_action( 'upgrader_pre_install', 'rl_before_update', 10, 2 ); // add_action( 'upgrader_process_complete', 'rl_after_update', 10, 2 );