Skip to:
Content
Pages
Categories
Search
Top
Bottom

Change User Role on form submission


  • bassibabes1
    Participant

    @bassibabes1

    Hi,

    I’m trying to change or add a user role for every user who submits a specific form. I couldn’t find a plugin or extension to do this, so have tried writing one myself and I have no idea why it isn’t working.

    Would appreciate any help. Thanks.

    Here’s the code:

    function change_user_role($WPCF7_ContactForm) { 
    	
    	if ( $WPCF7_ContactForm->id !== '10156' )
            return;
    	
    	$user_ID = get_current_user_id();
    	
    	if($user_ID) {
    	$u = new WP_User( $user_ID );
        $u->remove_role( 'pending' );
    	$u->set_role( 'free' );
    	};
    }; 
    add_action( ‘wpcf7_submit’, ‘change_user_role’, 10, 2 );
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Change User Role on form submission’ is closed to new replies.
Skip to toolbar