assign roles to users in custom drop down in signup form

You have to set user role using user id. use below code to assign role to user. add below code after this line : $user_id = wp_create_user($firstname,$lastname,$email); set role to new created user. by default it will set subscriber role. $user_id_role = new WP_User($user_id); $user_role = !empty($_POST[‘role’]) ? $_POST[‘role’] : ‘subscriber’; $user_id_role->set_role($user_role); i have tested … Read more

Check if specific role exists

This is based on Bosco’s comment. You can do this instead of line 3 in the above code: wp_roles()->is_role( ‘editor’ ); That grabs a WP_Roles object (what the code you had tries to do by getting a global variable) and calls the same is_role() function.

Disable Woocommerce checkout based on user role [closed]

Woocommerce is considered off-topic here but as a general answer, it is considered best practice to check against capabilities instead of roles In WP, this is done like that: add_action(‘init’, ‘wpse_capability_check’); // hooked on ‘init’ but depends on your actual code logic function wpse_capability_check(){ // you should check on a capability that only validated user … Read more

How to add user roles? [closed]

What you want is add_role() The Codex provides sample code: $result = add_role( ‘basic_contributor’, __( ‘Basic Contributor’ ), array( ‘read’ => true, // true allows this capability ‘edit_posts’ => true, ‘delete_posts’ => false, // Use false to explicitly deny ) ); if ( null !== $result ) { echo ‘Yay! New role created!’; } else … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)