• Resolved streamworksaudio

    (@streamworksaudio)


    I am doing some testing on an image upload script via AJAX I am working on and part of that script is to edit the image (size) with wp_get_image_editor.

    I wanted to test to see what would happen if somehow somebody uploaded a file that is not an image file. When it gets to the point where trying to initiate the editor (with a .txt file), the result from the AJAX call is always 500. It seems that if a non image file is sent to the wp_get_image_editor function, it craps out with an uncaught error.

    I think what would be good idea is to return an WP_Error if the file is not an image.

    I know wp_get_image_editor calls wp_check_filetype, so for a test I ran the uploaded file through the wp_check_filetype on its own, and it returned a MIME type plain/text for the .txt file.

    Is there some way to get wp_get_image_editor to return an error if a non image file is sent as the path argument?

    Cheers

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    The function does return a WP_Error object when the file’s MIME is inappropriate. The issue seems to be in the server side Ajax handler choking on it and causing a 500 instead of outputting something your Ajax caller can handle.

    Thread Starter streamworksaudio

    (@streamworksaudio)

    You are correct, a WP_Error is returned by the function.

    I do see where I went wrong (it is amazing what a few hours of sleep can do). I had my WP_Error check coming too late in the script and the uncaught errors were from trying to run methods on the editor before checking if wp_get_image_editor returned an error or not.

    Once I put the check for an error right after attempting to create an instance of the editor I was able to catch the error before running methods on it.

    Cheers

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘wp_get_image_editor uncaught error when file is not an image’ is closed to new replies.