Skip to content

Instantly share code, notes, and snippets.

@litzinger
Created June 4, 2015 16:57
Show Gist options
  • Save litzinger/48be5876d6bba1509323 to your computer and use it in GitHub Desktop.
Save litzinger/48be5876d6bba1509323 to your computer and use it in GitHub Desktop.
Create a Magento user via PHP script to get into admin area.
<?php
define( 'USERNAME', 'new.user' );
define( 'PASSWORD', 'password' );
define( 'FIRSTNAME', 'Excited' );
define( 'LASTNAME', 'Croc' );
define( 'EMAIL', '[email protected]' );
include_once( 'app/Mage.php' );
Mage::app( 'admin' );
try {
$adminUserModel = Mage::getModel( 'admin/user' );
$adminUserModel->setUsername( USERNAME )
->setFirstname( FIRSTNAME )
->setLastname( LASTNAME )
->setEmail( EMAIL )
->setNewPassword( PASSWORD )
->setPasswordConfirmation( PASSWORD )
->setIsActive( true )
->save();
$adminUserModel->setRoleIds( array( 1 ) )
->setRoleUserId( $adminUserModel->getUserId() )
->saveRelations();
echo 'User created.';
} catch( Exception $e ) {
echo $e->getMessage();
}
php -f create-magento-user.php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment