• I have a simple need, and help would be greatly appreciated.

    How do I make it so that when a form is submitted, then the current logged in users role is set. (this form will only be visible to logged in users).

    No conditions, I am just trying to make it so when the form is submitted the users role automatically changes.

    I’m not a programmer and I have no idea of PHP. I’m reaching out to see if there is a simple way to do this.

    I do have a plugin installed which allows me to run javascript at form submission, but that’s client side, not sure it helps.

Viewing 1 replies (of 1 total)
  • Hi
    I am giving you an just idea and hope that help you.
    You need to get postdata after form submit.
    Add this code in your active child theme.

    add_action( 'wpcf7_mail_sent', 'ahir_wpcf7_mail_sent_function' ); 
    function ahir_wpcf7_mail_sent_function( $contact_form ) {
        $title = $contact_form->title;
        $submission = WPCF7_Submission::get_instance();  
        if ( $submission ) {
            $posted_data = $submission->get_posted_data();
        }   
       // with specific form tilte    
       if ( 'Reagistation' == $title ) {
            $role = strtolower($posted_data['role']);
            $user = wp_get_current_user();
            $user_id =  $user->ID;
              $u = new WP_User( $user_id );
            // Replace the current role with 'manager' role
    	 $u->set_role( 'manager' );
     }
    }

    Not tested but this way you can do something like you want.

    Thanks
    Ahir

Viewing 1 replies (of 1 total)

The topic ‘Upgrade user role’ is closed to new replies.