Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to additional fields to register user #3

Closed
MichaelSowah opened this issue Aug 28, 2021 · 4 comments
Closed

how to additional fields to register user #3

MichaelSowah opened this issue Aug 28, 2021 · 4 comments

Comments

@MichaelSowah
Copy link

MichaelSowah commented Aug 28, 2021

How do I add additional fields such as user role, phone number, etc to register a user?

@agordn52
Copy link
Contributor

Hi @MichaelSowah, the API supports registration with an email, username and password.

WPUserRegisterResponse wpUserRegisterResponse = await WPJsonAPI.instance
      .api((request) => request.wpRegister(
         email: email,
         password: password,
         username: username
      ));

Once they are logged in, you could then call the API to update the user's phone number.
If it's the 'billing phone number' field, you could use the below API method or shippingPhone for the 'shipping phone number'.

WCCustomerUpdatedResponse wcCustomerUpdatedResponse = await WPJsonAPI.instance
        .api((request) => request.wcUpdateCustomerInfo(
            userToken,
            billingPhone: billingPhone
        ));

Re. the role, the API currently doesn't support that.
We can add it to the backlog of things to do, might have a quick turnaround on this for you.

@MichaelSowah
Copy link
Author

Thanks, I would really appreciate that especially the ability to pass the role of the user eg: customer, admin, etc.
At least an optional parameter/field for the dev to pass the user role will be very great for me please as I have different users with different roles creating accounts on my app...how possible is this and what's likely the timeline for adding the role parameter/field?

@agordn52
Copy link
Contributor

agordn52 commented Sep 3, 2021

Hi @MichaelSowah, v3.1.2 supports the ability to add/remove roles.

Add a new role to a user

WPUserAddRoleResponse wpUserAddRoleResponse = await WPJsonAPI.instance
        .api((request) => request.wpUserAddRole(
            userToken,
            role: "customer" // e.g. customer, subscriber
        ));

Remove role from a user

WPUserRemoveRoleResponse wpUserRemoveRoleResponse = await WPJsonAPI.instance
        .api((request) => request.wpUserRemoveRole(
            userToken,
            role: "customer" // e.g. customer, subscriber
        ));

You'll need to update your WordPress plugin WP JSON API to v3.1.0.

@MichaelSowah
Copy link
Author

great, I updated my plugin

@agordn52 agordn52 closed this as completed Sep 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants