Ivon Filho

Ivon Filho

Olá, procurando web designer freelancer para seu projeto?

Criar registro de usuário através de formulário Pro do Elementor

Tutorial em vídeo sobre como usar os formulários PHP e Elementor Pro, para criar um formulário de registro.

<?php
/**
 * Plugin Name: Elementor Form Create New User
 * Description: Create a new user using elementor form
 * Author:      Gal Hadad
 * Author URI:  https://wpsite.co.il
 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
 */

add_action( 'elementor_pro/forms/new_record',  'thewpchannel_elementor_form_create_new_user' , 10, 2 );

function thewpchannel_elementor_form_create_new_user($record,$ajax_handler)
{
    $form_name = $record->get_form_settings('form_name');
    //Check that the form is the "create new user form" if not - stop and return;
    if ('Create New User' !== $form_name) {
        return;
    }
    $form_data = $record->get_formatted_data();
    $username=$form_data['User Name']; //Get tne value of the input with the label "User Name"
    $password = $form_data['Password']; //Get tne value of the input with the label "Password"
    $email=$form_data['Email'];  //Get tne value of the input with the label "Email"
    $user = wp_create_user($username,$password,$email); // Create a new user, on success return the user_id no failure return an error object
    if (is_wp_error($user)){ // if there was an error creating a new user
        $ajax_handler->add_error_message("Failed to create new user: ".$user->get_error_message()); //add the message
        $ajax_handler->is_success = false;
        return;
    }
    $first_name=$form_data["First Name"]; //Get tne value of the input with the label "First Name"
    $last_name=$form_data["Last Name"]; //Get tne value of the input with the label "Last Name"
    wp_update_user(array("ID"=>$user,"first_name"=>$first_name,"last_name"=>$last_name)); // Update the user with the first name and last name


    /* Automatically log in the user and redirect the user to the home page */
    $creds= array( // credientials for newley created user
        "user_login"=>$username,
        "user_password"=>$password,
        "remember"=>true
    );
    $signon = wp_signon($creds); //sign in the new user
    if ($signon)
        $ajax_handler->add_response_data( 'redirect_url', get_home_url() ); // optinal - if sign on succsfully - redierct the user to the home page
}

Fonte: https://gal.dev/2019/03/create-registration-form-using-elementor-pro/

Rolar para cima

Vamos Conversar?

Melhorar sua performance digital é o nosso desafio. Colecionamos cases de sucesso e queremos fazer o mesmo pela sua marca. Envie uma mensagem pra gente!

Blog

Web Designer Freelancer Brasília DF

Sobre

Apaixonado por WordPress, Ivon Filho atua como web designer e desenvolvedor front-end desde 2010.

Trabalhando como freelancer, atende desde pequenas a grandes empresas que procuram por serviços de excelente qualidade a um custo acessível, além de agências que precisam terceirizar essas demandas.

Criação de sites em WordPress e desenvolvimento de plugins e temas personalizados são as especialidades da “casa”! O verdadeiro conceito de “feito à mão”.

Experiências

Website Developer

Viva Pixel
Freelancer

Website Developer

Conectando Pessoas
2013 – 2016 - 3 anos

Website Developer

7 Pontos Agência Integrada
2012 – 2013 - 1 ano

Formação

Universidade Paulista

Comunicação e Mídias Digitais
2009 – 2011