@giuliopanda I am the author of the WebP Converter for Media plugin. I analyzed what the problem is and I will describe my conclusions below.
In the file:
/includes/class-bulk-image-resizer-loader.php
You have the following code:
add_filter( 'wp_generate_attachment_metadata', [ $this, 'wp_generate_attachment_metadata' ], 10, 2 );
public function wp_generate_attachment_metadata( $attachment, $id ) {
if ( Opfn\op_get_resize_options( 'on_upload', 0 ) == 1 ) {
Opfn\op_optimize_single_img( $id );
$attachment = wp_get_attachment_metadata( $id, true );
}
return $attachment;
}
You are using the wp_generate_attachment_metadata filter there. You return false there when the PDF is uploaded. WordPress documentation says the returned value should be array. If wp_get_attachment_metadata
returns false, it means there was an error. Unfortunately, you do not support such an exception in your code.
I have the following code in my plugin:
add_filter( 'wp_update_attachment_metadata', [ $this, 'init_attachment_convert' ], 10, 2 );
public function init_attachment_convert( array $data = null, int $attachment_id = null ) {
@markussss receives the following error:
PHP Fatal error: Uncaught TypeError: Argument 1 passed to WebpConverter\Conversion\Media\Upload::init_attachment_convert() must be of the type array or null, bool given...
I use the wp_update_attachment_metadata filter as it is described in the documentation. The error occurs because your code is misusing a filter that was previously present in your WordPress code.
Correct your code like this and everything will work fine:
add_filter( 'wp_generate_attachment_metadata', [ $this, 'wp_generate_attachment_metadata' ], 10, 2 );
public function wp_generate_attachment_metadata( $attachment, $id ) {
if ( Opfn\op_get_resize_options( 'on_upload', 0 ) == 1 ) {
Opfn\op_optimize_single_img( $id );
$new_attachment = wp_get_attachment_metadata( $id, true );
if ( is_array( $new_attachment ) ) {
return $new_attachment;
}
}
return $attachment;
}
Additionally, I found one more bug (unrelated to this issue). In the file:
/bulk-image-resizer.php
You have the following code:
register_uninstall_hook(__FILE__, [$bulk_image_resizer_loader, 'uninstall']);
According to the WordPress documentation, when using register_uninstall_hook function you should pass a static method or function as the second parameter. This causes errors in the debug.log file:
PHP Notice: register_uninstall_hook was called <strong>incorrectly</strong>. Only a static class method or function can be used in an uninstall hook.
Best,
Mateusz