Tapping into switch_to_blog() Function Performance

It just happened that in my WordPress-related work I focused mostly on WordPress Multisite. I had a couple of big client projects in the past, then I developed WordPress plugins for multisite specifically, for example this one or this another one and here we go.

So I have quite a picture in my mind how the things should work the best.

In this tutorial I am about to talk about switch_to_blog() function, especially about its usage within a loop:

  • How does it work exactly?
  • Is it slow?
  • Can we improve it somehow?

First of all let me show you a code snippet I am talking about.

Understanding HPOS (High-Performance Order Storage)

In this tutorial I would like to guide you through the High-Performance Order Storage (HPOS) feature in WooCommerce – how to turn it on for your store, how it may affect it and how to update your plugins in order to make them work with the latest WooCommerce versions.

How to Improve WP Cron Performance

Recently I got some requests from the client who uses my Simple Inventory Sync plugin, and the request was about its “full resync tool”.

The thing is that full resync is using WP Cron to sync product inventory because it is a more seemless solution and sutable for a large stores (with an AJAX approach you can not refresh the tool page and forget about it). But this tool has a limit of HTTP requests per cron job, let’s say 5, so no page overload happen. And even when everything is coded with batch requests, sometimes the client could have tons of products with tons of variations for each for them – in that case the resync will take some time anyway.

The issue is when you have scheduled 1 cron job every minute, but your website has 1 visitor every hour, then guess what – WP Cron will run every hour.

Luckily it is possible to fix if you deactivate WordPress standard cron and just run it from the server.

Let’s do it now.

Speeding Up WooCommerce API

I’ve been working with WooCommerce REST API for quite a while now, well, I developed a couple of plugins – Simple WordPress Crossposting and Simple Inventory Sync and both of them are relying on WooCommerce REST API.

And when you develop something that is intended to be used not only on your test website with 5 products total but also on high load websites, when orders can contain more than 100 products and variations, of course you should always keep performance in mind.

In this tutorial I will share with you some simple simple yet effective tips and tricks.

Compare Meta Box Plugins Performance

Even though Gutenberg (WordPress Block Editor) has become our new reality and FSE themes are also on their way, we still need meta boxes on our projects. The meta boxes aren’t necessarily classic meta boxes for posts, it could be additional settings fields for taxonomies, users, comments and even options pages. It means that we are going to need them for a very long time. Maybe even forever.

Of course the best way to create any of the mentioned above is to code by yourself. But it could be really time consuming especially if you have a lot of fields (and working on lots of projects).

That’s when metabox plugins come into play. The most popular ones are Advanced Custom Fields and Carbon Fields. Also in this article I am going to mention my own metabox plugin I developed for my needs which is Simple Fields.

The idea of this tutorial is to become more conscious to what plugins we are using to achieve our goals, because there are lots of slow WordPress websites out there, not because WordPress is slow but because sites are overloaded with tens and even hundreds heavy plugins.

Let’s look the truth in the face – of course I am going to tell you how cool my Simple Fields plugin is. But I am not going to say “use it”, because I understand clearly that sometimes its functionality is not enough, then you can probably look at Carbon Fields plugin. And even Advanced Custom Fields PRO has its own advantages though I am not a big fan of it.