How to change user role after wordpress registration

  • 5 years-11 months

    How to change user role after wordpress registration

    • Category : wordpress
    • Viewed : 50 times
    • Posted On :
    • Posted by : Vikas

    This action hook allows you to access data for a new user immediately after they are added to the database. The user id is passed to hook as an argument.

    add_action( 'user_register', 'eddpremium_register_fields_save');
    add_action( 'profile_update', 'eddpremium_register_fields_save');
    
    function eddpremium_register_fields_save($user_id) {
    	$u = new WP_User($user_id);
    
    	// Remove role
    	$u->remove_role( 'subscriber' );
    
    	// Add role
    	$u->add_role( 'author' );
    }
     

Report this or Ask your own question

Your Answer

When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
Let's work to help developers, not make them feel stupid.