Coder Social home page Coder Social logo

wordpresspcl's Introduction

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 (and newer):

.NET implementation Version support
.NET and .NET Core 2.0, 2.1, 2.2, 3.0, 3.1, 5.0, 6.0, 7.0, 8.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("https://demo.wp-api.org/wp-json/");

//or pass the base address as strongly typed Uri
const wpBaseAddress = new Uri("https://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("https://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);

// Plugins
var plugins = await client.Plugins.GetAllAsync(useAuth:true);
var installedplugin = await client.Plugins.InstallAsync("akismet");
var activateplugin = await client.Plugins.ActivateAsync(installedplugin);
var deactivateplugin = await client.Plugins.DeactivateAsync(installedplugin);
var deleteplugin = await client.Plugins.DeleteAsync(installedplugin);

// 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 ---
Plugins yes yes 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 and Docker Compose will be required to run the tests.

wordpresspcl's People

Contributors

thomaspe avatar polushinmk avatar navjot50 avatar mykeels avatar kant2002 avatar christianfrick avatar simonhammes avatar tamper2 avatar colinmxs avatar cobalto avatar glienard avatar jamiehowarth0 avatar jessepreiner avatar kiranshahi avatar drhoroscope avatar papsl avatar petesbreencoding avatar dependabot[bot] avatar jeffkaffen avatar peshos avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.