I have an ipn script built works great. But i want to send the username, email, pass to my wordpress setup to create a user automatically. I have tried many examples online but all seem to fail or missing information on the properly needed require/include 's at the top for them to function properly.
Hey there lowridertj. i don't know what IPN script is however if i understand you correctly you are looking for a way to add users to WP automatically through code Right ?
If this is what you're looking for here is how the code should look like (php ofc) // You define an array with the user information you want to enter if i am not mistaken the required fields are Password, email, and user login everything else is pretty much optional $users = array( "user_pass" => "password", "user_login" => "UserLogIn", "user_nicename" => "someNickname", "user_email" => "userEmail@something.com", "user_url" => "something", "display_name" => "displayName", "nickname" => "nickname", "first_name" => "First Name", "last_name" => "Last Name", "description" => "" ); // Use wp_insert_user with the array you created to create the user. this will either return the id of the newly created user or false(if i am not mistaken) $someVariable = wp_insert_user( $user ); PHP: Hopes that helps. let me know if you have any more questions.
You should not include anything its a built in WP function. as long as you do the above within WP it will work with no problem however if you do this outside of wordpress on a custom script you'll have to do the following: // find the real path of your current location $fullpath = dirname(__FILE__); // if its in another folder you can change the full path to fit by doing something like: $fullpath = $fullpath.'/somefolder'; // you check if add_action which is a WP function exists if not then include wp-load.php. if (!function_exists('add_action')){ require_once ($fullpath.'/wp-load.php' ); } PHP:
For some reason the client site i was working on didnt allow me to call the files and execute the functions from another folder (location) so ended up using curl, and placed the create account settings in a file in the main root wordpress install. thank you for your help. it helped a lot.
> Create account file in root wordpress install (create.php) <?php global $duser,$dpass; require_once("user.php"); $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $payer_email = $_POST['payer_email']; $someVariable = createUser($first_name.$last_name,$payer_email); echo $someVariable; $message = "<html> <head><h1>Signup Detail</h1> </head> <body> <p>Signup Detail :</p> <p>Username : ".$duser."</p> <p>Password : ".$dpass."</p> <p>Payer Email : ".$payer_email."</p> <p></p> </body> </html>"; //$mail_To = "$payer_email"; $mail_To = $payer_email; $mail_Subject = "WP Signup Detail"; $mail_Body = $message; $headers = "Content-type: text/html; charset=utf-8 \r\n"; $headers .= "From: info@yoursite.com\r\n"; mail($mail_To, $mail_Subject, $mail_Body, $headers); ?> PHP: > curl script used outside the root wordpress install <?php /* CREATE WP USER */ //set POST variables $url = 'http://yoursite.com/create.php'; $fields = array( "first_name" => $custname, "last_name" => "", "payer_email" => $custemail, ); //url-ify the data for the POST foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; } rtrim($fields_string, '&'); //open connection $ch = curl_init(); //set the url, number of POST vars, POST data curl_setopt($ch,CURLOPT_URL, $url); curl_setopt($ch,CURLOPT_POST, count($fields)); curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string); //execute post $result = curl_exec($ch); //close connection curl_close($ch); ?> PHP: