[wp-hackers] Re: Reject uploaded image

scribu scribu at gmail.com
Mon Jan 26 15:08:14 GMT 2009


On Mon, Jan 26, 2009 at 5:00 PM, scribu <scribu at gmail.com> wrote:

> I'm trying to do something like this:
>>
>> A user uploads an image. If the image resolution is lower than 640x480px
>> (for example), then an error message is sent to the user and the image is
>> deleted.
>>
>> I've tried using *add_action('media_upload_image', 'my_function')*, but
>> that doesn't help.
>>
>> Maybe using *add_filter('async_upload_image', 'my_function')* ?
>>
>> Any ideas?
>>
>
That was a little rushed. This is the final version:


    add_filter('wp_update_attachment_metadata', 'check_size', 10, 2);

    public function check_size($data, $id) {
        if ( $data['width'] < 800 && $data['height'] < 600 ) {
            wp_delete_attachment($id);
            die("<strong class='error'>Error: Image too small</strong>");
        } else
            return $data;
    }


-- 
http://scribu.net


More information about the wp-hackers mailing list