Home › Forums › General Issues › Allow roles to be set to certain users › Reply To: Allow roles to be set to certain users
Thanks for the extra info. Knowing this, I would not create a custom location rules. What you should do is create your field group with a field for each user. You need to have some sort of patern in the field name which has either the user’s ID or the user’s username in it. So perhaps “accept_job_dave” or “accept_job_3”.
Then, use the filter acf/load_field (http://www.advancedcustomfields.com/resources/filters/acfload_field/) to remove fields.
Lets say the current logged in user is “jeff”. In your filter, you would target all fields, or perhaps only all radio fields (explained in docs).
Then, your code would look at the field name ($field[‘name’]). If this name included the string “accept_job_”, then you would compare the currentl logged in user to the field like so:
<?php
if( strpos($field['name'], 'accept_job_') !== false )
{
// accept_job_ was found in field name
$user = str_replace('accept_job_', '', $field['name']);
// $user is no 'jeff', find curent logged in user
$current_user_name = wp_function_to_find_current_username();
// compare and completely remove field if this user is not meant to see it!
if( $current_user_name != $user )
{
$field = null;
}
return $field;
}
?>
I hope that code example helps explain what you need to do.
Thanks
E
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!
We’re hard at work on ACF 6.1, and Beta 1 is now available 🚀
— Advanced Custom Fields (@wp_acf) March 16, 2023
This release includes custom post type and taxonomy registration, an improved experience when selecting field types, PHP 8.1 and 8.2 compatibility, and more!
Let’s take a look 🧵https://t.co/Y0WcAT11l4
© 2023 Advanced Custom Fields.
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.