The code below (modified from another post) works fine for me to create a user. But how do you set the new user's frontend language? In the code below, the lines
'frontend-language'=>'de-DE',
'frontend-language'=>$params['frontend-language'],
are how I've unsuccessfully tried to achieve it.
define( '_JEXEC', 1 );
define('JPATH_BASE', dirname(__FILE__) );//this is when we are in the root
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
$app = JFactory::getApplication('site');
$app->initialise();
$params = array(
'name'=>'test1',
'username'=>'test1_user',
'email'=>'mailtest1@example.com',
'password'=>'test',
'frontend-language'=>'de-DE',
);
$udata = array(
'name'=>$params['name'],
'username'=>$params['username'],
'password'=>$params['password'],
'email'=>$params['email'],
'groups'=>array(2), // set the usergroup(s) here (id)
'frontend-language'=>$params['frontend-language'],
);
$user = new JUser;
try{
echo '<pre>';
echo 'Bind user data: ';
var_dump($user->bind($udata));
echo 'Save user data: ';
var_dump($user->save());
//echo 'Testing login: ';
//var_dump( $app->login( array('username'=>$params['username'],'password'=>$params['password']) ) );
} catch (Exception $ex) {
echo 'Exception: ', $e->getMessage(), '\n';
}