acf/upload_prefilter


目录

Description

Used to perform custom validation on an attachment and prevent it being uploaded.

Similar to the acf/validate_attachment filter, this hook can be used to prevent a file being uploaded via the WP media modal.

Changelog

Parameters

apply_filters( 'acf/upload_prefilter', $errors, $file, $field );

Modifers

This filter provides modifiers to target specific fields. The following filter names are available:

Example

This example demonstrates how to restrict all uploads from ACF fields (Image, File, Gallery) to admin users only.

functions.php

<?php
add_filter('acf/upload_prefilter', 'my_acf_upload_prefilter', 10, 3);
function my_acf_upload_prefilter( $errors, $file, $field ){

    // Check if not admin.
    if( !current_user_can('manage_options') ) {
        $errors[] = __( 'Only administrators may upload attachments' );
    }
    return $errors; 
}

版本号 #1
由 壳壳虫 创建于 2026-08-29 15:44:03 UTC
由 壳壳虫 更新于 2026-08-29 15:44:03 UTC