Skip to content

Instantly share code, notes, and snippets.

@centerax
Created June 26, 2014 14:50
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save centerax/3654b3eb6290a82956e5 to your computer and use it in GitHub Desktop.
Save centerax/3654b3eb6290a82956e5 to your computer and use it in GitHub Desktop.
Create New Magento admin User programmatically
<?php
// Create New admin User programmatically.
require_once('./app/Mage.php');
umask(0);
Mage::app();
try {
$user = Mage::getModel('admin/user')
->setData(array(
'username' => 'admin',
'firstname' => 'Admin',
'lastname' => 'Admin',
'email' => 'hola@example.com',
'password' => '3lP4ass3or$',
'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