Register New WordPress Users with Elementor Form Approval
Create WooCommerce customer accounts from an Elementor Pro form, add an admin approval column, and block login until approval.
This snippet connects an Elementor Pro registration form to WordPress user creation. It creates a customer account, stores an approval flag, adds an approval action to the Users screen, emails the administrator and customer, and prevents unapproved accounts from logging in or resetting their password.
Before using it, create an Elementor Pro form named exactly registration_form with fields using the IDs name, email, and phone. Test the complete approval and password-reset flow on staging before enabling it on a live site.
The complete snippet
// Handle Elementor registration form submission.add_action( 'elementor_pro/forms/new_record', function ( $record, $handler ) { $form_name = $record->get_form_settings( 'form_name' );
if ( 'registration_form' !== $form_name ) { return; }
$raw_fields = $record->get( 'fields' ); $fields = array();
foreach ( $raw_fields as $id => $field ) { $fields[ $id ] = sanitize_text_field( $field['value'] ); }
$first_name = $fields['name'] ?? ''; $email = sanitize_email( $fields['email'] ?? '' ); $phone = $fields['phone'] ?? '';
if ( empty( $email ) ) { return; }
$username = sanitize_user( current( explode( '@', $email ) ) ); $password = wp_generate_password(); $user_id = wp_create_user( $username, $password, $email );
if ( ! is_wp_error( $user_id ) ) { wp_update_user( array( 'ID' => $user_id, 'first_name' => $first_name, 'role' => 'customer', ) );
update_user_meta( $user_id, 'customer_approved', 0 ); update_user_meta( $user_id, 'billing_phone', $phone ); update_user_meta( $user_id, 'shipping_phone', $phone );
wp_mail( get_option( 'admin_email' ), 'New Customer User Pending Approval', "A new Customer user has registered and is pending approval:\n\nName: $first_name\nEmail: $email\nPhone: $phone\n\nApprove Now: " . admin_url( 'users.php' ) ); }}, 10, 2 );
// Add approval column.add_filter( 'manage_users_columns', function ( $columns ) { $columns['customer_approved'] = 'Customer Approved'; return $columns;} );
// Column content and Approve button.add_filter( 'manage_users_custom_column', function ( $output, $column_name, $user_id ) { if ( 'customer_approved' === $column_name ) { $approved = get_user_meta( $user_id, 'customer_approved', true );
if ( 1 == $approved ) { return '<span style="color:green;font-weight:bold;">Approved</span>'; }
$approve_url = wp_nonce_url( add_query_arg( array( 'action' => 'approve_customer_user', 'user_id' => $user_id, ) ), 'approve_customer_user_' . $user_id );
return '<a href="' . esc_url( $approve_url ) . '" class="button">Approve</a>'; }
return $output;}, 10, 3 );
// Approval action.add_action( 'admin_init', function () { if ( isset( $_GET['action'], $_GET['user_id'] ) && 'approve_customer_user' === $_GET['action'] ) { $user_id = intval( $_GET['user_id'] );
if ( wp_verify_nonce( $_GET['_wpnonce'], 'approve_customer_user_' . $user_id ) ) { update_user_meta( $user_id, 'customer_approved', 1 );
$user_info = get_userdata( $user_id ); $reset_link = wp_lostpassword_url();
wp_mail( $user_info->user_email, 'Your Account Has Been Approved', "Hi {$user_info->first_name},\n\nYour account has been approved.\nYou can set your password here: $reset_link\n\nThank you!" );
wp_redirect( remove_query_arg( array( 'action', 'user_id', '_wpnonce' ) ) ); exit; } }} );
// Prevent login until approved.add_filter( 'authenticate', function ( $user, $username, $password ) { if ( $user instanceof WP_User ) { $approved = get_user_meta( $user->ID, 'customer_approved', true );
if ( 1 != $approved ) { return new WP_Error( 'approval_pending', __( 'Your account is pending approval. Please wait for admin approval.', 'textdomain' ) ); } }
return $user;}, 30, 3 );
// Block password reset for unapproved users.add_action( 'validate_password_reset', function ( $errors, $user ) { if ( $user && ! is_wp_error( $user ) ) { $approved = get_user_meta( $user->ID, 'customer_approved', true );
if ( 1 != $approved ) { $errors->add( 'approval_pending', __( 'Your account is pending approval. You cannot reset your password yet.', 'textdomain' ) ); } }}, 10, 2 );
// Also block the Set New Password screen.add_action( 'login_form_rp', 'block_unapproved_password_reset' );add_action( 'login_form_resetpass', 'block_unapproved_password_reset' );
function block_unapproved_password_reset() { $user = check_password_reset_key( $_REQUEST['key'] ?? '', $_REQUEST['login'] ?? '' );
if ( $user instanceof WP_User ) { $approved = get_user_meta( $user->ID, 'customer_approved', true );
if ( 1 != $approved ) { wp_die( __( 'Your account is pending approval. You cannot set a new password yet.', 'textdomain' ) ); } }}The form name must be registration_form. The field IDs used by the snippet are name, email, and phone.