• Resolved luigitec

    (@luigitec)


    Hello guys,

    I love the plugin, I was taking a look at the source code and couldn’t find a suitable action/filter I could hook once the images are all converted under the uploads-webpc directory, something similar to the wp_update_attachment_metadata WordPress filter.

    Goal: I’m syncing the content of the uploads-webpc and the uploads directories to a different directory.

    Thanks in advance!

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

    (@mateuszgbiorczyk)

    Hello @luigitec,

    Thanks for your message.

    Can you explain more precisely what you would like to achieve?

    Best,
    Mateusz

    Thread Starter luigitec

    (@luigitec)

    Hello @mateuszgbiorczyk

    When I upload an image, I want to sync both the images under the uploads directory, and the ones on the uploads-webpc directory to a new location via rsync, so, I’m looking for a hook similar to wp_update_attachment_metadata (WordPress), by the time it reaches that filter, the image and its thumbnails are already under the directory, then the rsync can be executed.

    
    wp-content
    |_ uploads/path/to/images/
       |_original.jpg
       |_original-150x150.jpg
       |_original-300x300.jpg
    |_ uploads-webpc/uploads/path/to/images/
       |_original.jpg.webp
       |_original-150x150.jpg.webp
       |_original-300x300.jpg.webp
    

    By the time the images are created, I plan to execute the rsync command to copy those images into a single directory:

    
    |_ different/location/uploads
       |_original.jpg
       |_original.jpg.webp
       |_original-150x150.jpg
       |_original-150x150.jpg.webp
       |_original-300x300.jpg
       |_original-300x300.jpg.webp
    

    Current problem is, I’m just able to sync the images under the core uploads directory. So, I’m trying to find out if there’s a filter/action I could hook on this plugin to execute the rsync.

    • This reply was modified 3 years, 3 months ago by luigitec.
    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    @luigitec See here:
    https://plugins.svn.www.ads-software.com/webp-converter-for-media/trunk/src/Conversion/Method/MethodAbstract.php

    More specifically to the line:
    do_action( 'webpc_convert_after', $output_path, $source_path );

    Thread Starter luigitec

    (@luigitec)

    I tried using that one, but for some reason it didn’t work as I expected, did I use it correctly?

    
    add_action('webpc_convert_after', 'myUploadFunction', 10, 2) 
    
    function myUploadFunction($output_path, $source_path)
    {
        rsyncCommand();
        return $output_path
    }
    
    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    @luigitec Yes, but you don’t need to return a value for an action. You only do return for filters.

    Thread Starter luigitec

    (@luigitec)

    Awesome, it did the trick, and just a WordPress question, if the do_action requires 2 parameters ($output_path and $source_path), can I skip those on the function?

    do_action( 'webpc_convert_after', $output_path, $source_path );

    
    add_action('webpc_convert_after', 'myUploadFunction', 10) 
    function myUploadFunction()
    {
        rsyncCommand();
    }
    

    This question is because if I’m not using the parameters, the IDE complains about it.

    Thanks a bunch for the help, 5 stars rating =)

    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    @luigitec In the case of filters and actions you do not need to use all the arguments.

    In the function you can add only firstparameter, and in the line adding the filter replace the last argument from 2 with 1, or remove it entirely.

    Thread Starter luigitec

    (@luigitec)

    Thanks!! I appreciate your help @mateuszgbiorczyk I’ll mark the thread as resolved.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘hook after images are converted’ is closed to new replies.