Skip to content

Instantly share code, notes, and snippets.

@janssens
Created July 12, 2017 17:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janssens/e7f0f49c4041507fdc7889d83d2c1f6b to your computer and use it in GitHub Desktop.
Save janssens/e7f0f49c4041507fdc7889d83d2c1f6b to your computer and use it in GitHub Desktop.
create admin user magento 1
<?php
# Create New admin User programmatically.
require_once('./app/Mage.php');
umask(0);
Mage::app();
try {
$user = Mage::getModel('admin/user')
->setData(array('username' => 'my_username',
'firstname' => 'my_firstname',
'lastname' => 'my_lastname',
'email' => 'my_email@plopcom.fr',
'password' => 'myPass',
'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