0

Please note that this was posted on wp-hackers mailing list.

Hi guys,

Just wondering, does anyone know how I can go about checking to see if there a wordpress account and create one if there isn't?

Script that I got: https://gist.github.com/Danielx64/7519092

There a marker in the file that has "// Somewhere here I want to put a check to see if there a wp account" What I want to happen there is that a check get done to see if there is a wordpress account and if there not, create one.

Does anyone know if it can be done?

PS, I don't need to worry about logging into wordpress as that will get taken care of by a different script. Also anyone who can help me out will also get credit in the source code and readme :)

Regards, Daniel

0

How are you searching for this user? Either way, this it the function you want to use, as it can look via ID, user_nicename, email and login.

e.g.:

$userEmail = $_GET['useremail'];
$field = 'email';
$user = get_user_by( $field, $userEmail );

if(!$user) {
    $newUserArgs = array(
        'user_login' => $_GET['userlogin'],
        'user_pass' => $_GET['hashedpass'],
        'user_email' => $_GET['useremail']
    );
    $user = wp_insert_user( $newUserArgs );
}

$user now has user in it. Either it found an existing one, or created one. As you can see I've assumed you are passing in userlogin, hashedpass and useremail from a form or such.

Hope this helps.

| improve this answer | |
  • As you said that you are looking to do this outside of wordpress, adding the following will allow you to access the wordpress functions; require('/var/www/path/to/httpdocs/wp-blog-header.php'); global $wpdb; – TomC Nov 18 '13 at 4:54
  • I managed to get what I'm after going, someone on wp-hackers given me a clean way of dealing with it. Code on github: gist.github.com/Danielx64/7519092 from 46 to 60 – Danielx64 Nov 19 '13 at 0:06
  • Daniel, thanks for the update. Maybe give us a link here so we can all see? – Nick M Nov 19 '13 at 0:07
  • Sure you can read up on it here, lists.automattic.com/pipermail/wp-hackers/2013-November/… that has the direct answer that I'm after. Please note that I did need to edit the script but it a very good starting point :) – Danielx64 Nov 19 '13 at 23:42

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.