This filter allows you to run custom validation on attachments before they are uploaded. The image, file and gallery field include settings to validate width, height, size and type for uploads, however you may find it necessary to add customized logic for all or specific upload fields.


  • Added in v5.1.9


Name Type Description
$errors array An array of errors for the given file about to be uploaded. Appending to this array will result in the attachment failing to upload, and the error message displayed to the client.
$file array An array containing the $_FILE data for the attachment about to be uploaded
$field array An array containing all the field settings for the field which was used to upload the attachment


There are 4 ways to hook into acf/upload_prefilter filter.

  1. acf/upload_prefilter – filter for every field
  2. acf/upload_prefilter/type={$field_type} – filter for a specific field based on it’s type
  3. acf/upload_prefilter/name={$field_name} – filter for a specific field based on it’s name
  4. acf/upload_prefilter/key={$field_key} – filter for a specific field based on it’s key



function my_acf_upload_prefilter( $errors, $file, $field ) {
    // only allow admin
    if( !current_user_can('manage_options') ) {
        $errors[] = 'Only administrators may upload attachments';
    // return
    return $errors;

add_filter('acf/upload_prefilter', 'my_acf_upload_prefilter', 10, 3);


⏰ It's finally time! ACF PRO pricing changes take effect on Monday, 24th February. Learn more

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.