1

I have the workflow thought out:

  • User pays for something on your site using e-junkie.

  • After payment, a http post ( with user email and name gets sent to a wordpress registration script ) and registers that user automatically -- ignores if the email is in database

I think we can use the wp-register.php page for hacking! The problem I am having is having this run automatically.

I already have the option in e-junkie to send an http post after payment with (POST variables to use) automatically -- but now I am not sure how to do the WordPress registration part (automatically)

Post variables from e-junkie:

payer_email Buyer's email address
first_name Buyer's first name
last_name Buyer's last name

Thanks in advance!!

EDIT:

So, here is some code I came up with -- It works, but now I need it to send the username and password it generated to that email address automatically ?? Also the first and last name isn't recording ?? Thanks!!

require('wordpress/wp-blog-header.php');

$user_email = trim(isset($_POST['payer_email']) ? $_POST['payer_email'] : "");
$user_name = trim(isset($_POST['first_name']) ? $_POST['first_name'] : "");

$user_id = username_exists( $user_name );
if ( !$user_id ) {
    $random_password = wp_generate_password( 12, false );
    $user_id = wp_create_user( $user_name, $random_password, $user_email );
} else {
    $random_password = __('User already exists.  Password inherited.');
}
0

1 Answer 1

3

How about using wp_create_user() and then add_user_meta()? Between those two, you should be able to store all the data you get back, and even store it in fields wordpress uses natively.

2
  • Great comment. So for code sake, how would you organize it with variables and such??
    – eberswine
    Jan 27, 2012 at 23:06
  • Depends how the data comes in, but basically grab the payer_email and then MD5 hash (or something) that for the username. Randomly generate a password and run that all into wp_create_user() then put the first and last name in as usermeta (create_user will return the id of the created user)...you'll needa grub around in profile.php a bit and see what the usermeta name they're pulling for first and last name is, but that should be cake.
    – mor7ifer
    Jan 27, 2012 at 23:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.