Manual:Hooks/LocalUserCreated

From MediaWiki.org
Jump to navigation Jump to search
LocalUserCreated
Available from version 1.26.0
Called immediately after a local user has been created and saved to the database
Define function:
public static function onLocalUserCreated( $user, $autocreated ) { ... }
Attach hook:

In extension.json:

{
	"Hooks": {
		"LocalUserCreated": "MyExtensionHooks::onLocalUserCreated"
	}
}

For MediaWiki ≤1.25:

$wgHooks['LocalUserCreated'][] = 'MyExtensionHooks::onLocalUserCreated';
Called from:File(s): AuthManager.php, AuthManagerAuthPlugin.php, AuthPluginPrimaryAuthenticationProvider.php

For more information about attaching hooks, see Manual:Hooks.
For examples of extensions using this hook, see Category:LocalUserCreated extensions.

Details[edit]

  • $user: User object for the created user
  • $autocreated: Boolean, whether this was an auto-creation. Note if your wiki uses CentralAuth this will always be true.

Notes[edit]

Added in MediaWiki 1.26 as part of the upcoming AuthManager system. Replaces the AuthPlugin::initUser() method call and the AddNewAccount and AuthPluginAutoCreate hooks.

Extensions which implement their own authentication provider might want to use AuthManager::autoCreatedAccount and AuthManager::postAccountCreation instead, which are similar but have access to more information. (Note that postAccountCreation is called significantly later in the process, after secondary authentication providers have finished.)

Changes which are not immediately required for database consistency should probably be deferred; see Database transactions.

See also[edit]