Best way to create a user programatically
I want to create a user via a standalone script. I want an activation email to be sent out, in the same way that it is when a user is created from the Add User screen. An email is set out with a link to create the password. There is no password in the email.
There seem to be various functions for creating new users.
- wp_insert_user
- wp_create_user
- [register_new_user][3]
There's also
- wp-admin/user-new.php
Below is the code I have. It creates a new user, but it isn't the notification email. I've checked that wp-mail() and php mail() are working correctly.
I'm not sure that this is the right direction. I feel there might be an easier way to do it. If this is the right direction, any pointers on why the notification is not being sent?
Thanks.
?php
define( 'SHORTINIT', true );
require_once( '/var/www/html/mysite/wp-load.php' );
require_once ('/var/www/html/mysite/wp-includes/user.php');
require_once ('/var/www/html/mysite/wp-includes/formatting.php');
require_once ('/var/www/html/mysite/wp-includes/capabilities.php');
require_once ('/var/www/html/mysite/wp-includes/pluggable.php');
require_once ('/var/www/html/mysite/wp-includes/kses.php');
require_once ('/var/www/html/mysite/wp-includes/meta.php');
function __() {}
wp_create_user ( 'testuser8', 'apsswd', '[email protected]' );
wp_new_user_notification ( testuser8,null,'both' );
?
Topic wp-create-user scripts php email user-registration Wordpress
Category Web