WordPressPCL 2.0.1

.NET Standard 2.0
dotnet add package WordPressPCL --version 2.0.1
NuGet\Install-Package WordPressPCL -Version 2.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="WordPressPCL" Version="2.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add WordPressPCL --version 2.0.1
#r "nuget: WordPressPCL, 2.0.1"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install WordPressPCL as a Cake Addin
#addin nuget:?package=WordPressPCL&version=2.0.1

// Install WordPressPCL as a Cake Tool
#tool nuget:?package=WordPressPCL&version=2.0.1

WordPressPCL

Integration Tests NuGet

This is a portable library for consuming the WordPress REST-API in (almost) any C# application. 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.

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

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

Supported Plattforms

WordPressPCL is built on top of the .NET Standard targeting netstandard version 2.0 - therefore it should work on the following plaforms:

.NET implementation Version support
.NET and .NET Core 2.0, 2.1, 2.2, 3.0, 3.1, 5.0, 6.0
.NET Framework 4.6.1 2, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
Mono 5.4, 6.4
Xamarin.iOS 10.14, 12.16
Xamarin.Mac 3.8, 5.16
Xamarin.Android 8.0, 10.0
Universal Windows Platform 10.0.16299, TBD
Unity 2018.1

Quickstart: Using the API Wrapper

// Client construction

//pass the Wordpress REST API base address as string
var client = new WordPressClient("http://demo.wp-api.org/wp-json/");

//or pass the base address as strongly typed Uri
const wpBaseAddress = new Uri("http://demo.wp-api.org/wp-json/");
var client = new WordpressClient(wpBaseAddress);

//or to reuse an HttpClient pass the HttpClient with base address set to api's base address
httpClient.BaseAddress = new Uri("http://demo.wp-api.org/wp-json/")
var client = new WordpressClient(httpClient);

// Posts
var posts = await client.Posts.GetAllAsync();
var postbyid = await client.Posts.GetByIdAsync(id);
var postsCount = await client.Posts.GetCountAsync();

// Comments
var comments = await client.Comments.GetAllAsync();
var commentbyid = await client.Comments.GetByIdAsync(id);
var commentsbypost = await client.Comments.GetCommentsForPostAsync(postid, true, false);

// Authentication
var client = new WordPressClient(ApiCredentials.WordPressUri);

//Either Bearer Auth using JWT tokens
client.Auth.UseBearerAuth(JWTPlugin.JWTAuthByEnriqueChavez);
await client.Auth.RequestJWTokenAsync("username", "password");
var isValidToken = await client.IsValidJWTokenAsync();
  
//Or Basic Auth using Application Passwords
client.Auth.UseBasicAuth("username", "password");

// now you can send requests that require authentication
var response = client.Posts.DeleteAsync(postId);

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
Taxonomies --- yes --- ---
Post Types --- yes --- ---
Post Statuses --- yes --- ---
Settings --- yes yes ---

Additional Features

Contribution Guidelines

We're very happy to get input from the community on this project! To keep the code clean we ask you to follow a few simple contribution guidelines.

First, create an issue describing what feature you want to add or what problem you're trying to solve, just to make sure no one is already working on that. That also gives us a chance to debate whether a feature is within the scope of this project.

Second, please try to stick to the official C# coding guidelines. https://msdn.microsoft.com/en-us/library/ms229002(v=vs.110).aspx

Also, make sure to write some tests covering your new or modified code.

In order to run the tests on local machine please refer to the install.md file in the dev directory of the repository. Docker along with docker-compose cli will be required to run the tests.

Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48 net481
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on WordPressPCL:

Package Downloads
BlazingApple.Blog.Services

Package Description

VEFramework.VEDriversLite.Extensions.WooCommerce

.NET drivers for getting information from and to the WooCommerce instance. It can hanlde also communication with main WordPress database

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on WordPressPCL:

Repository Stars
Webreaper/Damselfly
Damselfly is a server-based Photograph Management app. The goal of Damselfly is to index an extremely large collection of images, and allow easy search and retrieval of those images, using metadata such as the IPTC keyword tags, as well as the folder and file names. Damselfly includes support for object/face detection, and face-recognition.
Version Downloads Last updated
2.0.1 1,648 12/21/2022
2.0.0 30,026 4/12/2022
2.0.0-beta.2 165 3/22/2022
2.0.0-beta 74 3/21/2022
2.0.0-alpha 128 1/27/2022
1.9.0 89,381 4/19/2021
1.8.5 16,534 1/6/2021
1.8.4 853 12/26/2020
1.8.2 4,544 11/7/2020
1.7.2 3,020 9/22/2020
1.7.1 14,949 5/11/2020
1.7.0 420 5/11/2020
1.6.2 103,396 3/19/2019
1.6.1 7,821 11/15/2018
1.6.0-beta1 1,124 11/8/2018
1.5.1 1,411 10/26/2018
1.5.0 3,050 9/10/2018
1.4.6 829 8/23/2018
1.4.5 5,615 6/18/2018
1.4.4 934 6/2/2018
1.4.3 806 6/2/2018
1.4.2 3,599 4/18/2018
1.4.1 834 4/18/2018
1.4.1-alpha 792 3/15/2018
1.4.0 1,950 3/9/2018
1.3.3 1,594 1/29/2018
1.3.2 951 1/18/2018
1.3.1 853 1/10/2018
1.3.0 1,200 10/30/2017
1.3.0-alpha 645 10/28/2017
1.2.1 866 10/16/2017
1.2.0 837 10/7/2017
1.1.1 941 9/18/2017
1.1.0 820 9/11/2017
1.0.0 923 8/9/2017
0.1.9 955 6/19/2017
0.1.8 942 6/19/2017
0.1.7 865 6/1/2017
0.1.6 873 5/23/2017
0.1.5 856 5/14/2017
0.1.4 885 4/30/2017
0.1.2-alpha 717 3/14/2017
0.1.1-alpha 794 12/7/2016
0.1.0 3,410 8/18/2016
0.0.5 871 8/18/2016
0.0.4 946 8/4/2016
0.0.3 933 8/4/2016
0.0.2 915 8/4/2016
0.0.1 922 8/4/2016

V2.0.1
- Upgraded Newtonsoft.Json dependency to 13.0.1

V2.0.0
- Dropped netstandard1.x support
- Added Async-Suffix for all public async methods
- Moved Auth-related functionality to Auth-Sub-Client
- Error handling for WP_DEBUG_DISPLAY
- Moved Settings functionality to Settings-Sub-Client
New Features:
- WordPressClient accepts endpoint also as Uri
- Get total Post count without the actual posts
- Generic JWT and Basic Auth support
     
V1.9.0
- Support for Application Passwords
- Upped netstandard1.1 to netstandard1.3

V1.8.5
- Bugfix for Query Builder, will now append default enum values to query string for easier debugging

V1.8.4
- Bugfix for HttpClient injection

V1.8.2
- Support for JWT Auth Plugin

V1.7.2
- Added support for posts trash status
- Added support for providing httpclient to WordPressClient

V1.7.1
- Added Icon
- Updated License Expression

V1.7.0
- Added optional MIME-Type override for Media upload
- Improved handling of HttpClient headers
- Downgraded JSON.NET dependency to V11.0.1
- Exceptions Refactoring

V1.6.2
- Clean up file stream after upload #166
- Added .kmz & .kml Mime Types #162

V1.6.1
- Fix for #147 where Capabilities might contain strings instead of bool

V1.6.0-beta1
- marking all Meta properties as dynamic as the structure seems to be very volatile

V1.5.1
- Make height & width optional in MediaSizes (#143)

V1.5.0
- Enhanced Error handling
https://github.com/wp-net/WordPressPCL/issues/138

V1.4.6
- Bugfix: Add DefaultValueHandling to Comment Status property

V1.4.5
- Bugfix: Add NullValueHandling to FeaturedMedia property

V1.4.4
- Add Yoast Taxonomy Terms

V1.4.3
- Bugfix: Add default JsonSerzializerSettings, setting MissingMemberHandling to ignore

V1.4.2
- Bugfix: delete requests return bool instead of HTTPResponseMessage

V1.4.1-alpha
- Experimental WordPress.com support (readonly)
- Experimental Descending Threaded Comments support

V1.4.0
- making HttpClient static
- Exceptions will be thrown instead of hiding them
- don't auto-append /wp-json to WordPress Uri

V1.3.3
- Fixing update of Comment.Status

V1.3.2
- Fixing Comment.Status issue

V1.3.1
- added maxDepth option for threaded comments

V1.3.0
- added ToThreaded-method for transforming comments
- pass deserialization settings into HttpHelper class
- Added .netstandard 2.0 support
- upload media directly from file path (.netstandard 2.0 only)

V1.2.1
- added JWT getter & setter methods

V1.2
- added helper method to sort comments for a threaded view
- added method to get all comments for a post id
- fixed some async issues for better performance
- added logout method