Add User with Usermeta using ajax

<form id="ajaxform_member" action="ajaxform_member" method="post">
<p class="status"></p>
<label for="mname">Name:</label>
<input type="text" name="mname" id="mname" required></br>

<label for="maddress">Address:</label>
<input type="text" name="maddress" id="maddress" required></br>

<label for="mphone_num">Phone Number:</label>
<input type="text" name="mphone_num" id="mphone_num" required></br>

<label for="memail">Email:</label>
<input type="text" name="memail" id="memail" required></br>

<label for="muname">User Name:</label>
<input type="text" name="muname" id="muname" required></br>

<label for="mpass">Password:</label>
<input type="text" name="mpass" id="mpass" required></br>

<input type="submit" value="Membership Register " name="mregister">


/* Members */
function members() {
$mname = $_POST['mname'];
$maddress = $_POST['maddress'];
$mphone_num = $_POST['mphone_num'];

$memail = $_POST['memail'];
$muname = $_POST['muname'];
$mpass = $_POST['mpass'];

$userdata = array(
'user_email' => $memail,
'user_login' => $muname,
'user_pass' => $mpass,
$user_id = wp_insert_user($userdata);

update_user_meta($user_id, 'm_name', $mname);
update_user_meta($user_id, 'm_address', $maddress);
update_user_meta($user_id, 'm_phone_num', $mphone_num);

$blogusers = get_users( 'role=administrator' );
// Array of WP_User objects.
foreach ( $blogusers as $user ) {

$to = array($memail,$from_email);
//$urllink = ""; //get_page_link(54);
$subject = 'Your Admin Password';
$body = 'Your User name is: <b>' . $muname . '</b> </br>
Your Password is: <b>' . $mpass . '</b></br>';
wp_mail($to, $subject, $body);
add_action( 'wp_ajax_member', 'members' );
add_action( 'wp_ajax_nopriv_member', 'members' );


jQuery(document).ready(function($) {

// Perform AJAX send mail and create user on form submit
$('form#ajaxform_member').on('submit', function(e){
$('form#ajaxform_member p.status').show().text(ajax_signup_object.loadingmessage);
type: 'POST',
dataType: 'json',
url: ajax_signup_object.ajaxurl,
data: {
'action': 'member', //calls wp_ajax_nopriv_ajaxsignup
'mname': $('form#ajaxform_member #mname').val(),
'maddress': $('form#ajaxform_member #maddress').val(),
'mphone_num': $('form#ajaxform_member #mphone_num').val(),
'memail': $('form#ajaxform_member #memail').val(),
'muname': $('form#ajaxform_member #muname').val(),
'mpass': $('form#ajaxform_member #mpass').val(),



Tagged: ,

One thought on “Add User with Usermeta using ajax

  1. SutoCom March 25, 2015 at 12:50 pm Reply

    Reblogged this on SutoCom Solutions.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: