Cant add user from front end with phpWhat's the best method for sanitizing user input with PHP?What is the best way to add options to a select from as a JS object with jQuery?PHP: Delete an element from an arrayPrevent users from submitting a form by hitting EnterPHP login and get user informationReturning JSON from a PHP Scripti am trying to make a simple login pageZend Ajax post to actionHow to pass variables and data from PHP to JavaScript?ajax jquery json phpmailer with smtp

Generic lambda vs generic function give different behaviour

How can I replace every global instance of "x[2]" with "x_2"

Can I use my Chinese passport to enter China after I acquired another citizenship?

Bash method for viewing beginning and end of file

How can I get through very long and very dry, but also very useful technical documents when learning a new tool?

Cynical novel that describes an America ruled by the media, arms manufacturers, and ethnic figureheads

Is it correct to write "is not focus on"?

If you attempt to grapple an opponent that you are hidden from, do they roll at disadvantage?

Is there an Impartial Brexit Deal comparison site?

How could Frankenstein get the parts for his _second_ creature?

Efficiently merge handle parallel feature branches in SFDX

What defines a dissertation?

Can a monster with multiattack use this ability if they are missing a limb?

Your magic is very sketchy

Coordinate position not precise

Teaching indefinite integrals that require special-casing

What to do with wrong results in talks?

Is a roofing delivery truck likely to crack my driveway slab?

Opposite of a diet

What would be the benefits of having both a state and local currencies?

Should my PhD thesis be submitted under my legal name?

Can somebody explain Brexit in a few child-proof sentences?

What is the opposite of 'gravitas'?

I'm in charge of equipment buying but no one's ever happy with what I choose. How to fix this?



Cant add user from front end with php


What's the best method for sanitizing user input with PHP?What is the best way to add options to a select from as a JS object with jQuery?PHP: Delete an element from an arrayPrevent users from submitting a form by hitting EnterPHP login and get user informationReturning JSON from a PHP Scripti am trying to make a simple login pageZend Ajax post to actionHow to pass variables and data from PHP to JavaScript?ajax jquery json phpmailer with smtp













-3















Im working on a frontend only system, and i need a way for admins to add a user from the front end.



However i cant seem to get it to work. Any help would be appreciated.



here is my code im calling it through AJAX






$( "#createuser" ).click(function() 
var getusername = $("#usernameset").val();
var getpassword = $("#userpasswordset").val();
var getemail = $("#useremailset ").val();
var getlocation = $(".country_id_set").html();

adduserfrontend(getusername,getpassword,getemail,getlocation);
);

function adduserfrontend(username,password,email,location)
$.ajax (
url: "http://localhost/wordpress/wp-content/themes/example/functions.php",
type: 'POST',
data:
action: 'addnewuser',
'username': username,
'password': password,
'email': email,
'location': location,
,
success: function (results)
console.log( 'New user was added' );
,
fail: function(data)
console.log( data.responseText );
console.log( 'Request Failed' + data.statusText );

)

<div class="adduser">
<label>Username: </label><input type="text" id="usernameset" name="usernameset" placeholder="New User">
<label>Password: </label><input type="text" id="userpasswordset" name="userpasswordset" placeholder="Enter Password">
<label>Email: </label><input type="text" id="useremailset" name="useremailset" placeholder="example@example.com">
<button id="createuser">Create User</button>
</div>





PHP






function addnewuser() 
$username = sanitize_text_field( $_POST['username'] );
$pasword = sanitize_text_field( $_POST['password'] );
$email = sanitize_text_field( $_POST['email'] );
$location = sanitize_text_field( $_POST['location'] );
// add new user
$user_id = wp_create_user( $username, $pasword, $email );
$user_id_role = new WP_User($user_id);
$user_id_role->location($location);

exit;


add_action( 'wp_ajax_addnewuser', 'addnewuser' );












share|improve this question

















  • 4





    Please clarify what exactly is not working with the given code

    – Nico Haase
    Mar 8 at 9:38











  • Ajax posts to functions.php How ever nothing happens from there. User is not added to the wordpress install.

    – Mic
    Mar 8 at 9:40






  • 2





    So, what have you tried to debug the problem?

    – Nico Haase
    Mar 8 at 9:41











  • in my php, i have tried setting the username,password,email and location within the php, so it doesnt need the $_Post information and still nothing. Other then that. im not sure what else to try and debug it with.

    – Mic
    Mar 8 at 9:42






  • 1





    set up your error function of jquery ajax as well along with success and fail. see if you end up in error function

    – Gagan Deep
    Mar 8 at 9:50















-3















Im working on a frontend only system, and i need a way for admins to add a user from the front end.



However i cant seem to get it to work. Any help would be appreciated.



here is my code im calling it through AJAX






$( "#createuser" ).click(function() 
var getusername = $("#usernameset").val();
var getpassword = $("#userpasswordset").val();
var getemail = $("#useremailset ").val();
var getlocation = $(".country_id_set").html();

adduserfrontend(getusername,getpassword,getemail,getlocation);
);

function adduserfrontend(username,password,email,location)
$.ajax (
url: "http://localhost/wordpress/wp-content/themes/example/functions.php",
type: 'POST',
data:
action: 'addnewuser',
'username': username,
'password': password,
'email': email,
'location': location,
,
success: function (results)
console.log( 'New user was added' );
,
fail: function(data)
console.log( data.responseText );
console.log( 'Request Failed' + data.statusText );

)

<div class="adduser">
<label>Username: </label><input type="text" id="usernameset" name="usernameset" placeholder="New User">
<label>Password: </label><input type="text" id="userpasswordset" name="userpasswordset" placeholder="Enter Password">
<label>Email: </label><input type="text" id="useremailset" name="useremailset" placeholder="example@example.com">
<button id="createuser">Create User</button>
</div>





PHP






function addnewuser() 
$username = sanitize_text_field( $_POST['username'] );
$pasword = sanitize_text_field( $_POST['password'] );
$email = sanitize_text_field( $_POST['email'] );
$location = sanitize_text_field( $_POST['location'] );
// add new user
$user_id = wp_create_user( $username, $pasword, $email );
$user_id_role = new WP_User($user_id);
$user_id_role->location($location);

exit;


add_action( 'wp_ajax_addnewuser', 'addnewuser' );












share|improve this question

















  • 4





    Please clarify what exactly is not working with the given code

    – Nico Haase
    Mar 8 at 9:38











  • Ajax posts to functions.php How ever nothing happens from there. User is not added to the wordpress install.

    – Mic
    Mar 8 at 9:40






  • 2





    So, what have you tried to debug the problem?

    – Nico Haase
    Mar 8 at 9:41











  • in my php, i have tried setting the username,password,email and location within the php, so it doesnt need the $_Post information and still nothing. Other then that. im not sure what else to try and debug it with.

    – Mic
    Mar 8 at 9:42






  • 1





    set up your error function of jquery ajax as well along with success and fail. see if you end up in error function

    – Gagan Deep
    Mar 8 at 9:50













-3












-3








-3








Im working on a frontend only system, and i need a way for admins to add a user from the front end.



However i cant seem to get it to work. Any help would be appreciated.



here is my code im calling it through AJAX






$( "#createuser" ).click(function() 
var getusername = $("#usernameset").val();
var getpassword = $("#userpasswordset").val();
var getemail = $("#useremailset ").val();
var getlocation = $(".country_id_set").html();

adduserfrontend(getusername,getpassword,getemail,getlocation);
);

function adduserfrontend(username,password,email,location)
$.ajax (
url: "http://localhost/wordpress/wp-content/themes/example/functions.php",
type: 'POST',
data:
action: 'addnewuser',
'username': username,
'password': password,
'email': email,
'location': location,
,
success: function (results)
console.log( 'New user was added' );
,
fail: function(data)
console.log( data.responseText );
console.log( 'Request Failed' + data.statusText );

)

<div class="adduser">
<label>Username: </label><input type="text" id="usernameset" name="usernameset" placeholder="New User">
<label>Password: </label><input type="text" id="userpasswordset" name="userpasswordset" placeholder="Enter Password">
<label>Email: </label><input type="text" id="useremailset" name="useremailset" placeholder="example@example.com">
<button id="createuser">Create User</button>
</div>





PHP






function addnewuser() 
$username = sanitize_text_field( $_POST['username'] );
$pasword = sanitize_text_field( $_POST['password'] );
$email = sanitize_text_field( $_POST['email'] );
$location = sanitize_text_field( $_POST['location'] );
// add new user
$user_id = wp_create_user( $username, $pasword, $email );
$user_id_role = new WP_User($user_id);
$user_id_role->location($location);

exit;


add_action( 'wp_ajax_addnewuser', 'addnewuser' );












share|improve this question














Im working on a frontend only system, and i need a way for admins to add a user from the front end.



However i cant seem to get it to work. Any help would be appreciated.



here is my code im calling it through AJAX






$( "#createuser" ).click(function() 
var getusername = $("#usernameset").val();
var getpassword = $("#userpasswordset").val();
var getemail = $("#useremailset ").val();
var getlocation = $(".country_id_set").html();

adduserfrontend(getusername,getpassword,getemail,getlocation);
);

function adduserfrontend(username,password,email,location)
$.ajax (
url: "http://localhost/wordpress/wp-content/themes/example/functions.php",
type: 'POST',
data:
action: 'addnewuser',
'username': username,
'password': password,
'email': email,
'location': location,
,
success: function (results)
console.log( 'New user was added' );
,
fail: function(data)
console.log( data.responseText );
console.log( 'Request Failed' + data.statusText );

)

<div class="adduser">
<label>Username: </label><input type="text" id="usernameset" name="usernameset" placeholder="New User">
<label>Password: </label><input type="text" id="userpasswordset" name="userpasswordset" placeholder="Enter Password">
<label>Email: </label><input type="text" id="useremailset" name="useremailset" placeholder="example@example.com">
<button id="createuser">Create User</button>
</div>





PHP






function addnewuser() 
$username = sanitize_text_field( $_POST['username'] );
$pasword = sanitize_text_field( $_POST['password'] );
$email = sanitize_text_field( $_POST['email'] );
$location = sanitize_text_field( $_POST['location'] );
// add new user
$user_id = wp_create_user( $username, $pasword, $email );
$user_id_role = new WP_User($user_id);
$user_id_role->location($location);

exit;


add_action( 'wp_ajax_addnewuser', 'addnewuser' );








$( "#createuser" ).click(function() 
var getusername = $("#usernameset").val();
var getpassword = $("#userpasswordset").val();
var getemail = $("#useremailset ").val();
var getlocation = $(".country_id_set").html();

adduserfrontend(getusername,getpassword,getemail,getlocation);
);

function adduserfrontend(username,password,email,location)
$.ajax (
url: "http://localhost/wordpress/wp-content/themes/example/functions.php",
type: 'POST',
data:
action: 'addnewuser',
'username': username,
'password': password,
'email': email,
'location': location,
,
success: function (results)
console.log( 'New user was added' );
,
fail: function(data)
console.log( data.responseText );
console.log( 'Request Failed' + data.statusText );

)

<div class="adduser">
<label>Username: </label><input type="text" id="usernameset" name="usernameset" placeholder="New User">
<label>Password: </label><input type="text" id="userpasswordset" name="userpasswordset" placeholder="Enter Password">
<label>Email: </label><input type="text" id="useremailset" name="useremailset" placeholder="example@example.com">
<button id="createuser">Create User</button>
</div>





$( "#createuser" ).click(function() 
var getusername = $("#usernameset").val();
var getpassword = $("#userpasswordset").val();
var getemail = $("#useremailset ").val();
var getlocation = $(".country_id_set").html();

adduserfrontend(getusername,getpassword,getemail,getlocation);
);

function adduserfrontend(username,password,email,location)
$.ajax (
url: "http://localhost/wordpress/wp-content/themes/example/functions.php",
type: 'POST',
data:
action: 'addnewuser',
'username': username,
'password': password,
'email': email,
'location': location,
,
success: function (results)
console.log( 'New user was added' );
,
fail: function(data)
console.log( data.responseText );
console.log( 'Request Failed' + data.statusText );

)

<div class="adduser">
<label>Username: </label><input type="text" id="usernameset" name="usernameset" placeholder="New User">
<label>Password: </label><input type="text" id="userpasswordset" name="userpasswordset" placeholder="Enter Password">
<label>Email: </label><input type="text" id="useremailset" name="useremailset" placeholder="example@example.com">
<button id="createuser">Create User</button>
</div>





function addnewuser() 
$username = sanitize_text_field( $_POST['username'] );
$pasword = sanitize_text_field( $_POST['password'] );
$email = sanitize_text_field( $_POST['email'] );
$location = sanitize_text_field( $_POST['location'] );
// add new user
$user_id = wp_create_user( $username, $pasword, $email );
$user_id_role = new WP_User($user_id);
$user_id_role->location($location);

exit;


add_action( 'wp_ajax_addnewuser', 'addnewuser' );





function addnewuser() 
$username = sanitize_text_field( $_POST['username'] );
$pasword = sanitize_text_field( $_POST['password'] );
$email = sanitize_text_field( $_POST['email'] );
$location = sanitize_text_field( $_POST['location'] );
// add new user
$user_id = wp_create_user( $username, $pasword, $email );
$user_id_role = new WP_User($user_id);
$user_id_role->location($location);

exit;


add_action( 'wp_ajax_addnewuser', 'addnewuser' );






php jquery ajax wordpress post






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 8 at 9:36









MicMic

719




719







  • 4





    Please clarify what exactly is not working with the given code

    – Nico Haase
    Mar 8 at 9:38











  • Ajax posts to functions.php How ever nothing happens from there. User is not added to the wordpress install.

    – Mic
    Mar 8 at 9:40






  • 2





    So, what have you tried to debug the problem?

    – Nico Haase
    Mar 8 at 9:41











  • in my php, i have tried setting the username,password,email and location within the php, so it doesnt need the $_Post information and still nothing. Other then that. im not sure what else to try and debug it with.

    – Mic
    Mar 8 at 9:42






  • 1





    set up your error function of jquery ajax as well along with success and fail. see if you end up in error function

    – Gagan Deep
    Mar 8 at 9:50












  • 4





    Please clarify what exactly is not working with the given code

    – Nico Haase
    Mar 8 at 9:38











  • Ajax posts to functions.php How ever nothing happens from there. User is not added to the wordpress install.

    – Mic
    Mar 8 at 9:40






  • 2





    So, what have you tried to debug the problem?

    – Nico Haase
    Mar 8 at 9:41











  • in my php, i have tried setting the username,password,email and location within the php, so it doesnt need the $_Post information and still nothing. Other then that. im not sure what else to try and debug it with.

    – Mic
    Mar 8 at 9:42






  • 1





    set up your error function of jquery ajax as well along with success and fail. see if you end up in error function

    – Gagan Deep
    Mar 8 at 9:50







4




4





Please clarify what exactly is not working with the given code

– Nico Haase
Mar 8 at 9:38





Please clarify what exactly is not working with the given code

– Nico Haase
Mar 8 at 9:38













Ajax posts to functions.php How ever nothing happens from there. User is not added to the wordpress install.

– Mic
Mar 8 at 9:40





Ajax posts to functions.php How ever nothing happens from there. User is not added to the wordpress install.

– Mic
Mar 8 at 9:40




2




2





So, what have you tried to debug the problem?

– Nico Haase
Mar 8 at 9:41





So, what have you tried to debug the problem?

– Nico Haase
Mar 8 at 9:41













in my php, i have tried setting the username,password,email and location within the php, so it doesnt need the $_Post information and still nothing. Other then that. im not sure what else to try and debug it with.

– Mic
Mar 8 at 9:42





in my php, i have tried setting the username,password,email and location within the php, so it doesnt need the $_Post information and still nothing. Other then that. im not sure what else to try and debug it with.

– Mic
Mar 8 at 9:42




1




1





set up your error function of jquery ajax as well along with success and fail. see if you end up in error function

– Gagan Deep
Mar 8 at 9:50





set up your error function of jquery ajax as well along with success and fail. see if you end up in error function

– Gagan Deep
Mar 8 at 9:50












2 Answers
2






active

oldest

votes


















0














Use this in JS code



url: '<?php echo admin_url( "admin-ajax.php" ); ?>


Also you have used the wrong way to call ajax in wordpress
Use this method



 add_action( 'wp_ajax_addnewuser', 'addnewuser' );
add_action( 'wp_ajax_nopriv_addnewuser', 'addnewuser' );

function addnewuser()
$username = sanitize_text_field( $_POST['username'] );
$pasword = sanitize_text_field( $_POST['password'] );
$email = sanitize_text_field( $_POST['email'] );
$location = sanitize_text_field( $_POST['location'] );
// add new user
$user_id = wp_create_user( $username, $pasword, $email );
$user_id_role = new WP_User($user_id);
$user_id_role->location($location);

exit;






share|improve this answer

























  • thanks, didnt notice that. How ever its still not passing. im going to have to find another way of doing this.

    – Mic
    Mar 8 at 10:10











  • Did you try that? Takes 10 seconds to check that whether you have a space or not, it will still get the right element... Please don't post answers before being sure it will work and help OP.

    – MrUpsidown
    Mar 8 at 10:38












  • I did try it yes, How ever it didnt solve the issue. Im not sure what exactly is wrong with the setup i have. But its not adding any user.

    – Mic
    Mar 8 at 10:43











  • Did you have installed any membership plugin?

    – Ravi Kumar
    Mar 8 at 10:44











  • No, its a clean install of wordpress besides jquery How ever something intresting. I just tried adding the php to start on init with the username, password, email, and location set with "example" instead of pulling from post and it added the user correctly. weird.

    – Mic
    Mar 8 at 10:51


















0

















function user_profile_enqueue() 

// Register script for localization
wp_register_script (
'user-profile-mod',
get_template_directory_uri() . '/js/example.js',
array( 'jquery' ),
'1.0',
true
);

// Localize script so we can use $ajax_url
wp_localize_script (
'user-profile-mod',
'user_meta_ajax',
array(
'ajaxurl' => admin_url( 'admin-ajax.php' )
)
);



// Enqueue script
wp_enqueue_script( 'user-profile-mod' );


add_action( 'wp_enqueue_scripts', 'user_profile_enqueue' );





the poster above was correct. i needed to include admin-ajax.php,
But i went with it this way.






share|improve this answer






















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55060387%2fcant-add-user-from-front-end-with-php%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Use this in JS code



    url: '<?php echo admin_url( "admin-ajax.php" ); ?>


    Also you have used the wrong way to call ajax in wordpress
    Use this method



     add_action( 'wp_ajax_addnewuser', 'addnewuser' );
    add_action( 'wp_ajax_nopriv_addnewuser', 'addnewuser' );

    function addnewuser()
    $username = sanitize_text_field( $_POST['username'] );
    $pasword = sanitize_text_field( $_POST['password'] );
    $email = sanitize_text_field( $_POST['email'] );
    $location = sanitize_text_field( $_POST['location'] );
    // add new user
    $user_id = wp_create_user( $username, $pasword, $email );
    $user_id_role = new WP_User($user_id);
    $user_id_role->location($location);

    exit;






    share|improve this answer

























    • thanks, didnt notice that. How ever its still not passing. im going to have to find another way of doing this.

      – Mic
      Mar 8 at 10:10











    • Did you try that? Takes 10 seconds to check that whether you have a space or not, it will still get the right element... Please don't post answers before being sure it will work and help OP.

      – MrUpsidown
      Mar 8 at 10:38












    • I did try it yes, How ever it didnt solve the issue. Im not sure what exactly is wrong with the setup i have. But its not adding any user.

      – Mic
      Mar 8 at 10:43











    • Did you have installed any membership plugin?

      – Ravi Kumar
      Mar 8 at 10:44











    • No, its a clean install of wordpress besides jquery How ever something intresting. I just tried adding the php to start on init with the username, password, email, and location set with "example" instead of pulling from post and it added the user correctly. weird.

      – Mic
      Mar 8 at 10:51















    0














    Use this in JS code



    url: '<?php echo admin_url( "admin-ajax.php" ); ?>


    Also you have used the wrong way to call ajax in wordpress
    Use this method



     add_action( 'wp_ajax_addnewuser', 'addnewuser' );
    add_action( 'wp_ajax_nopriv_addnewuser', 'addnewuser' );

    function addnewuser()
    $username = sanitize_text_field( $_POST['username'] );
    $pasword = sanitize_text_field( $_POST['password'] );
    $email = sanitize_text_field( $_POST['email'] );
    $location = sanitize_text_field( $_POST['location'] );
    // add new user
    $user_id = wp_create_user( $username, $pasword, $email );
    $user_id_role = new WP_User($user_id);
    $user_id_role->location($location);

    exit;






    share|improve this answer

























    • thanks, didnt notice that. How ever its still not passing. im going to have to find another way of doing this.

      – Mic
      Mar 8 at 10:10











    • Did you try that? Takes 10 seconds to check that whether you have a space or not, it will still get the right element... Please don't post answers before being sure it will work and help OP.

      – MrUpsidown
      Mar 8 at 10:38












    • I did try it yes, How ever it didnt solve the issue. Im not sure what exactly is wrong with the setup i have. But its not adding any user.

      – Mic
      Mar 8 at 10:43











    • Did you have installed any membership plugin?

      – Ravi Kumar
      Mar 8 at 10:44











    • No, its a clean install of wordpress besides jquery How ever something intresting. I just tried adding the php to start on init with the username, password, email, and location set with "example" instead of pulling from post and it added the user correctly. weird.

      – Mic
      Mar 8 at 10:51













    0












    0








    0







    Use this in JS code



    url: '<?php echo admin_url( "admin-ajax.php" ); ?>


    Also you have used the wrong way to call ajax in wordpress
    Use this method



     add_action( 'wp_ajax_addnewuser', 'addnewuser' );
    add_action( 'wp_ajax_nopriv_addnewuser', 'addnewuser' );

    function addnewuser()
    $username = sanitize_text_field( $_POST['username'] );
    $pasword = sanitize_text_field( $_POST['password'] );
    $email = sanitize_text_field( $_POST['email'] );
    $location = sanitize_text_field( $_POST['location'] );
    // add new user
    $user_id = wp_create_user( $username, $pasword, $email );
    $user_id_role = new WP_User($user_id);
    $user_id_role->location($location);

    exit;






    share|improve this answer















    Use this in JS code



    url: '<?php echo admin_url( "admin-ajax.php" ); ?>


    Also you have used the wrong way to call ajax in wordpress
    Use this method



     add_action( 'wp_ajax_addnewuser', 'addnewuser' );
    add_action( 'wp_ajax_nopriv_addnewuser', 'addnewuser' );

    function addnewuser()
    $username = sanitize_text_field( $_POST['username'] );
    $pasword = sanitize_text_field( $_POST['password'] );
    $email = sanitize_text_field( $_POST['email'] );
    $location = sanitize_text_field( $_POST['location'] );
    // add new user
    $user_id = wp_create_user( $username, $pasword, $email );
    $user_id_role = new WP_User($user_id);
    $user_id_role->location($location);

    exit;







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Mar 8 at 11:08

























    answered Mar 8 at 10:08









    Ravi KumarRavi Kumar

    31329




    31329












    • thanks, didnt notice that. How ever its still not passing. im going to have to find another way of doing this.

      – Mic
      Mar 8 at 10:10











    • Did you try that? Takes 10 seconds to check that whether you have a space or not, it will still get the right element... Please don't post answers before being sure it will work and help OP.

      – MrUpsidown
      Mar 8 at 10:38












    • I did try it yes, How ever it didnt solve the issue. Im not sure what exactly is wrong with the setup i have. But its not adding any user.

      – Mic
      Mar 8 at 10:43











    • Did you have installed any membership plugin?

      – Ravi Kumar
      Mar 8 at 10:44











    • No, its a clean install of wordpress besides jquery How ever something intresting. I just tried adding the php to start on init with the username, password, email, and location set with "example" instead of pulling from post and it added the user correctly. weird.

      – Mic
      Mar 8 at 10:51

















    • thanks, didnt notice that. How ever its still not passing. im going to have to find another way of doing this.

      – Mic
      Mar 8 at 10:10











    • Did you try that? Takes 10 seconds to check that whether you have a space or not, it will still get the right element... Please don't post answers before being sure it will work and help OP.

      – MrUpsidown
      Mar 8 at 10:38












    • I did try it yes, How ever it didnt solve the issue. Im not sure what exactly is wrong with the setup i have. But its not adding any user.

      – Mic
      Mar 8 at 10:43











    • Did you have installed any membership plugin?

      – Ravi Kumar
      Mar 8 at 10:44











    • No, its a clean install of wordpress besides jquery How ever something intresting. I just tried adding the php to start on init with the username, password, email, and location set with "example" instead of pulling from post and it added the user correctly. weird.

      – Mic
      Mar 8 at 10:51
















    thanks, didnt notice that. How ever its still not passing. im going to have to find another way of doing this.

    – Mic
    Mar 8 at 10:10





    thanks, didnt notice that. How ever its still not passing. im going to have to find another way of doing this.

    – Mic
    Mar 8 at 10:10













    Did you try that? Takes 10 seconds to check that whether you have a space or not, it will still get the right element... Please don't post answers before being sure it will work and help OP.

    – MrUpsidown
    Mar 8 at 10:38






    Did you try that? Takes 10 seconds to check that whether you have a space or not, it will still get the right element... Please don't post answers before being sure it will work and help OP.

    – MrUpsidown
    Mar 8 at 10:38














    I did try it yes, How ever it didnt solve the issue. Im not sure what exactly is wrong with the setup i have. But its not adding any user.

    – Mic
    Mar 8 at 10:43





    I did try it yes, How ever it didnt solve the issue. Im not sure what exactly is wrong with the setup i have. But its not adding any user.

    – Mic
    Mar 8 at 10:43













    Did you have installed any membership plugin?

    – Ravi Kumar
    Mar 8 at 10:44





    Did you have installed any membership plugin?

    – Ravi Kumar
    Mar 8 at 10:44













    No, its a clean install of wordpress besides jquery How ever something intresting. I just tried adding the php to start on init with the username, password, email, and location set with "example" instead of pulling from post and it added the user correctly. weird.

    – Mic
    Mar 8 at 10:51





    No, its a clean install of wordpress besides jquery How ever something intresting. I just tried adding the php to start on init with the username, password, email, and location set with "example" instead of pulling from post and it added the user correctly. weird.

    – Mic
    Mar 8 at 10:51













    0

















    function user_profile_enqueue() 

    // Register script for localization
    wp_register_script (
    'user-profile-mod',
    get_template_directory_uri() . '/js/example.js',
    array( 'jquery' ),
    '1.0',
    true
    );

    // Localize script so we can use $ajax_url
    wp_localize_script (
    'user-profile-mod',
    'user_meta_ajax',
    array(
    'ajaxurl' => admin_url( 'admin-ajax.php' )
    )
    );



    // Enqueue script
    wp_enqueue_script( 'user-profile-mod' );


    add_action( 'wp_enqueue_scripts', 'user_profile_enqueue' );





    the poster above was correct. i needed to include admin-ajax.php,
    But i went with it this way.






    share|improve this answer



























      0

















      function user_profile_enqueue() 

      // Register script for localization
      wp_register_script (
      'user-profile-mod',
      get_template_directory_uri() . '/js/example.js',
      array( 'jquery' ),
      '1.0',
      true
      );

      // Localize script so we can use $ajax_url
      wp_localize_script (
      'user-profile-mod',
      'user_meta_ajax',
      array(
      'ajaxurl' => admin_url( 'admin-ajax.php' )
      )
      );



      // Enqueue script
      wp_enqueue_script( 'user-profile-mod' );


      add_action( 'wp_enqueue_scripts', 'user_profile_enqueue' );





      the poster above was correct. i needed to include admin-ajax.php,
      But i went with it this way.






      share|improve this answer

























        0












        0








        0










        function user_profile_enqueue() 

        // Register script for localization
        wp_register_script (
        'user-profile-mod',
        get_template_directory_uri() . '/js/example.js',
        array( 'jquery' ),
        '1.0',
        true
        );

        // Localize script so we can use $ajax_url
        wp_localize_script (
        'user-profile-mod',
        'user_meta_ajax',
        array(
        'ajaxurl' => admin_url( 'admin-ajax.php' )
        )
        );



        // Enqueue script
        wp_enqueue_script( 'user-profile-mod' );


        add_action( 'wp_enqueue_scripts', 'user_profile_enqueue' );





        the poster above was correct. i needed to include admin-ajax.php,
        But i went with it this way.






        share|improve this answer
















        function user_profile_enqueue() 

        // Register script for localization
        wp_register_script (
        'user-profile-mod',
        get_template_directory_uri() . '/js/example.js',
        array( 'jquery' ),
        '1.0',
        true
        );

        // Localize script so we can use $ajax_url
        wp_localize_script (
        'user-profile-mod',
        'user_meta_ajax',
        array(
        'ajaxurl' => admin_url( 'admin-ajax.php' )
        )
        );



        // Enqueue script
        wp_enqueue_script( 'user-profile-mod' );


        add_action( 'wp_enqueue_scripts', 'user_profile_enqueue' );





        the poster above was correct. i needed to include admin-ajax.php,
        But i went with it this way.






        function user_profile_enqueue() 

        // Register script for localization
        wp_register_script (
        'user-profile-mod',
        get_template_directory_uri() . '/js/example.js',
        array( 'jquery' ),
        '1.0',
        true
        );

        // Localize script so we can use $ajax_url
        wp_localize_script (
        'user-profile-mod',
        'user_meta_ajax',
        array(
        'ajaxurl' => admin_url( 'admin-ajax.php' )
        )
        );



        // Enqueue script
        wp_enqueue_script( 'user-profile-mod' );


        add_action( 'wp_enqueue_scripts', 'user_profile_enqueue' );





        function user_profile_enqueue() 

        // Register script for localization
        wp_register_script (
        'user-profile-mod',
        get_template_directory_uri() . '/js/example.js',
        array( 'jquery' ),
        '1.0',
        true
        );

        // Localize script so we can use $ajax_url
        wp_localize_script (
        'user-profile-mod',
        'user_meta_ajax',
        array(
        'ajaxurl' => admin_url( 'admin-ajax.php' )
        )
        );



        // Enqueue script
        wp_enqueue_script( 'user-profile-mod' );


        add_action( 'wp_enqueue_scripts', 'user_profile_enqueue' );






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 8 at 11:26









        MicMic

        719




        719



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55060387%2fcant-add-user-from-front-end-with-php%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

            Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

            2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived