Good morning!
I need with ACF pro to be able to use the standard WordPress creation form to create members, with personalized fields, and to assign them to one or more user groups predefined in ACF too. I can’t find an up-to-date, recent tutorial to learn how to do this.
Thank you for your help.
Hi John, yes i already saw those results, but i dont know witch one could be the good for my need… google sorts 2 650 000 results, and almost are old 🙁
I don’t know what you mean by
assign them to one or more user groups
Is this an ACF field? What type of field? A user Role? A taxonomy? A post?
Unless you’re doing something special then it should be as easy as adding the field group to the WP registration form by setting the field group location rules.
Thanks John 🙂
yes the idea is that I create user groups with ACF (group 1, group 2 and group 3 for example).
Then I can assign a user to one of these groups directly when I create this user with the normal WP profile creation system. That’s all 🙂
I still don’t understand WHAT specifically these groups are.
Or you don’t know and you are asking how someone would do this? It could be done an any one of these ways.
that’s part of the question I’m asking myself too 🙂 These will be user groups. Imagine a company for example: You have the Staff, the Office and the Management. This group can see this page but not another, this group can see ALL the pages etc… I know how to manage this, regarding permissions, with USER ROLE EDITOR which I already have.
I may have misspoke because WP does not support taxonomies on users. That option would really not be viable.
The best option I can think of is to use user roles
What you would really need to do is to create a select box with the groups. Then you’d have to use an acf/save_post action to get the value selected and set the user’s role based on the values saved in the field.
In your action you’d want to make sure a user is being created or saved, the $post_id value in this case would start with “user”, (ie: "user_{$user_id}"
).
I thought it would be simpler… ACF can create groups of fields I saw, and it should also be able to add a GROUP type field to the registration form? I have no PHP skills…
You can put them in groups using an ACF select type field.
The real question is what are you going to use the field for. No matter what way you turn you’ll need to either do something like adding the roles mentioned or doing a custom query on users with a meta_query on the field to get users in a specific group.
And if you’re talking about limiting access to certain pages based on this value, then in either case it’s going to require custom coding.
thank you John for trying to help me. I told you that for group authorizations I use USER ROLE EDITOR which works very easily and without coding anything, it is very easy to manage that with this plugin. My ONLY question is in the creation of users, to be able to assign them in these groups created by ACF, that’s all 😉
Let’s say that you create a select type field with the values
group_1 : Group 1
group_2 : Group 2
group_3 : Group 3
group_4 : Group 4
the values are on the left, and that you also create user roles that match the values.
add_action('acf/save_post', 'add_user_role_from_acf', 20);
function add_user_role_from_acf($post_id) {
if (substr($post_id, 0, 5) != 'user_') {
// not saving a user
return;
}
if (empty(get_field('your_field_name', $post_id)) {
// no value saved in user group field
return;
}
$role = get_field('your_field_name', $post_id);
$user_id = intval(substr($post_id, 5));
$user = new WP_User($user_id);
$user->set_role($role);
}
One not is that you would only want to show the field on the new user registration form and not on edit user page because this function would not distinguish between adding a user and updating a user. The field would not be needed in the admin because there if it needed to be changed you would do that using the WP Role setting field.
thanks John. This all seems complicated to me… maybe there is a plugin that can handle all this directly I think? But I can’t find which one will do it well.
the only needs is to connect Members i create with ACF groups i do and standard WP core user system…
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!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.