Every once in a while I am receiving questions about my Simple Multisite Crossposting plugin whether it works with shared media library plugins or not (yes – it works). And when I decided to test it I figured it out that there are multiple shared media library plugins out there and every one of them works a little bit differently.
The key idea of most of these plugins is to store all the media on one “main” blog and not necessarily it should be the blog with ID = 1. Then some of them use
switch_to_blog() function every time you’re working with attachments on subsites, the other ones even create attachments in database linked to original files on all subsites (I assume it could lead to issues by the way).
Most of all I like a
switch_to_blog() approach because it seems unharmful, you can even stop using network media library any time, just deactivate the plugin and continue to use your websites as usual.
In this tutorial I am going to show you two ways how you can sync your WooCommerce products between stores within a single WordPress multisite network.
Under two ways I mean this:
- In code with the help of the
woocommerce_update_productaction hook, the
switch_to_blog()function and CRUD layers (in case we’re working not with a multisite network but with standalone WooCommerce stores, then we need to use REST API, there is a separate tutorial about that).
- With the plugin (just install and here we go).
Below is an example of how it can be implemented on your store with my plugin:
Let’s assume, that you’re currently working on Site A and you need to get and display a post (or page or a custom post type – doesn’t matter) from Site B of your Multisite network.
How to do that?
Recently I’ve been working with this functionality in one of my plugins and now I decided to share it with you.
But I always want my tutorials to be more practical, so check what we are going to create:
The whole tutorial consists of two parts – in the first one I will show you a ready to use function that allows to move media from one site of a multisite network to another, in the second – we will create a custom bulk action for media files.
There are actually two ways of organising shared content between sites in Multisite Network: