You can download the WordPress plugin here WP JSON API.
Install the WordPress plugin to use this Flutter package.
WordPress
- Register/Sign Up API for Users
- Login (with email or username)
- Get Users Info
- Update Users Info
- Update Users Password
- Add role to a user
- Remove role from a user
- Delete a user
WooCommerce
- Get Customers Info (Billing and Shipping)
- Update Customers details
To use this API you must have the WP JSON API Plugin installed first on your WordPress site, you can download it via the WooSignal website.
In your flutter project add the dependency:
dependencies:
...
wp_json_api: ^3.5.13
Import wp_json_api.dart
import 'package:wp_json_api/wp_json_api.dart';
import 'package:wp_json_api/wp_json_api.dart';
...
void main() {
WPJsonAPI.instance.init(baseUrl: "https://mysite.com");
...
try {
WPUserLoginResponse wpUserLoginResponse = await WPJsonAPI.instance
.api((request) => request.wpLogin(
email: email,
password: password
));
} on Exception catch (e) {
print(e);
}
- Used for returning a valid nonce
WPNonceResponse wpNonceResponse = await WPJsonAPI.instance
.api((request) => request.wpNonce());
- Used for verifying register and login request
WPNonceVerifiedResponse wpNonceVerifiedResponse = await WPJsonAPI.instance
.api((request) => request.wpNonceVerify(
nonce: nonce
));
- Used to login a user
WPUserLoginResponse wpUserLoginResponse = await WPJsonAPI.instance
.api((request) => request.wpLogin(
email: email,
password: password,
authType: WPAuthType.WpEmail
));
- Used to login a user
WPUserLoginResponse wpUserLoginResponse = await WPJsonAPI.instance
.api((request) => request.wpLogin(
username: username,
password: password,
authType: WPAuthType.WpUsername
));
- Used to register a user
- The username parameter is required, ensure that this is unique
WPUserRegisterResponse wpUserRegisterResponse = await WPJsonAPI.instance
.api((request) => request.wpRegister(
email: email,
password: password,
// username: username // optional - the library will automatically generate a username if not provided
));
- Used to get a WordPress users info
- After you login/register, you can all this method to get the users info
WPUserInfoResponse wpUserInfoResponse = await WPJsonAPI.instance
.api((request) => request.wpGetUserInfo());
- Used to update a WordPress users info
- After you login/register, you can all this method to update the users info
WPUserInfoUpdatedResponse wpUserInfoUpdatedResponse = await WPJsonAPI.instance
.api((request) => request.wpUpdateUserInfo(
firstName: firstName,
lastName: lastName,
displayName: displayName
));
- Used to update a users password
- After you login/register, you can all this method to update the users password
WPUserResetPasswordResponse wpUserResetPasswordResponse = await WPJsonAPI.instance
.api((request) => request.wpResetPassword(
password: password
));
- Used to add a role to a user in WordPress
- After you login/register, you can all this method to add a role to the user
WPUserAddRoleResponse wpUserAddRoleResponse = await WPJsonAPI.instance
.api((request) => request.wpUserAddRole(
role: "customer" // e.g. customer, subscriber
));
- Used to remove a role from a user in WordPress
- After you login/register, you can all this method to remove a role from the user
WPUserRemoveRoleResponse wpUserRemoveRoleResponse = await WPJsonAPI.instance
.api((request) => request.wpUserRemoveRole(
role: "customer" // e.g. customer, subscriber
));
- Used to delete a user in WordPress
- After you login/register, you can all this method to delete the user
- You can pass an optional argument 'reassign' to reassign posts and links to new User ID.
WPUserDeleteResponse wpUserDeleteResponse = await WPJsonAPI.instance
.api((request) => request.wpUserDelete());
- Used to register a user
WPUserRegisterResponse wpUserRegisterResponse = await WPJsonAPI.instance
.api((request) => request.wpRegister(
email: email,
password: password
));
- Used to get WooCommerce info for a given user
- After you login/register, you can all this method to get the users WooCommerce info
WCCustomerInfoResponse wcCustomerInfoResponse = await WPJsonAPI.instance
.api((request) => request.wcCustomerInfo(
userToken
));
- Used to update a users WooCommerce details
- All the parameter are optional so if you wanted to just update the name, you could just add first_name and last_name
- After you login/register, you can all this method to update the users WooCommerce info
WCCustomerUpdatedResponse wcCustomerUpdatedResponse = await WPJsonAPI.instance
.api((request) => request.wcUpdateCustomerInfo(
firstName: firstName,
lastName: lastName,
displayName: displayName,
billingFirstName: billingFirstName,
billingLastName: billingLastName,
billingCompany: billingCompany,
billingAddress1: billingAddress1,
billingAddress2: billingAddress2,
billingCity: billingCity,
billingState: billingState,
billingPostcode: billingPostcode,
billingCountry: billingCountry,
billingEmail: billingEmail,
billingPhone: billingPhone,
shippingFirstName: shippingFirstName,
shippingLastName: shippingLastName,
shippingCompany: shippingCompany,
shippingAddress1: shippingAddress1,
shippingAddress2: shippingAddress2,
shippingCity: shippingCity,
shippingState: shippingState,
shippingPostcode: shippingPostcode,
shippingCountry: shippingCountry,
shippingEmail: shippingEmail,
shippingPhone: shippingPhone
));
- This is used to get the user's current points in the WooCommerce Points and Rewards plugin
- After you login/register, you can all this method to get the users points
WcPointsAndRewardUser wcPointsAndRewardUser = await WPJsonAPI.instance
.api((request) => request.wcPointsAndRewardsUser());
- This is used to calculate the value of points in the WooCommerce Points and Rewards plugin
- After you login/register, you can all this method to calculate the value of points
WcPointsAndRewardCalculatePoints wcPointsAndRewardsCalculatePoints = await WPJsonAPI.instance
.api((request) => request.wcPointsAndRewardsCalculatePoints(
points: 100
));
For help getting started with WooSignal, view our online documentation, which offers a more detailed guide.
To use this plugin, add wp_json_api
as a dependency in your pubspec.yaml file.
Install our WordPress plugin "WP JSON API" v3.4.0 to use this flutter plugin.
Disclaimer: This plugin is not affiliated with or supported by Automattic, Inc. All logos and trademarks are the property of their respective owners.