I have a select field that is getting disabled .. mysteriously. Which is to say, I can’t figure how it’s happening. I put a debug output in the load_field filter for that field, and the “disabled” property is already true. I’m not sure when this started happening, as it’s been some months since anyone has needed to do anyhting that required the field to be enabled (ie, I can’t point to a recent plugin update as the potential culprit). There is one spot in the code where the field gets disabled, but it’s in that same load_field filter, and commenting out the disablement doesn’t change the outcome.
Is there a filter earlier in the page lifecycle than load_field? I’m trying to figure out when it’s happening.
It would have to be happening in a filter somewhere on the site. ACF by default does not add the ability to disable fields and it must be done in a filter.
I would start with a search of the code base for acf/load_field or acf/prepare_field filters. It’s possible that a filter on some other field is affecting this select field as well.
Another possibility is that the acf/load_field filter affected the field while a field group was being edited and ACF save it in the field settings for the field. acf/load_field can affect how fields are saved, for example if an acf/load_field filter is used to add choices dynamically to a select field, these added choices will appear when editing a field. Whereas an acf/prepare_field filter will not have this result. Generally it is better to use an acf/prepare_field filter rather than an acf/load_field filter for this reason. But the acf/prepare_field filter is newer.
Thanks, John! I ended up using get_field_object() to see how the field was coming out of the data store, wondering if that might be before any filters were applied, and the disabled flag was set to 1 in the return from that function.
Then I remembered that I’d created an acf-json folder in my theme just a few days prior to take advantage of the caching speed. Sure enough, the json that had been written to disk had the disabled flag on. I deleted the folder, and the field went back to functioning normally.
So it appears that anything that happens in load_field affects what’s cached in the acf-json folder. I reported this in a support ticket.
I appreciate the insight into prepare_field vs. load_field. I switched to prepare_field for this conditional disabling.
The issue with the acf/load_field filter affecting the saving a fields when editing has always existed. When I say acf/prepare_field is newer, it was introduced in version 5.0.0, for most people they have probably never worked with ACF without this. Before this version I always added checks to my acf/load_field filters to check if an ACF field group was being edited before applying the field.
There should be more information given in the docs for these filters. acf/load_field more or less permanently alters the field unless you never edit a field group where acf/prepare_field is a temporary change applied just before the field is show.
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!