这是一个可移植的库,用于在 (几乎) 任何 C# 应用程序中使用 WordPress REST-API
This is a .NET 10 library for consuming the WordPress REST API in C# applications. If you find bugs or have any suggestions, feel free to create an issue.
https://wp-net.github.io/WordPressPCL/
Since WordPress 4.7 the REST API has been integrated into the core so there's no need for any plugins to get basic functionality.
If you want to access protected endpoints, there are two authentication options:
Supported JWT Authentication Plugins (install either of the following):
To use Application Passwords for authentication read through:
https://make.wordpress.org/core/2020/11/05/application-passwords-integration-guide/
The WordPressPCL API Wrapper is avaiable through NuGet:
> Install-Package WordPressPCLWordPressPCL uses GitHub Releases as the source of truth for publishing new package versions.
vX.Y.Z tag (or vX.Y.Z-suffix for pre-releases) and GitHub-generated release notes.WordPressPCL 3.0 targets .NET 10 only. Upgrading from 2.x is a breaking change and requires applications and test environments to move to the .NET 10 SDK/runtime before restoring, building, or running tests.
WordPressPCL 3.0 targets .NET 10 and is intended for applications running on the current .NET platform:
| .NET implementation | Version support |
|---|---|
| .NET | 10.0 |
…For ASP.NET Core and worker services, prefer registering WordPressClient through DI so that HttpClient pooling is managed by IHttpClientFactory.
using Microsoft.Extensions.DependencyInjection;
using WordPressPCL;
builder.Services
.AddWordPressClient(
(services, httpClient) =>
{
httpClient.BaseAddress = new Uri(builder.Configuration["WordPress:BaseUrl"]!);
httpClient.DefaultRequestHeaders.Add("User-Agent", "MyApp/1.0");
},
(services, client) =>
{
client.Auth.UseBasicAuth(
builder.Configuration["WordPress:Username"]!,
builder.Configuration["WordPress:ApplicationPassword"]!);
});You can then request WordPressClient anywhere DI is available:
public sealed class PublishWorker(WordPressClient client)
{
public Task> GetPostsAsync()
=> client.Posts.GetAllAsync();
}| Create | Read | Update | Delete | |
|---|---|---|---|---|
| Posts | yes | yes | yes | yes |
| Pages | yes | yes | yes | yes |
| Comments | yes | yes | yes | yes |
| Categories | yes | yes | yes | yes |
| Tags | yes | yes | yes | yes |
| Users | yes | yes | yes | yes |
| Media | yes | yes | yes | yes |
| Post Revisions | --- | yes | --- | yes |
| Page Revisions | --- | yes | --- | yes |
| Post Autosaves | yes | yes | --- | --- |
| Page Autosaves | yes | yes | --- | --- |
| Taxonomies | --- | yes | --- | --- |
| Post Types | --- | yes | --- | --- |
| Post Statuses | --- | yes | --- | --- |
| Settings | --- | yes | yes | --- |
| Plugins | yes | yes | yes | yes |
| Themes | --- | yes | --- | --- |
| Search | --- | yes | --- | --- |
| URL Details | --- | yes | --- | --- |
Notes:
client.Posts.Revisions(postId).client.Pages.Revisions(pageId).client.Posts.Autosaves(postId) and client.Pages.Autosaves(pageId).WordPressPCL currently provides dedicated clients for the most common wp/v2 endpoints:
client.Posts.Revisions(postId) and client.Pages.Revisions(pageId)client.Posts.Autosaves(postId) and client.Pages.Autosaves(pageId)client.Searchclient.UrlDetails (wp-block-editor/v1/url-details, authentication required)The standard WordPress REST API reference also includes endpoints that do not yet have first-class wrappers in this library, including:
You can still work with unsupported standard endpoints, plugin namespaces and site-specific custom endpoints by using CustomRequest.
// Discover the namespaces and routes exposed by a site
dynamic apiIndex = await client.CustomRequest.GetAsync("", ignoreDefaultPath: true);
// Call a plugin or custom namespace route
dynamic customEndpoint = await client.CustomRequest.GetAsync("wc/v3/products", useAuth: true);For a fuller endpoint-by-endpoint summary, see docs/v3/endpoint-coverage.md.
We're very happy to get input from the community on this project! See CONTRIBUTING.md for full details on setting up a development environment, running tests, and submitting pull requests.
In brief:
dev/install.md file and use Docker Compose.暂无开放 Issues,或尚未同步最近议题。