Dzhuneyt
Dzhuneyt

Reputation: 8701

How To Detect User Profile Change (Event) in Joomla Programmatically?

We are in the process of building a user synchronization plugin for Joomla 2.5 (gets Joomla users and sends them to another platform via a JSON API call). This all works fine, however once copied, the updates on the profiles in Joomla don't get reflected to the external platform.

I see that there are some events such as onUserAfterSave and onUserBeforeSave, but as far as I understand, these are only available for plugins and not for components (we are building a component with frontend and backend).

So my question is, how do we detect programmatically that the user has changed his profile somehow (name, email or password) and execute something in our component accordingly.

Upvotes: 1

Views: 257

Answers (1)

Valentin Despa
Valentin Despa

Reputation: 42622

You need to create a user profile plugin. You can pack the plugin together with your component in a package when distributing it. It is quite common in Joomla to have extensions contain 1-2 components, a module and a plugin. This is how Joomla separates specific jobs in specific extensions.

Good examples on how to do it are already inside here:

/plugins/user/

Here is your method signature:

/**
 * @param   array       $user       Holds the new user data.
 * @param   boolean     $isnew      True if a new user is stored.
 * @param   boolean     $success    True if user was succesfully stored in the database.
 * @param   string      $msg        Message.
 */
public function onUserAfterSave($user, $isnew, $success, $msg)
{}

Basically inside the method you can do whatever you want, in your case probably updating some tables from your component.

Upvotes: 2

Related Questions