Answers for "how to add new user to wp"

PHP
1

wordpress create user php

// ADD THIS TO YOUR FUNCTIONS.PHP FILE AND THEN RELOAD ANY PAGE
/////////////////////////////////////////////////////////////////

add_action( 'init', function () {				  
	// set username, password, and email address
  	$username = 'user';
	$password = 'password';
	$email_address = '[email protected]';

  	if ( ! username_exists( $username ) ) {
    	$user_id = wp_create_user( $username, $password, $email_address );
    	$user = new WP_User( $user_id );
    	// set the role (administrator, contributor, subscriber)
      	$user->set_role( 'administrator' );
  	}

} );
Posted by: Guest on October-17-2021
0

wp create user programmatically

$result = wp_create_user('johndoe', 'passwordgoeshere', '[email protected]');
if(is_wp_error($result)){
  $error = $result->get_error_message();
  //handle error here
}else{
  $user = get_user_by('id', $result);
  //handle successful creation here
}
Posted by: Guest on April-23-2021

Code answers related to "how to add new user to wp"

Browse Popular Code Answers by Language