isotopsweden/wp-syncs

Syncs synchronizes posts and terms between multisites

Installs: 873

Dependents: 0

Suggesters: 0

Security: 0

Stars: 8

Watchers: 3

Forks: 1

Open Issues: 2

Type:wordpress-muplugin

v2.0.0 2021-11-01 03:32 UTC

README

Requires PHP 7.0 and WordPress 4.6

Syncs synchronizes attachments, posts and terms between multisites

Installation

composer require isotopsweden/wp-syncs

Usage

Example configuration for post types:

// With `register_post_type`
register_post_type( 'book', [
  'syncs' => true
] );

// With the filter.
add_filter( 'syncs_post_types', function ( $post_types ) {
  return ['page', 'post', 'book'];
} );

Example configuration for taxonomies:

// With `register_taxonomy`
register_taxonomy( 'group', 'post', [
  'syncs' => true
] );

// With the filter.
add_filter( 'syncs_taxonomies', function ( $taxonomies ) {
  return ['tag', 'category', 'group'];
} );

How the sync works

Created data

When a new post, term or attachment is created on a multisite it will be created on the other multisites and all obeject ids will be linked with a global sync id that is stored in the syncs table like this:

All sync ids are stored as metadata on objects just because of WP_Query, when you read sync_id with get_metadata it actual reads from the syncs table.

Updated data

When a post, term or attachment is updated on a multisite the master it's the multisite where the user is updating. The other objects on other multisites will be removed and created again with the same global sync id but with new object ids. That's why you can't use object id as a id, instead you have to use sync_id value. It can be access via get_metadata or syncs()->get_sync_id( $object_id, $object_type, [$site_id = 0] )

Deleted data

When a post, term or attachment is deleted it will be deleted on all multisites and the sync_id will be deleted.

WP CLI

You can run wp syncs sync to synchronizes all posts from one site to all other sites.

License

MIT © Isotop