how to add wordpress user from external remote form

815 Views Asked by At

i have two websites, websiteA is a worpdress website, and websiteB is a simple php website. i want to link the two website. i have a form in websiteB and i want it to be able to add users in websiteA. i already tried the code below , it creates user but redirect to websiteA while i am in websiteB:

<form name="myForm" action="http://ipSiteA/wp-admin/user-new.php" method="post">

<input type="hidden" name="action" value="createuser">
<input type="hidden" name="user_login" value="test">
<input type="hidden" name="email" value="[email protected]">
<input type="hidden" name="pass1" value="test">
<input type="hidden" name="pass2" value="test">
<input type="hidden" name="role" value="seller">
<input type="hidden" name="createuser" value="Ajouter un utilisateur">
<input type="hidden" name="_wpnonce_create-user" value="815389c6d9">
<input type="hidden" name="_wp_http_referer" value="/wp-admin/user-new.php">
<input type="submit" name="create" value="Creer">

is there any other solution using remote apli for example? if not, is there a way to not be redirected to websiteA? thanks

1

There are 1 best solutions below

3
On

You can set up a hook on the registration method on the site, where you need it. Open your functions.php in your websiteB. This is in your theme directory. If there is no file like this, create one.

Put this into that file:

add_action('register_form', 'my_register_form');
function my_register_form() {
    //Redirects the user to an URL
    header("Location: http://example.com/");
    die();
}

Of course, you need to write your URL instead of the example.com.

Here is the referenc of the register_form action.