REST API – Page 4

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.

Disable REST API without Plugins

Before I provide you a code snippet which you can copy and paste to your functions.php or something I would like to discuss why do even need to disable JSON REST API in WordPress?

The long story short is to provide less information about your website to those who shouldn’t probably have it. For example if we add at the end of site URL /wp-json/wp/v2/users, we can list all the registered users! Without emails of course but anyway.

If you want to prevent this from hapenning, you can either disable WordPress REST API completely or just its specific endpoints. And that’s what we’re going to do in this guide.

Sync WooCommerce Customers Between Stores

We already know from my previous tutorial how you can sync WordPress users between sites using REST API. And I also have a plugin for that. But today we are going to make it a little bit differently – for WooCommerce customers using WooCommerce REST API.

Once again I have plenty of tutorials about WooCommerce REST API on my blog, so those who already had a chance to work with it, they will learn nothing new here, I guess.

Indeed, the example in this tutorial is quite simple – we are going to go to any user profile settings, hit “Update User” button and we expect those changes to be reflected on the other WooCommerce store. As simple as that.

Delete all Product Variations Using REST API

Recently I have found this question on the internet and since I was doing exactly the same when developing WooCommerce functionality for my crossposting plugin, I decided to create a small guide for you.

The long story short we will need two REST API requests here:

  • To get all variations of a specific product,
  • To delete all of them in a single batch request.

I think the most clear way here would be to create a function for that, let’s say for example rudr_delete_all_variations() or something.

Using REST API to Sync Users Between Remote Sites

In this post we are going to talk about REST API, particularly about how to sync user registrations, profile updates and removals between two remote WordPress websites.

Manage Custom Taxonomy Terms with REST API

In this tutorial I would like to guide you how you can create WordPress REST API requests in order to manage custom taxonomy terms. And also I’d like to show you some interesting examples along the way.

The idea of this article actually came to my mind when I was developing an add-on for my Simple WordPress Crossposting plugin.

Include Meta Data When Updating Users via REST API

In my another tutorial about syncing users using WordPress REST API I received a question in comments, where I was asked about metadata. After googling for quite a bit I found out that there is no clear explanation out there about using user’s meta in REST API requests.