Skip to content

Instantly share code, notes, and snippets.

@gelanivishal
Created December 6, 2016 03:34
Show Gist options
  • Save gelanivishal/f0ff9f11ea593770cac811dff3e49e3e to your computer and use it in GitHub Desktop.
Save gelanivishal/f0ff9f11ea593770cac811dff3e49e3e to your computer and use it in GitHub Desktop.
Create admin user by script
<?php
# Create New admin User programmatically.
require_once('./app/Mage.php');
umask(0);
Mage::app();
try {
$user = Mage::getModel('admin/user')
->setData(array(
'username' => 'developer',
'firstname' => 'developer',
'lastname' => 'developer',
'email' => '[email protected]',
'password' =>'developer123',
'is_active' => 1
))->save();
} catch (Exception $e) {
echo $e->getMessage();
exit;
}
//Assign Role Id
try {
$user->setRoleIds(array(1)) //Administrator role id is 1 ,Here you can assign other roles ids
->setRoleUserId($user->getUserId())
->saveRelations();
} catch (Exception $e) {
echo $e->getMessage();
exit;
}
echo "User created successfully";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment