Manual:Hooks/SaveUserOptions

SaveUserOptions
Available from version 1.37.0
Called just before saving user preferences. This hook replaces UserSaveOptions . Hook handlers can either add or manipulate options, or reset one back to its default to block changing it. Hook handlers are also allowed to abort the process by returning false, e.g. to save to a global profile instead. Compare to the UserSaveSettings hook, which is called after the preferences have been saved.
Define function:
public static function onSaveUserOptions( UserIdentity $user, array &$modifiedOptions, array $originalOptions ) { ... }
Attach hook: In extension.json:
{
	"Hooks": {
		"SaveUserOptions": "MediaWiki\\Extension\\MyExtension\\Hooks::onSaveUserOptions"
	}
}
Called from: File(s): user/UserOptionsManager.php
Interface: SaveUserOptionsHook.php

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

Details edit

  • $user: The user for which the options are going to be saved
  • &$modifiedOptions: The user's options as an associative array, modifiable. To reset the preference value to default, set the preference to null. To block the preference from changing, unset the key from the array. To modify a preference value, set a new value.
    • Note: $modifiedOptions can contain options whose values haven't changed.
    • i.e. If there is option = false and later on it is set again to option = false, it's still added to $modifiedOptions even if the value itself hasn't changed.
  • $originalOptions: The user's original options being replaced

See also edit