Modifying user settings and profile fields programmatically

I am writing a web service (Modifying create user web service ) to modify user settings ( name and password) and profile fields ( Interests and Location) . But it is not working as expected. Could somebody please help me?

1)    User settings :-
                             $ userObj ->name=’Modified Name’;
        $ userObj ->save();
            I printed $ userObj , it has values what I expected from database .   I tried even with entity, but that is also not working. 

2)    Profile Fields
      update_metadata ($userObj->guid, 'Interests', 'Dancing’, '', 0, ACCESS_PUBLIC);

Already ‘Interests‘value is defined .I am just trying to modify it. Even this one not working

Am I missing some basics?


  • whoops , no luck trying this and that ( users_settings_save and Set_userSettings ) , but no luck . Could sombody please give me a clue?




  • To change attributes on a user object, you need to have the proper permissions. What user is logged in through the web services to make this sort of change?

    Also, did you test the return value of save()?

  • Thanks Cash for your respnse . I am not logging as any user,  installed it as plugin and calling it from external application . Registration worked without any issues. I used the this one for registration . Same one changed for Modification and added as a plugin to the system and calling from external system to modify it . To make sure I called  get_loggedin_user()->username from the plugin and returned it . It just returned empty string .. and I tested the return value of the save() and even that is empty


    Thanks for helping me







  • save() returns false on failure and returns the GUID of the user on success

  • You can override the elgg permissions with the permission hooks.. It will help you save the data even if you are logged out.

  • Thanks Cash , Invsible  and Brett thanks for pointing me to hooks . But even I am failed here too . May be my understanding is wrong. Could you please advise ?

            register_plugin_hook('update_user', 'all', 'update_user_profile');
            trigger_plugin_hook('update_user','all', $values , false)

        function update_user_profile($hook_name, $entity_type, $return_value, $parameters) {
            $userObj->name='Testing Name';
            $savedObj=$userObj->save() ;

            return true;


  • Read the link that Brett added. You need to use the permissions hook system. The hook is fired when an object is saved and is used to determine whether permission should be granted to save the object.

    Why are you changing settings on a user without that user being logged in?

  • Hi Cash,

    Thanks for your response.  I am sorry may be I am confusing you.

    My case is I have two websites 1) PHP based website 2) Elgg based website. Both are on the same server.

    User enters and updates his information only in the first website and at elgg side user will not have update profile permissions that includes name, password, location, gender. So I am writing a web service at elgg end accessing the input data from the first website and updating it. Here there is no concept of user logged into Elgg or not. Whenever user updates information in the first website I want that information to be updated at Elgg end.

    Elgg userid and the first website userid both are same. First website calls my elgg website webservice and passes username and other profile information. After getting the information at elgg end , I am trying to get the object of user using Useried that I received in the call and trying to update it .

    Am I doing the right thing to update the information at elgg end? Or is there any other way?

    Thanks again for your time

  • I would log the user in programmatically to the Elgg site. All permissions go away then.