function wpmu_create_user( $user_name, $password, $email) {}

Create a user.
This function runs when a user self-registers as well as when a Super Admin creates a new user. Hook to ‘wpmu_new_user’ for events that should affect all new users, but only on Multisite (otherwise use ‘user_register’).


  • string $user_name: The new user’s login name.
  • string $password: The new user’s password.
  • string $email: The new user’s email address.

Return values

returns:Returns false on failure, or int $user_id on success

Defined actions

  • wpmu_new_user
    do_action( 'wpmu_new_user', $user_id );

Source code

function wpmu_create_user( $user_name, $password, $email) {

	$user_name = preg_replace( '/\s+/', '', sanitize_user( $user_name, true ) );

	$user_id = wp_create_user( $user_name, $password, $email );

	if ( is_wp_error($user_id) )

		return false;

	// Newly created users have no roles or caps until they are added to a blog.

	delete_user_option( $user_id, 'capabilities' );

	delete_user_option( $user_id, 'user_level' );

	do_action( 'wpmu_new_user', $user_id );

	return $user_id;



No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: