WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

After following the guide for How can I prevent uploading bmp image? to remove bmp (and in my case tiff images) from being uploaded, I tested and it is working, but noticed users are now getting the error message:

Sorry, this file type is not permitted for security reasons.


That looks to be in the wp-admin/includes/file.php folder:

if ( ( !$type || !$ext ) && !current_user_can( 'unfiltered_upload' ) )
        return $upload_error_handler( $file, __( 'Sorry, this file type is not permitted for security reasons.' ));

and also further down:

if ( ( !$type || !$ext ) && !current_user_can( 'unfiltered_upload' ) )
        return call_user_func($upload_error_handler, $file, __( 'Sorry, this file type is not permitted for security reasons.' ));

How can I hook into this so that I can change the message to something a little more friendly?

share|improve this question
up vote 0 down vote accepted

This is untested, but I think you can just define wp_handle_upload_error in your functions.php file and return custom error messages. If you look at where that function is defined in that file,

if ( ! function_exists( 'wp_handle_upload_error' ) ) {
    function wp_handle_upload_error( &$file, $message ) {
        return array( 'error'=>$message );

You can see it first does a test to see if the function is defined, so it would be safe to create another one (of course, in your own code, also check to see if its defined just to be safe). You'll have some experimenting to do, but hopefully this puts you on the right path!


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.