Last active
February 29, 2016 10:11
-
-
Save anishsheela/ce320bfba2626018acdf to your computer and use it in GitHub Desktop.
Programatically create user in Drupal 7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name = "Programatic user create" | |
description = "A sample module to create user programaticaly." | |
core = 7.x |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @file | |
* Programatically create user | |
*/ | |
/** | |
* Implements hook_menu() | |
*/ | |
function user_create_menu() { | |
$items['user_create'] = array( | |
'access callback' => TRUE, | |
'page callback' => 'user_create_new', | |
'type' => MENU_CALLBACK, | |
); | |
return $items; | |
} | |
/** | |
* Page callback to create new user | |
*/ | |
function user_create_new() { | |
require_once DRUPAL_ROOT . '/includes/password.inc'; | |
$account = new stdClass; | |
$account->is_new = TRUE; | |
$account->name = 'bar'; | |
$account->pass = user_hash_password('foo'); | |
$account->mail = 'foo@example.com'; | |
$account->init = 'foo@example.com'; | |
$account->status = TRUE; | |
$account->roles = array(DRUPAL_AUTHENTICATED_RID => TRUE); | |
$account->timezone = variable_get('date_default_timezone', ''); | |
user_save($account); | |
return array( | |
'#markup' => 'User Created' | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment