I would like to know, if it's possible to filter a file upload by name. In my case i want that the uploader let me upload the file only if the file name contains the string "example". Ex: "miimage-example.jpg". And deny if does not contains it Ex:"miimage.jpg".

Is there any way to do that? i don't know how Wordpress handless the functions so i'm completely lost.

I will appreciate any help you could provide me. Thanks in advance.


This is not the best solution, but it can be considered as a starting point

add_filter('sanitize_file_name', 'filter_function_name_11', 10, 2);

function filter_function_name_11($filename, $filename_raw) {  
    $pos = strripos($filename, 'example');
    if ($pos === false) {
    } else {
        return $filename;

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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