Hello @luigitec,
Thanks for your message.
Can you explain more precisely what you would like to achieve?
Best,
Mateusz
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 4 years, 8 months ago by
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
}
@luigitec Yes, but you don’t need to return a value for an action. You only do return for filters.
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 =)
@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.
Thanks!! I appreciate your help @mateuszgbiorczyk I’ll mark the thread as resolved.