• Resolved markussss

    (@markussss)


    Hi,

    I tried to use your plugin with WebP Converter for Media simultaneously, which throws an error.

    WebP Converter for Media
    https://www.ads-software.com/plugins/webp-converter-for-media/

    It’s the same error as someone else described here already
    https://www.ads-software.com/support/topic/webp-and-svg-file/

    Error: Unexpected response from the server. The file may have been uploaded successfully. Check in the Media Library or reload the page.

    I set up your plugin to resize images when uploading to the media library. I tested to upload images and PDFs. It also throws the error on PDF, however, the actual files are getting uploaded.

    Not sure on which end this should be fixed. If I disable the automatic resizing on upload the error does not get thrown.

    Hope that’s something that can be fixed as it makes sense to combine resizing + optimization + converting to WebP.

    best regards
    Markus

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author giuliopanda

    (@giuliopanda)

    I will try to solve the problem as soon as possible. But in my opinion the problem is that both WebP Converter and my plugin try to convert images when you are loading them. You can try disabling scaling on my plug-in when images are loaded or disable the plug-in when you’re not using it.

    Thread Starter markussss

    (@markussss)

    That’s probably right and you probably knwow that better than I am, but it sounds like that could be an explanation.

    One tool tries to resize
    The other tool tries to optimize and convert to webP

    Both should happen on upload – and I think there is no order / priority

    On the other hand it’s a use case that probably will be desired by many.
    resize + optimize + webp convert

    Hope there will be a solution as your plugin works quite well so far ??

    @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

    Thread Starter markussss

    (@markussss)

    I am incredibly, incredibly impressed … that’s what I love so much about the WordPress community around the world ??

    Plugin Author giuliopanda

    (@giuliopanda)

    I have posted a new version with corrections.
    @mateuszgbiorczyk thank you very much I fixed the plugin following your suggestions, now loading a pdf does not give more errors. Further on the more in-depth tests to check if there are other errors.
    @markussss thanks to you too for reporting the problem, from here I discovered that I had been rough in writing some functions. I hope it all works out now.

    Thread Starter markussss

    (@markussss)

    Hi,

    thanks to both of you – I just wanted to share what I see after I updated. Did not change anything else, only updated to the latest version.

    I currently want to avoid to mess around with php.ini – especially as this error is new and appeared without changing anything on the server settings

    Attention it is not possible to start the instance of WP_Image_Editor. This plugin cannot work until the problem is fixed. Even if you don’t want to use this plugin, this kind of error can create problems.
    Often to solve this problem just activate one of the two graphic modules from php.ini imagick or GD.
    To do this you can try to go to php.ini and delete the; from the line; extension = gd.
    Once done, save the file and restart the server.

    best regards
    Markus

    Plugin Author giuliopanda

    (@giuliopanda)

    Hi, I actually added this new control. The idea was to warn if I found something wrong with the configuration (for images only).
    But maybe I exaggerated by saying that nothing works and what needs to be done to correct.

    Thanks for the feedback and patience, as soon as (today or tomorrow I hope) I make the message less dramatic and avoid blocking the plugin.

    Thread Starter markussss

    (@markussss)

    Yes, when I read it, it felt to me that it’s better to disable the plugin for now as I was not able to invest enough time to investigate (especially as nothing changed on my end).

    The plugin did work already perfectly fine (except for the “conflict” when the mentioned WebP Plugin was installed and I got that error when uploading PDF).

    Looking forward to see if it works again without changes on my end.

    @giuliopanda I have a request for you. Could you please remove the phrases “(Thanks to Mateusz Gbiorczyk)” from the README?

    I appreciate it, but please remove it nonetheless. I will be very grateful!

    Plugin Author giuliopanda

    (@giuliopanda)

    Done

    @giuliopanda Thanks!

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Compatibility issue with WebP Converter’ is closed to new replies.