Post-Migrator/services/wordpress/create-user.go

31 lines
802 B
Go
Raw Normal View History

2024-05-07 22:03:15 +00:00
package wordpress
import (
"encoding/json"
"federated.computer/wp-sync-slowtwitch/utilities"
)
type CreateUser struct {
Username string `json:"username"`
Email string `json:"email"`
Roles string `json:"roles"`
Password string `json:"password"`
2024-05-07 22:03:15 +00:00
}
2024-05-08 00:52:47 +00:00
type CreateUserResponse struct {
Id int `json:"id"`
Username string `json:"username"`
Email string `json:"email"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
}
2024-05-08 01:23:21 +00:00
func (parameters *CreateUser) Execute(baseUrl, user, pass string) CreateUserResponse {
endpoint := baseUrl + "wp-json/wp/v2/users"
2024-05-07 22:03:15 +00:00
body := utilities.PostHttpRequestToWordpress(endpoint, user, pass, parameters)
2024-05-08 01:23:21 +00:00
var userData CreateUserResponse
2024-05-07 22:03:15 +00:00
err := json.Unmarshal(body, &userData)
utilities.CheckError(err)
return userData
}