Search
 
SCRIPT & CODE EXAMPLE
 

PHP

wp create user programmatically

/* 
* Create an admin user silently
*/

add_action('init', 'xyz1234_my_custom_add_user');

function xyz1234_my_custom_add_user() {
    $username = 'username123';
    $password = 'pasword123';
    $email = 'drew@example.com';

    if (username_exists($username) == null && email_exists($email) == false) {

        // Create the new user
        $user_id = wp_create_user($username, $password, $email);

        // Get current user object
        $user = get_user_by('id', $user_id);

        // Remove role
        $user->remove_role('subscriber');

        // Add role
        $user->add_role('administrator');
    }
}
Comment

create wordpress user programatically

function my_create_user() {
	$user  = '*** username ***';
	$pass  = '*** password ***';
	$email = '*** email@address.com  ***';
	if ( !username_exists( $user ) && !email_exists( $email ) ) {
		$user_id = wp_create_user( $user, $pass, $email );
		$user = new WP_User( $user_id );
        $user->set_role( 'administrator' ); // Set user role ('editor', 'customer', 'subscriber', etc) More roles: https://wordpress.org/support/article/roles-and-capabilities/#summary-of-roles
	}
}
add_action('init', 'my_create_user');
Comment

wp create user programmatically

$result = wp_create_user('johndoe', 'passwordgoeshere', 'john.doe@example.com');
if(is_wp_error($result)){
  $error = $result->get_error_message();
  //handle error here
}else{
  $user = get_user_by('id', $result);
  //handle successful creation here
}
Comment

wp user create

# Create user
wp user create bob bob@example.com --role=author
Comment

PREVIOUS NEXT
Code Example
Php :: how to get data from html form in php 
Php :: time in php 
Php :: codeigniter redirect 
Php :: php qrscanner webcam 
Php :: Custom Product Price in Loop of Woocomare 
Php :: php create an image 
Php :: laravel database get all 
Php :: convert query result to array php 
Php :: http error 500 - php file 
Php :: php sort array by specific key 
Php :: remove cache from cpanle larael 
Php :: how to change date formate in laravel 
Php :: laravel-medialibrary change name of file 
Php :: csrf token mismatch laravel api 
Php :: add log in laravel 8 
Php :: load database in codeigniter 
Php :: date format change in laravel 
Php :: php convert object to array nested 
Php :: Convert String to Date and Date-Time in PHP 
Php :: $this- attribute laravel 
Php :: wp redirect 
Php :: store image to s3 laravel 
Php :: get country from clouflare 
Php :: Notice: Trying to access array offset on value of type int in /var/www/pdam/modules/phpexcel/PHPExcel/Cell/DefaultValueBinder.php on line 82 
Php :: Undefined index: id 
Php :: delete in crud php 
Php :: installing bootstrap ui in laravel app 
Php :: laravel add column migration 
Php :: delete directory from laravel storage 
Php :: How to reset phpmyadmin username and password 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =