Blog – Page 2

Create a Post with WordPress REST API using JavaScript

In the previous tutorial we discussed how you can create WooCommerce products by sending REST API requests in JS, so I kind of liked this topic and decided to take a deeper look at regular WordPress posts as well, besided there is almost no similar information out there.

The main struggle here of course is to send POST API requests in JavaScript. When you need to get posts, it is simple โ€“ just use fetch() and there we go. But when we need to authenticate โ€“ how we can do that so nobody can obtain our site application data by just inspecting the code?

Libraries (Official) to Work with WooCommerce REST API and Examples

In the examples across my blog I almost always use the HTTP API when create REST API requests to WooCommerce. I do that because my plugins and especially the crossposting plugin uses HTTP API. You would probably agree with me that it is not always the point to include the whole PHP library inside your custom plugin.

But guys, WooCommerce has the amazingly convenient libraries to work with its REST API which you can use on your projects! In this guide we’re going to talk about PHP and JavaScript libraries (but there are also Python and Ruby ones).

Create Block Patterns Programmatically

Recently I’ve been implementing an automatic block pattern synchronisation feature into my Simple Multisite Crossposting plugin and decided why not to talk about it in a new post.

The goal of this tutorial is to learn how to create both synced and not synced block patterns programmatically and to assign specific pattern categories to them.

How to Integrate Custom Payment Gateways with WooCommerce Checkout Block

On my blog you can find a complete tutorial about creating a WooCommerce payment gateway but in the latest versions of WooCommerce (since 8.3 I guess) you may notice that your custom payment method isn’t available in the Checkout block.

For example if you try to deactivate all the payment methods except your custom one on your store, you’ll probably get an error message like this:

Custom payment method is not displaying in the checkout block
Here I am using Storefront theme as an example, but the same error message will appear for any WordPress theme anyway.

But for sure everything is working great when you’re using a legacy [woocommerce_checkout] shortcode.

Yes, it seems like my complete payment gateway tutorial isn’t that complete anymore, but we’re about to change it today by this extra tutorial where I guide you step by step what you should do in order to add the compatibility of your custom WooCommerce payment method for the WooCommerce Cart and Checkout blocks.

That’s what we’re going to achieve by end of this tutorial:

Custom payment gateway integration with WooCommerce checkout blocks

Sure thing, I will also show you some neat extra stuff like adding a custom icon for your payment method.

How to Publish a Plugin to the WordPress Plugin Directory

Recently I published one more plugin to the repository and I decided it is time to share the whole process with you.

This is not going to be the guide how you need to develop your own plugin in order for it to be accepted by the moderators team, the long story short โ€“ย just read the guidelines, make sure that any user input is properly validated and sanitized, any output is escaped, turn on WP_DEBUG while developing and make sure that there are no PHP notices etc.

How to Auto-Post From One WordPress Site to Another

In this tutorial I am going to show you how you can automatically post an article to another WordPress website with the help of a couple of hooks and REST API. There is also an alternative way of doing that with my Simple WP Crossposting plugin, we’re also going to cover in just a little bit.

By the way, in the similar tutorials about this topic it is usually recommended to use a RSS feed and a plugin which allows to import the content from a feed. Well, this may work when your post consists only from a title and some content but it won’t work of course for complex posts with custom fields, featured images etc.

Prevent Posts in the Trash from Being Updated via REST API

This is a very specific post so it may not be useful for many of you guys, but on the other hand I didn’t even find I hint about anything like this across the internet, so, for those of you who need it, this tutorial is a gem. I hope ๐Ÿ™‚

Let’s say that you have my Simple WP Crossposting plugin installed on your main site (Site 1) or it could be any custom functionality or a plugin that uses a post update REST API endpoint {WP url}/wp-json/wp/v2/posts/{post ID}. So basically we’re syncing changes between the same posts on “Site 1” and “Site 2”.

And our goal is to prevent syncing changes we made on “Site 1” when a post copy on “Site 2” has been moved to the trash. Please note that here I mean not only restoring a post from the trash (changing the post status) but any changes.