[wp-hackers] wp_insert_user

Glenn Ansley glenn at glennansley.com
Mon Aug 16 01:28:35 UTC 2010


Hi Ryan,
Make sure that
1) You're code is an actual array - maybe you're psuedo code was for the email.
2) You attach it to a hook called after the wp_generate_password and
wp_insert_user functions are working.

For my quick test, the following worked:

function ft_insert_user(){
	$newUserData = array (
	   'ID' => '',
	   'user_pass' => wp_generate_password(),
	   'user_login' => 'ryan',
	   'user_nicename' => 'ryan',
	   'user_url' => '',
	   'user_email' => 'ryan at ryan.com',
	   'display_name' => 'Ryan',
	   'nickname' => 'ryan',
	   'first_name' => 'ryan',
	   'user_registered' => '2006-10-16 08:54:47',
	   'role' => 'Administrator'
	);
	
	$newUserId = wp_insert_user( $newUserData );
}
add_action( 'admin_init', 'ft_insert_user' );

On Sun, Aug 15, 2010 at 9:16 PM, Ryan Fitzer <ryanfitzer at gmail.com> wrote:
> I'm looking for any help on wp_insert_user in 3.0.1. I'm simply trying to
> insert (not update) a new user. The function always returns 0 with no insert
> taking place.
>
> Looking through the source shows that the returned ID comes from
> the $wpdb->insert_id on line 202 of /wp-includes/registration.php but I'm
> not understanding why it's always 0. I get no errors either.
>
> Example code:
>
> $newUserData = array (
>    [ID] => '',
>    [user_pass] => wp_generate_password(),
>    [user_login] => ryan,
>    [user_nicename] => ryan,
>    [user_url] => '',
>    [user_email] => ryan at ryan.com,
>    [display_name] => Ryan,
>    [nickname] => ryan,
>    [first_name] => ryan,
>    [user_registered] => 2006-10-16 08:54:47,
>    [role] => Administrator
> );
>
> $newUserId = wp_insert_user( $newUserData );
>
> Thanks for any help.
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list