How to create a new hook?


NextCloud documentation presents some hooks on the following page:

However, I strongly suspect these are not all hooks. Or, that it is possible to define new hooks.

In my case, I want to capture the update account action (change name, email, address, etc), in order to save user data on an LDAP base. Is it possible to do this?

I was wondering about the possibility of capturing the ajax call , which is this case is a PUT call to /index.php/settings/users/{uid}/settings.

I would be gratefull if someone could point me out a way of solving this.

By the way, this is part of the, which can already be used to reflect NextCloud user management actions on an LDAP base.


There is the following hook triggered:

\OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value));

feature is displayName or eMailAddress value the given name.

To listen to the hook just register with:

\OCP\Util::connectHook('OC_User', 'changeUser', 'YourClassName', 'methodToCall');

just add that code into your appinfo/app.php

Thanks a lot, Nick!

I’ll also add it to the documentation!

Hi Nick and everybody,

The above answer solves the issue regarding only email and displayName, which appear to be “first class” parameters. However, what I really wanted was to have access to the other parameters, particularly the address.

Is there any hook for that?

EDIT: I opened a new topic for this.