- Notifications
You must be signed in to change notification settings - Fork 15
Usage
Easily integrate WordPress functionalities into your Dart project with the wordpress_client package.
Add wordpress_client to your project's pubspec.yaml file:
dependencies: wordpress_client: ^{latest}Make sure to check the Package Page for the most recent version.
Integrate the library into the desired Dart class:
import 'package:wordpress_client/wordpress_client.dart';Initialize the WordpressClient using either the simple or advanced method. Create it once and reuse the instance across your app.
final baseUrl = Uri.parse('https://example.com/wp-json/wp/v2'); final client = WordpressClient(baseUrl: baseUrl);final client = WordpressClient.forSite( siteUrl: Uri.parse('https://example.com'), );final baseUrl = Uri.parse('https://example.com/wp-json/wp/v2'); final client = WordpressClient( baseUrl: baseUrl, bootstrapper: (bootstrapper) => bootstrapper .withStatisticDelegate((baseUrl, requestCount) { print('$baseUrl -> $requestCount'); }) .withDebugMode(true) .withDefaultAuthorization( WordpressAuth.appPassword( user: 'username', appPassword: 'xxxx-xxxx', ), // or: WordpressAuth.usefulJwt(user: 'username', password: 'password', device: 'device-id') // or: WordpressAuth.basicJwt(user: 'username', password: 'password') ) .build(), );wordpress_client also offers the flexibility of using a custom Dio instance with the client. This can be achieved by calling WordpressClient.fromDioInstance(...) constructor and by passing the Dio instance via the instance parameter.
That's it! You're now equipped to seamlessly integrate WordPress functionalities into your Dart project using wordpress_client. Happy coding!
Each interface exposes an extensions property with useful helpers, keeping the core API clean:
final post = await client.posts.extensions.getById(123); final bySlug = await client.pages.extensions.findBySlug('about'); final allUsers = await client.users.extensions.listAll(perPage: 100);Construct list requests with a fluent builder that autoβseeds the correct request type.
final res = await client.posts.query .withPage(1) .withPerPage(20) .withSearch('hello') .withOrder(Order.desc) .execute(); // Advanced: mutate the underlying seed final res2 = await client.posts.query .configureSeed((seed) { seed.context = RequestContext.view; }) .execute(); // Or access it directly then execute later final builder = client.posts.query; builder.seedRequest.context = RequestContext.view; final res3 = await builder.execute();Notes:
- A few interfaces (e.g., revisions/navigation) autoβseed with placeholder IDsβset them via
configureSeed/seedRequestbefore.execute(). - There are many fluent helpers (
withPage,withPerPage,withSearch,withOrder,withOrderBy,withCategories,withTags,withInclude,withExclude,withStatus,withSlug,withAuthor, etc.). If a field isnβt covered, set it on the seed.
- π Welcome to our Wiki!
- π Usage
- π Using Custom Requests
- π‘ Authorization
- π Supported REST Methods
- π API Changelog
- π Middlewares
- π« Parallel Requests
- π§© Interfaces & Extensions
- π‘οΈ Error Handling & Responses
- βοΈ Bootstrap & Configuration
- π Events & Statistics
- π Pagination & Finders