wpUpdateUserInfo method
Sends a request to update details for a WordPress user. Include a valid
userToken
to send a successful request. Optional parameters include
a firstName
, lastName
, displayName
or metaData
to update user's.
Returns a WPUserInfoUpdatedResponse future. Throws an Exception if fails.
Implementation
Future<WPUserInfoUpdatedResponse> wpUpdateUserInfo(
{String? userToken,
String? firstName,
String? lastName,
String? displayName,
List<WpMetaData>? metaData}) async {
Map<String, dynamic> payload = {};
if (firstName != null) payload["first_name"] = firstName;
if (lastName != null) payload["last_name"] = lastName;
if (displayName != null) payload["display_name"] = displayName;
if (metaData != null) {
payload['meta_data'] = {
"items": metaData.map((e) => e.toJson()).toList()
};
}
// send http request
final json = await _http(
method: "POST",
url: _urlForRouteType(WPRouteType.UserUpdateInfo),
userToken: userToken,
shouldAuthRequest: true,
body: payload,
);
// return response
return _jsonHasBadStatus(json)
? this._throwExceptionForStatusCode(json)
: WPUserInfoUpdatedResponse.fromJson(json);
}