Skip to content

Instantly share code, notes, and snippets.

@alana-mullen
Created March 20, 2018 16:43
Show Gist options
  • Save alana-mullen/4099feea88d635ded977809ab7b69e4d to your computer and use it in GitHub Desktop.
Save alana-mullen/4099feea88d635ded977809ab7b69e4d to your computer and use it in GitHub Desktop.
Create new Magento admin user programmatically. Edit and add the php file below to the root of your Magento folder. Run it in the browser and the user will be created.
<?php
# Create new Magento admin user programmatically.
require_once('./app/Mage.php');
umask(0);
Mage::app();
try {
$user = Mage::getModel('admin/user')
->setData(array(
'username' => 'admin1',
'firstname' => 'Admin',
'lastname' => 'Admin',
'email' => '[email protected]',
'password' => 'admin123',
'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