分享这篇文章

WordHerd just finished building a custom user database and profile search in WordPress for a customer.

The Issue with Publicly Accessible ACF Image Fields

When building the user database we needed to add additional image fields to user profiles. The issue was that when a user logged in to edit their profile they would have access to the media library through the image uploader.

Converting ACF Image Fields to the Basic Uploader

In order to resolve this we found a great solution from a Guru on the ACF forum, but we had to tweak the code slightly. Below is a tweaked version of the code he provided. The only difference is that the original was meant for the front-end, where as this is for the admin user edit page.

// force basic uploader for a certain field
function my_acf_force_basic_uploader( $field ) {

// set the uploader setting before rendering the field
acf_update_setting('uploader', 'basic');

return $field;
}

// target the field using its name (Replace field_name)
add_filter('acf/prepare_field/name=field_name', 'my_acf_force_basic_uploader');

The filter assigns a custom function my_acf_force_basic_uploader to the ACF field before it’s rendered. This allows us to filter the field data before display, which is where we use acf_update_setting to change the uploader to ‘basic’, telling ACF not to use the media library uploader.

Reference post: https://support.advancedcustomfields.com/forums/topic/enable-basic-uploader-for-frontend-comments/


WordHerd provides website migration services from any CMS platform to WordPress. In addition to moving your content and converting your theme, we can also migrate custom data to Advanced Custom Fields (ACF) through our powerful processing tool, the Wrangler. If you have a CMS or customer that you need help moving get a free evaluation.

准备好迁移您的网站了吗?

首先进行免费的无义务网站评估。我们将对您的项目进行评估,推荐合适的平台,并为您提供明确的报价。

保证零数据丢失
完整 SEO 保留与重定向映射
准时且按预算交付
专业化的平台专家,而非泛泛的专家

请告诉我们您的网站信息

"*"*” 表示必填字段

此字段用于验证目的,不应更改。
姓名*