I would like to validate an uploaded image for a custom post type before upload

I would like to check an image before uploading it to the server.
I need to check if it has a minimum width and height, 300dpi and only jpg.

I’m using the next function to invoke the upload process, except it invokes on every upload not for a certain post type.

Read More
add_filter('wp_handle_upload_prefilter','tc_handle_upload_prefilter');

function mf_handle_upload_prefilter($file)
{
  // do checks and return error if fails

  return $file;
}

Does anyone know how to do this?
Can I maybe at an extra value to the $file parameter which I can use?
Or is there another way to do this?

ps. I has to be before the upload itself!

Related posts

Leave a Reply

1 comment

  1. The solution:

    add_filter('wp_handle_upload_prefilter','tc_handle_upload_prefilter');
    
    function mf_handle_upload_prefilter($file)
    {
      if(get_post_type($_REQUEST['post_id']) == 'post_type')
      {
         // do checks
      }
    
      return $file;
    }