I’m new in wordpress plugin development and I’m trying to hook my function to one of wordpress’s upload / attachements functions.
My target is to:
– hook to wordpress function (I’ve tried: wp_handle_upload, wp_handle_upload_prefilter)
– use image/media resource in my function (apply filter on image)
– return modified resource to further processing by wordpress core.
Is there a way to achieve that?
The code I’m using is similar to:
add_filter('wp_handle_upload', 'handle_upload');
function handle_upload($resource){
$tools->tool_blurImage($resource);
return $resource;
}
Thanks in advance!
The
$resource
passed to the function is an array of 3 elements:file
is the absolute path to the image file;url
is the url to the image;type
is the mime type of the file (i.e.image/jpeg
).So if your
$tools->tool_blurImage
function accept the file path as parameter you should check if the file is an image and then pass the file path: