百科.dev
全部条目AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
W

WordPressPCL

> 编程语言
开源

这是一个可移植的库,用于在 (几乎) 任何 C# 应用程序中使用 WordPress REST-API

357 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

这是一个可移植的库,用于在 (几乎) 任何 C# 应用程序中使用 WordPress REST-API

WordPressPCL

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.

Documentation

https://wp-net.github.io/WordPressPCL/

Quickstart

WordPress Requirements

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.

  • WordPress 4.7 or newer

If you want to access protected endpoints, there are two authentication options:

  • Authentication using JSON Web Tokens (JWT) (plugin required)
  • Basic Authentication using Application Passwords

Supported JWT Authentication Plugins (install either of the following):

  • JWT Authentication for WP REST API
  • JWT Auth By Useful Team

To use Application Passwords for authentication read through:

https://make.wordpress.org/core/2020/11/05/application-passwords-integration-guide/

Including WordPressPCL

The WordPressPCL API Wrapper is avaiable through NuGet:

> Install-Package WordPressPCL

Release Process

WordPressPCL uses GitHub Releases as the source of truth for publishing new package versions.

  1. Update CHANGELOG.md with the release highlights.
  2. Create a GitHub release with a vX.Y.Z tag (or vX.Y.Z-suffix for pre-releases) and GitHub-generated release notes.
  3. Publishing that release triggers the NuGet workflow, which builds and publishes the same version to NuGet.

Runtime Requirement

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.

Versioned Reference Docs

  • Version 3.x reference docs
  • Version 2.x reference docs
  • Version 1.x reference docs

Supported Platforms

WordPressPCL 3.0 targets .NET 10 and is intended for applications running on the current .NET platform:

.NET implementation Version support
.NET 10.0

Quickstart: Using the API Wrapper

…

Dependency injection and IHttpClientFactory

For ASP.NET Core and worker services, prefer registering WordPressClient through DI so that HttpClient pooling is managed by IHttpClientFactory.

csharp
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:

csharp
public sealed class PublishWorker(WordPressClient client)
{
    public Task> GetPostsAsync()
        => client.Posts.GetAllAsync();
}

Supported REST Methods

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:

  • Post revisions are available through client.Posts.Revisions(postId).
  • Page revisions are available through client.Pages.Revisions(pageId).
  • Post and page autosaves are available through client.Posts.Autosaves(postId) and client.Pages.Autosaves(pageId).

Endpoint Coverage and Gaps

WordPressPCL currently provides dedicated clients for the most common wp/v2 endpoints:

  • Posts, Pages, Comments, Categories, Tags, Users and Media
  • Taxonomies, Post Types, Post Statuses and Settings
  • Post and page revisions via client.Posts.Revisions(postId) and client.Pages.Revisions(pageId)
  • Post and page autosaves via client.Posts.Autosaves(postId) and client.Pages.Autosaves(pageId)
  • Plugins and Themes
  • Search via client.Search
  • URL details via client.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:

  • newer block editor endpoints such as block types, blocks, block rendering, templates, template parts and global styles
  • navigation, sidebars, widgets and widget types

You can still work with unsupported standard endpoints, plugin namespaces and site-specific custom endpoints by using CustomRequest.

csharp
// 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.

Additional Features

  • Authentication using JSON Web Tokens (JWT)
  • HttpResponsePreProcessing: manipulate the API response before deserializing it

Contribution Guidelines

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:

  • Open an issue before starting work so we can discuss scope and avoid duplicate effort.
  • Follow the Microsoft C# coding guidelines.
  • Add or update tests to cover your change.
  • In order to run the tests locally, refer to the dev/install.md file and use Docker Compose.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

C#

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言