Support

Account

Home Forums ACF PRO Register new user with acf_form Reply To: Register new user with acf_form

  • I have found !

    function register_accueilli($post_id) {
    	
    	$action  = $_POST['action_form'];
    
        	if ( $action == "inscription_accueilli" ) {
        
            $f      = $_POST['acf'];
            $prenom = $f['field_580dda605ce41'];
            $nom    = $f['field_580dda605cdc8'];
            $email  = $f['field_580f277e392bc'];
            $pseudo = sanitize_title($prenom." ".$nom);
    
            if ( !username_exists($pseudo) && !email_exists($email) ) {
    
                $random_password = wp_generate_password( $length = 8, false );
                $key_active      = wp_generate_password( $length = 20, false );
    
                $user_id         = wp_create_user( $pseudo, $random_password, $email );
                $user_id_role    = new WP_User($user_id);
                $user_id_role->set_role('accueilli');
    
                update_user_meta($user_id, 'pseudo', $pseudo );
                update_user_meta($user_id, 'key_new', $key_active );
    
                $test_inscription = wp_update_user( array(
                    'ID'            => $user_id,
                    'first_name'    => $prenom,
                    'last_name'     => $nom,
                    'user_login'    => $pseudo,
                    'user_nicename' => $prenom . " " . $nom,
                    'display_name'  => $prenom . " " . $nom
                ));
    
                $values_emails = array(
                    'prenom'      => $prenom,
                    'nom'         => $nom,
                    'pseudo'      => $pseudo,
                    'mdp'         => $random_password,
                    'url_activer' => get_bloginfo('url')."/inscription/activer-votre-compte/?key=".$key_active
                );
    
                envoyer_mail($email,232, $values_emails);
    
                /* ------  ADD THE DO_ACTION SAVE POST ------ */
                do_action('acf/save_post', "user_".$user_id);
    
            }
            
        }
    
    }
    
    add_filter('acf/pre_save_post' , 'register_accueilli' );