Home › Forums › General Issues › Change user role on a front-end form save? › Reply To: Change user role on a front-end form save?
Hi @dzonivejin,
Thanks for the post.
You can hook into the acf/pre_save_post filter and then change the user roles using the WP_User class. A user’s role can be set by creating an instance of the WP_user class, and calling the add_role() or remove_role() methods.
The code would look like so:
$u = new WP_User( $user_id );
// Remove role
$u->remove_role( 'subscriber' );
// Add role
$u->add_role( 'editor' );
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.