public function setUserNameReplaceFilter( $replacepatterns ) {

		if ( !is_array( $replacepatterns ) ) {
			throw new UnexpectedValueException( __METHOD__ . ' expects an array as parameter.' );
		}

		Hooks::register(
			static::HOOKNAME,
			function ( &$username ) use ( $replacepatterns ) {
				foreach ( $replacepatterns as $pattern => $replacement ) {
					# If $pattern is no regex, create one from it.
					if ( @preg_match( $pattern, null ) === false ) {
						$pattern = str_replace( '\\', '\\\\', $pattern );
						$pattern = str_replace( '/', '\\/', $pattern );
						$pattern = "/$pattern/";
					}
					$replaced = preg_replace( $pattern, $replacement, $username );
					if ( null === $replaced ) {
						return false;
					}
					$username = $replaced;
				}
				return true;
			}
		);

	}