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



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

require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );

$app = JFactory::getApplication('site');

$params = array(

$udata = array(
    'groups'=>array(2), // set the usergroup(s) here (id)

$user = new JUser;

    echo '<pre>';
    echo 'Bind user data: ';

    echo 'Save user data: ';

    //echo 'Testing login: ';
    //var_dump( $app->login( array('username'=>$params['username'],'password'=>$params['password']) ) );

} catch (Exception $ex) {

    echo 'Exception: ',  $e->getMessage(), '\n';


Frontend language field is called language, not frontend-language. It also doesn't have its own column in the database. Instead it's JSON-encoded with other params and stored to params column.

Remove frontend-language element from $udata and instead add params array with language as key and selected language as value:

$udata = array(
    'name' => $params['name'],
    'username' => $params['username'],
    'password' => $params['password'],
    'email' => $params['email'],
    'groups' => array(2), // set the usergroup(s) here (id)
    'params' => array('language' => $params['frontend-language']),

Alternatively, you can use JUser::setParam() to set param values:

$user = new JUser;
$user->setParam('language', 'de-DE');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.