Sending Multiple REST API Requests using PHP Requests Library

Recently I got a message from one of my customer and he complained about that inventory sync in my Simple Inventory Sync plugin doesn’t work as fast as he wanted it to.

When I took a look at his website configuration, I noticed that he wanted to syncronise the product stock up to 10 websites at the same time.

At that moment my plugin was already using batch API requests in case someone made an order with 50 products (for example) at the same time (so we can send only a one request instead of 50), but we can not send a single batch request to 10 different sites, can we?

Get Attachment Alt Text, Caption, Description and Title Programmatically

Every time I work with WordPress attachments I always forget what is what, for example:

  • What is the name of the alt text meta field?
  • How to get an image caption programmatically?

Probably after publishing this tutorial I will never forget that again, but I really hope that it will be helpful for you guys.

So, the long story short, in this tutorial I am going to show you how you can get the following attachment data programmatically:

WordPress attachment information – alt text, caption, title and description

Let’s dive into it right now!

Hooks When Creating or Updating a Post (Classic Editor, Gutenberg and REST API)

Probably all of us know the save_post action hook which usually runs every time a WordPress post of any type (or even a WooCommerce product) is getting created or updated.

But sometimes you need to process only post updates in some specific cases, for example only when you do it via the REST API or using the Classic Editor. Is there a way to do that?

Let’s try to figure it out.

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?

How to Publish a Plugin to the WordPress Plugin Directory

Recently I published one more plugin to the wordpress.org 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.