Discussion:
Check to see if there a wordpress user account and create one if not outside of wordpress
Daniel
2013-11-17 22:34:54 UTC
Permalink
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
Alex Rayan
2013-11-17 23:55:40 UTC
Permalink
Hi Daniel,

I'm sorry I don't have time to go through your whole script, but to check
whether the user exists you can use:
if( !email_exists( $email )) {
}
and to pass email that you would like to check against.
Then if the email is not found in the database, you can create a new user
account as follows:

$args = array(
'user_pass'=>$plain_text_pass,
'user_login'=>$username,
'user_nicename'=>$url_friendly_name,
'user_email'=>$user_email,
'display_name'=>$display_name
);
$user_id = wp_insert_user($args);

You can check a full list of arguments that you can pass here:
http://codex.wordpress.org/Function_Reference/wp_insert_user

Also, it's probably a good idea to check for username_exists before passing
a username in case that one is already taken. Then, you could, for example,
append a number at the end of the username.

On success the function above returns user_id.

Hope it helps.

Best regards,
Alex
Post by Daniel
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
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Daniel
2013-11-18 00:08:38 UTC
Permalink
Hi Alex,

Thank-you for getting back to me, now I take it that I should be able
to use the script that you provided (I know that it need some editing)
after I done the usual "include '/../../../wp-load.php';"?

Also what should I do if the password is not in plain text? (I'm not
entirely sure if the "$password" is still alive at that point of the
script, it's going right after someone logged into phpbb, I will need
to check on that)

Having said that I will give it a go and see how I go :)

Thank-you again Alex :)

Regards,
Daniel
Post by Alex Rayan
Hi Daniel,
I'm sorry I don't have time to go through your whole script, but to check
if( !email_exists( $email )) {
}
and to pass email that you would like to check against.
Then if the email is not found in the database, you can create a new user
$args = array(
'user_pass'=>$plain_text_pass,
'user_login'=>$username,
'user_nicename'=>$url_friendly_name,
'user_email'=>$user_email,
'display_name'=>$display_name
);
$user_id = wp_insert_user($args);
http://codex.wordpress.org/Function_Reference/wp_insert_user
Also, it's probably a good idea to check for username_exists before passing
a username in case that one is already taken. Then, you could, for example,
append a number at the end of the username.
On success the function above returns user_id.
Hope it helps.
Best regards,
Alex
Post by Daniel
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
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Alex Rayan
2013-11-18 14:52:54 UTC
Permalink
Hi Danial,

Yes, in order to user wordpress core functions you would need to include
wp-load.php or call your script from within a custom wordpress template
page, for example.
If the password is not a plain text, you could generate a random password
and ask a user to update it after. wp_insert_user only accepts a plain text
password since it applies required hashing on it after.

Hope it worked for you. : )

Best regards,
Alex
Post by Daniel
Hi Alex,
Thank-you for getting back to me, now I take it that I should be able
to use the script that you provided (I know that it need some editing)
after I done the usual "include '/../../../wp-load.php';"?
Also what should I do if the password is not in plain text? (I'm not
entirely sure if the "$password" is still alive at that point of the
script, it's going right after someone logged into phpbb, I will need
to check on that)
Having said that I will give it a go and see how I go :)
Thank-you again Alex :)
Regards,
Daniel
Post by Alex Rayan
Hi Daniel,
I'm sorry I don't have time to go through your whole script, but to check
if( !email_exists( $email )) {
}
and to pass email that you would like to check against.
Then if the email is not found in the database, you can create a new user
$args = array(
'user_pass'=>$plain_text_pass,
'user_login'=>$username,
'user_nicename'=>$url_friendly_name,
'user_email'=>$user_email,
'display_name'=>$display_name
);
$user_id = wp_insert_user($args);
http://codex.wordpress.org/Function_Reference/wp_insert_user
Also, it's probably a good idea to check for username_exists before
passing
Post by Alex Rayan
a username in case that one is already taken. Then, you could, for
example,
Post by Alex Rayan
append a number at the end of the username.
On success the function above returns user_id.
Hope it helps.
Best regards,
Alex
Post by Daniel
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
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Daniel
2013-11-18 23:36:52 UTC
Permalink
Hi Alex,

I managed to get 95% of what I'm after going, the other 5% is info
that I'm trying to pull from phpBB and I'm going to ask over there
because it looks like an issue on phpBB and not WordPress side.

Alex please let me know how you want me to credit you (Got a website?)
and I'll do that right away.

Thank-you :)

Daniel
Post by Alex Rayan
Hi Danial,
Yes, in order to user wordpress core functions you would need to include
wp-load.php or call your script from within a custom wordpress template
page, for example.
If the password is not a plain text, you could generate a random password
and ask a user to update it after. wp_insert_user only accepts a plain text
password since it applies required hashing on it after.
Hope it worked for you. : )
Best regards,
Alex
Post by Daniel
Hi Alex,
Thank-you for getting back to me, now I take it that I should be able
to use the script that you provided (I know that it need some editing)
after I done the usual "include '/../../../wp-load.php';"?
Also what should I do if the password is not in plain text? (I'm not
entirely sure if the "$password" is still alive at that point of the
script, it's going right after someone logged into phpbb, I will need
to check on that)
Having said that I will give it a go and see how I go :)
Thank-you again Alex :)
Regards,
Daniel
Post by Alex Rayan
Hi Daniel,
I'm sorry I don't have time to go through your whole script, but to check
if( !email_exists( $email )) {
}
and to pass email that you would like to check against.
Then if the email is not found in the database, you can create a new user
$args = array(
'user_pass'=>$plain_text_pass,
'user_login'=>$username,
'user_nicename'=>$url_friendly_name,
'user_email'=>$user_email,
'display_name'=>$display_name
);
$user_id = wp_insert_user($args);
http://codex.wordpress.org/Function_Reference/wp_insert_user
Also, it's probably a good idea to check for username_exists before
passing
Post by Alex Rayan
a username in case that one is already taken. Then, you could, for
example,
Post by Alex Rayan
append a number at the end of the username.
On success the function above returns user_id.
Hope it helps.
Best regards,
Alex
Post by Daniel
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
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Alex Rayan
2013-11-19 14:34:35 UTC
Permalink
Hi Daniel,

Glad to hear you progressed with your task. No need to credit me. It's an
open community to share knowledge.

Best regards,
Alex
Post by Daniel
Hi Alex,
I managed to get 95% of what I'm after going, the other 5% is info
that I'm trying to pull from phpBB and I'm going to ask over there
because it looks like an issue on phpBB and not WordPress side.
Alex please let me know how you want me to credit you (Got a website?)
and I'll do that right away.
Thank-you :)
Daniel
Post by Alex Rayan
Hi Danial,
Yes, in order to user wordpress core functions you would need to include
wp-load.php or call your script from within a custom wordpress template
page, for example.
If the password is not a plain text, you could generate a random password
and ask a user to update it after. wp_insert_user only accepts a plain
text
Post by Alex Rayan
password since it applies required hashing on it after.
Hope it worked for you. : )
Best regards,
Alex
Post by Daniel
Hi Alex,
Thank-you for getting back to me, now I take it that I should be able
to use the script that you provided (I know that it need some editing)
after I done the usual "include '/../../../wp-load.php';"?
Also what should I do if the password is not in plain text? (I'm not
entirely sure if the "$password" is still alive at that point of the
script, it's going right after someone logged into phpbb, I will need
to check on that)
Having said that I will give it a go and see how I go :)
Thank-you again Alex :)
Regards,
Daniel
Post by Alex Rayan
Hi Daniel,
I'm sorry I don't have time to go through your whole script, but to
check
Post by Alex Rayan
Post by Daniel
Post by Alex Rayan
if( !email_exists( $email )) {
}
and to pass email that you would like to check against.
Then if the email is not found in the database, you can create a new
user
Post by Alex Rayan
Post by Daniel
Post by Alex Rayan
$args = array(
'user_pass'=>$plain_text_pass,
'user_login'=>$username,
'user_nicename'=>$url_friendly_name,
'user_email'=>$user_email,
'display_name'=>$display_name
);
$user_id = wp_insert_user($args);
http://codex.wordpress.org/Function_Reference/wp_insert_user
Also, it's probably a good idea to check for username_exists before
passing
Post by Alex Rayan
a username in case that one is already taken. Then, you could, for
example,
Post by Alex Rayan
append a number at the end of the username.
On success the function above returns user_id.
Hope it helps.
Best regards,
Alex
Post by Daniel
Hi guys,
Just wondering, does anyone know how I can go about checking to see
if
Post by Alex Rayan
Post by Daniel
Post by Alex Rayan
Post by Daniel
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
Post by Alex Rayan
Post by Daniel
Post by Alex Rayan
Post by Daniel
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
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Continue reading on narkive:
Loading...