Viewing 15 replies - 1 through 15 (of 19 total)
  • Thread Starter docbt

    (@docbt)

    The plugin is working. WebP images were created for all my image folders except ultimatemember and wpdiscuz.

    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    Hi @docbt,

    Thank you for your message.

    Ultimate Member and wpDiscuz plugins are not compatible with this plugin. Therefore, it is not possible to convert images from these folders.

    You have to understand that this type of plugins are hundreds, if not thousands – I am not able to do the integration of each of them.

    @mateuszgbiorczyk But maybe there is the way to add custom folder to conversion?
    For example in WebP Express plugin user has choice what folder to pick: uploads, theme folder or entire site.

    Or maybe you could provide some custom code solution?

    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    Unfortunately, this is not possible at the moment. I will work on it and in the future I think that support for custom folders will be possible.

    Thread Starter docbt

    (@docbt)

    I wrote a little custom function to generate the webp files manually for custom folders:

    add_action( 'admin_init', 'manual_webpc_convert_paths' );
    function manual_webpc_convert_paths() {  
        $testmode = false;
        $uploadpath = ABSPATH . "wp-content/uploads/";
    	// Custom folders in uploads
    	$custom_folders = array(
    		'ultimatemember/',
    		'wpdiscuz/'
        );  
        foreach ($custom_folders as $key => $custom_folder) {
            $paths = array();          
            $path = $uploadpath . $custom_folder;
            // Known linux problem with "." ".." in scandir()
            $folders = array_diff(scandir($path), array('..', '.'));
            foreach ($folders as $key => $folder) {
                if(is_file($folder)){
                    $paths[] = $path . $folder;
                } else {
                    // Known linux problem with "." ".." in scandir()
                    $subfolders[$folder] = array_diff(scandir($path . $folder), array('..', '.'));
                }
            }
            foreach ($subfolders as $folder => $file) {
                foreach ($file as $key => $filename) {
                    if(is_file($path . $folder . "/" . $filename)){
                        $paths[] = $path . $folder . "/" . $filename;
                    } else {
                        // Known linux problem with "." ".." in scandir()
                        $subsubfolders[$folder . "/" . $filename] = array_diff(scandir($path . $folder . "/" . $filename), array('..', '.'));
                    }
                }
            }
            foreach ($subsubfolders as $folder => $file) {
                foreach ($file as $key => $filename) {
                    if(is_file($path . $folder . "/" . $filename)){
                        $paths[] = $path . $folder . "/" . $filename;
                    }
                }
            }                
            if($testmode){
                //debug output in admin dashboard
                echo '<pre>' . print_r($paths) . '</pre>';             
            } else {
                // image checks are done in webpc 
                do_action('webpc_convert_paths', $paths);
            }
            unset($paths);      
            unset($subfolders);
            unset($subsubfolders);
        }
    }

    Goes to your theme -> functions.php

    You can check the files first with $testmode = true in the first line. This will print the files in your admin dashboard instead of generating anything.

    Add your custom folders in this section:

    	$custom_folders = array(
    		'ultimatemember/',
    		'wpdiscuz/'
        );  
    • This reply was modified 4 years, 5 months ago by docbt.
    • This reply was modified 4 years, 5 months ago by docbt. Reason: forgot the first line
    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    Thank you so much for your commitment. Preparation of such a simple version is relatively easy, but to publish it for everyone I need to do much more elements, such as proper debugging and documentation.

    However, if this solution works for you, then go ahead and use it.

    @docbt Thanks man! I’ll test it later on.
    @mateuszgbiorczyk Of course you’re right, it is ad-hoc solution, but it will do for me ?? Tahnks!

    Thread Starter docbt

    (@docbt)

    EDIT:
    I forgot the first line ??

    It works perfect for me.

    Right know it runs everytime you open the admin dashboard. Would be better to run it only when the convert button is pressed.

    Is there an existing hook?

    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    I have prepared a version 1.2.7, which is a preparation for handling images from the entire /wp-content directory.

    To make the redirects for all images work, add the following rules to the /wp-content/.htaccess file:

    # BEGIN WebP Converter
    # ! --- DO NOT EDIT PREVIOUS LINE --- !
    <IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteCond %{HTTP_ACCEPT} image/webp
      RewriteCond %{DOCUMENT_ROOT}/wp-content/uploads-webpc/$1.jpg.webp -f
      RewriteRule (.+)\.jpg$ /wp-content/uploads-webpc/$1.jpg.webp [NC,T=image/webp,E=cache-control:private,L]
      RewriteCond %{HTTP_ACCEPT} image/webp
      RewriteCond %{DOCUMENT_ROOT}/wp-content/uploads-webpc/$1.jpeg.webp -f
      RewriteRule (.+)\.jpeg$ /wp-content/uploads-webpc/$1.jpeg.webp [NC,T=image/webp,E=cache-control:private,L]
      RewriteCond %{HTTP_ACCEPT} image/webp
      RewriteCond %{DOCUMENT_ROOT}/wp-content/uploads-webpc/$1.png.webp -f
      RewriteRule (.+)\.png$ /wp-content/uploads-webpc/$1.png.webp [NC,T=image/webp,E=cache-control:private,L]
    </IfModule>
    # ! --- DO NOT EDIT NEXT LINE --- !
    # END WebP Converter

    And then the rule is as follows:

    • when the original image has the path:
      /wp-content/uploads/2020/06/image.png
      then its equivalent in WebP will have:
      /wp-content/uploads-webpc/uploads/2020/06/image.png.webp
    • when the original image has the path:
      /wp-content/uploads/ultimatemember/image.png
      then its equivalent in WebP will have:
      /wp-content/uploads-webpc/uploads/ultimatemember/image.png.webp
    • when the original image has the path:
      /wp-content/themes/my-theme/public/img/image.png
      then its equivalent in WebP will have:
      /wp-content/uploads-webpc/themes/my-theme/public/img/image.png.webp

    This update is preparation because I want to split the changes into several stages so that everything goes without problems. For now, only images from the media library are still supported, but the logic will be as described.

    @docbt, @wellmadeonline, please tell me what you think about it.

    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    @docbt, @wellmadeonline I have also prepared for you the test version v1.2.8 that gives the functionality you need:
    https://gbiorczyk.pl/webp-converter-for-media-v1.2.8.zip

    It allows you to convert the entire /uploads directory and the /plugins and /themes directories. All you have to do is enter the CMS, save the settings and regenerate all the images again. Can I ask you for thorough tests and feedback?

    I will be very grateful for all suggestions.

    @mateuszgbiorczyk Thank you, I’m impressed how quick you did it ??
    Not sure when I be able to test your new plugin but I’ll try to do it this Saturday or beginning of next week.
    Thanks!

    @mateuszgbiorczyk I finally tested your new plugin and… it’s working almost prefect ??
    I was able to convert images in my theme folder but not all of them for some reason. Some small PNG images stayed untouched. You can take a look here: https://silverhand.eu/

    I think it might be due to option “Automatic removal of WebP files larger than original” but I ran “Regenerate All” with “Automatic removal of WebP files larger than original” unchecked and it had no effect.

    Another thing is when I run “Regenerate All” the plugin did regenerate all images but removed old ones and created brand new set of images. The option “Force convert all images again” was unchecked.

    Not sure if this happened because I did something wrong?

    But this is no big deal, new plugin did the job, thank you very much ??

    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    From what I see, there is a problem loading the logo.png file. It probably results from the fact that this file is loaded by JS, by the WP Rocket plugin.

    The second thing is probably you mean that the files have been moved from the directory /wp-content/uploads-webpc to the directory /wp-content/uploads-webpc/uploads? This is a conscious change since version 1.2.7. This transfer occurs only once during a plugin update. Please try to regenerate all the images again and let me know if the problem occurs.

    Hi, yes, you’re right files have been moved from the directory /wp-content/uploads-webpc to the directory /wp-content/uploads-webpc/uploads, that was what I meant. Like I wrote before – not a big deal, but I think on some budget hosts if someone have tons of images it can be a little inconvenience.

    I did regenerate all images again and – as expected – there was 0 regenerated files this time.
    Thanks again!

    PS
    I really like your plugin, I use it at almost every website I work on, it just simple, works flawless and does exactly what it meant to do. Good job!

    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    This change was necessary to support other directories than /uploads. Thank you very much for your kind words and I am very happy.

    Do you still have any ideas that I could implement?

Viewing 15 replies - 1 through 15 (of 19 total)
  • The topic ‘Add custom folders’ is closed to new replies.