• Resolved anobjectn

    (@anobjectn)


    The plugin is working well for me except for exclusion options I used are now broken.

    I have animated pngs that I keep from being replaced because the replacement versions are not animated (animated text beginning with “We Are”).

    I was using a filter on webpc_attachment_paths with a naming convention, but this stopped working with the latest plugin update. After reviewing your FAQs I implemented a solution with enumerated file names.

    Both solutions just do not work to exclude specific images from being replaced – in my <picture/> element – and this used to work.

    Here are my functions for exclusion:

    add_filter('webpc_attachment_paths', function($paths) {
        $suffix = '-nowebp';
        foreach ($paths as $index => $path) {
          if (!preg_match('/(.*?)' . $suffix . '((-(.*))?)\.(jpe?g|png|gif)/', basename($path))) continue;
          unset($paths[$index]);
        }
        return $paths;
    });
    
    add_filter( 'webpc_supported_source_file', function( bool $status, string $file_name, string $server_path ): bool {
        $excluded_files = [ 
            'Overit-Website_Text_Animation-APNG_opt-tinypng-nowebp.png',
            'Overit-Website_Text_Animation-APNG_420px_opt-tinypng-nowebp.png',
        ];
        if ( ! $status || in_array( $file_name, $excluded_files ) ) {
            return false;
        }
    
        return $status;
    }, 10, 3 );

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    Hello @anobjectn,

    Thanks for your message.

    Please use the following filter:

    add_filter( 'webpc_supported_source_file', function( bool $status, string $file_name, string $server_path ): bool {
    	if ( ! $status || ( strpos( $file_name, '-nowebp.' ) !== false ) ) {
    		return false;
    	}
    
    	return $status;
    }, 10, 3 );

    Remember that if an image has already been converted, excluding it will not work. This file should be removed from the /wp-content/uploads-webpc/ directory.

    Best,
    Mateusz

    Thread Starter anobjectn

    (@anobjectn)

    Thank you for the update. Unfortunately, webp were created. Will the Regenerate All plugin feature delete the existing uploads-webpc contents? If not, I wish it could be an option. I don’t have a way to quickly remove files manually – no ssh.

    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    @anobjectn Unfortunately, this is not possible. Try disabling the plugin and uninstalling it. Then all WebP files will be deleted.

    Next install the plugin again and convert all images.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Exclusion tactics not working on’ is closed to new replies.