iolevel / wpdotnet-sdk

WordPress compiled to .NET Standard. SDK for ASP.NET Core.
http://www.wpdotnet.com
Other
414 stars 69 forks source link

How is the Wordpress API exposed and how can I leverage it to extend my site? #141

Open DeanLaw14 opened 1 year ago

DeanLaw14 commented 1 year ago

Hello Hello,

I've recently configured a wp app, so I'm still figuring a lot of this out but I'm looking to intercept requests from WP (perhaps via NETCore middleware), with the intention of applying some logic to the request payload before further sending it to a downstream API. Is something like this possible? If so is there a sample app or documentation you can point me to?

Apologies if this question isn't as focused as it could be, but any help/ideas would be much appreciated

jakubmisek commented 1 year ago

Hi,

I'm glad you're trying wp on .net!

To intercept (any) request on .NET, just add a request handler (middleware) before the WordPress middleware (i.e. before app.UseWordPress();) https://docs.peachpie.io/scenarios/wordpress/overview/#quick-start

To add WordPress hooks in C#, you can take advantage of the plugin API, like this one: https://github.com/iolevel/peachpie-wordpress/blob/master/app/Plugins/ShortcodePlugin.cs .

Then register it in app.UseWordPress(); (https://github.com/iolevel/peachpie-wordpress/blob/20e1c00f94d93467c1987ed48223b98a9e794a20/app/Program.cs#L40)