Hi,
i’d like to prevent user from modifying a field value, once the post has been published.
=> is there any action / filter / function to dynamically set this field to read-only in wp-admin, “if post_status == ‘publish’ && current_user_can(“publisher”) ?
Thanks for your help
Baptiste
Hi Baptiste,
Yes, you can use the acf/load_field
filter to modify the field object. The code would look something like this:
function my_load_field($field) {
if(...) {
$field['readonly'] = 1;
}
return $field;
}
add_filter("acf/load_field", "my_load_field");
For more info, check out the documentation of the filter. Here is the link: http://www.advancedcustomfields.com/resources/acfload_field/
Hi —
I have found that setting readonly to 1 works for text fields, but not for fields of other types — if there’s a widget, the widget still functions (*and* changed values are saved). In my case I have both a select of users and a radio dialog box.
Currently I am getting around this by converting each field to a text field in the load_field filter, plus setting it to readonly.
But this feels very hacky and fragile — I already ran into a problem where I had switched between saving the label or the value of a choice and it broke.
So I would like to add my vote for official support of the ability to dynamically set a field to readonly, and have that work for widgets as well.
Hi @draperd
Could you please open a new ticket so your request can be passed directly to the plugin author? You can open a new ticket here: https://support.advancedcustomfields.com/new-ticket. Also, please don’t forget to explain your request again.
Thanks 🙂