Welcome to the forum. If this is your first time you can browse around and see what you like. You will need to be registered in order to post!

Join our community and talk about tech, gaming, get support for computer problems and even sale your own product.
Considering supporting us by subscribing.

Validation for WP Roles at Registration

Post Reply
User avatar
kachan64
USER_STATUS: Offline
Site Admin
Site Admin
Posts: 47
Joined: Sat Jul 01, 2017 9:35 pm
Contact:

Validation for WP Roles at Registration

Post by kachan64 » Thu Jan 02, 2020 3:25 pm

What is WP Roles at Registration?
This plugin asks the user to choose his role in the website during registration from a list of selected roles. It works with BuddyPress also. It provides an interface from where the admin can choose which roles to display during registration for the user to choose from.
What is this?

Someone asked if they can check if a user has selected a role while they register. So here I whipped out a simple code which will check against default role selection and throws in an error message upon selection.

Code: Select all

// Code taken from http://chatngo.co/bb/viewtopic.php?f=10&t=279
add_filter( 'registration_errors', 'select_user_role_error', 10, 3 );
function select_user_role_error( $errors, $sanitized_user_login, $user_email ) {
  if(isset($_REQUEST['wp_rar_user_role']) && $_REQUEST['wp_rar_user_role'] == 'contributor') :

    $errors->add( 'policy_error', "<strong>ERROR</strong>: Please select an option." );
    return $errors;
  endif;
  return $errors;
}
You can change which role to target by changing contributor to your own. Also error messages are customizable.

This guide was based off: https://stackoverflow.com/questions/102 ... -down-list
Image
PC: Custom Built Gaming PC
Monitor: Samsung S24D390H, Asus VE248H

Post Reply

Return to “WordPress”

Who is online

Users browsing this forum: No registered users and 0 guests

Topic Subscribers

1 user subscribed to this topic: kachan64