SyncFromExternalSourceTrait
Apply Sync rules after an external multilingual plugin (e.g. WPML) created a translation.
Expects AbstractLanguagePlugin helpers (translateInput, filterMetaValue, withSourceTranslationCatalog, …).
WPML-specific hooks and defer overrides live in WPML.
Table of Contents
Properties
- $applyingExternalSourceSync : mixed
- True while `syncPostFromExternalSource()` / `syncTermFromExternalSource()` write target fields. Suppresses live `updated_*_meta` fan-out in `Sync` for those writes.
Methods
- isApplyingExternalSourceSync() : mixed
- Whether `Sync::updated_postmeta()` / `Sync::updated_term_meta()` should skip.
- isExternalTranslationSyncDeferredForPost() : mixed
- Gate for `Sync::save_post()`: when `true`, Sync skips post sync for this write.
- isExternalTranslationSyncDeferredForTerm() : mixed
- Gate for `Sync::created_term()`: when `true`, Sync skips term sync for this write.
- syncPostFromExternalSource() : mixed
- Apply sync copy rules after an external plugin created a post translation: taxonomies + translated columns.
- syncPostMetaFromExternalSource() : mixed
- Run configured post meta through `filterMetaValue()` on the target translation.
- syncTermFromExternalSource() : mixed
- Apply sync copy (meta + term columns) after an external plugin created the translation.
- syncTermMetaFromExternalSource() : mixed
- Copy configured term meta from the source translation after an external plugin created the target.
- whileApplyingExternalSourceSync() : mixed
- Run callback while external-source sync writes the target translation only (no live meta fan-out).
Properties
$applyingExternalSourceSync
True while `syncPostFromExternalSource()` / `syncTermFromExternalSource()` write target fields. Suppresses live `updated_*_meta` fan-out in `Sync` for those writes.
private
mixed
$applyingExternalSourceSync
= false
Methods
isApplyingExternalSourceSync()
Whether `Sync::updated_postmeta()` / `Sync::updated_term_meta()` should skip.
public
isApplyingExternalSourceSync() : mixed
See whileApplyingExternalSourceSync().
isExternalTranslationSyncDeferredForPost()
Gate for `Sync::save_post()`: when `true`, Sync skips post sync for this write.
public
isExternalTranslationSyncDeferredForPost(int $postId) : mixed
Sync::save_post() calls this first and returns immediately when it is true — no
copyPostToOtherLanguage(), no cross-language meta/column sync on that hook. The external
plugin already created or is creating the translation; applies sync copy rules later via
syncPostFromExternalSource() instead.
WPML example: true only while make_duplicate runs (duplicateCreationInProgress).
After icl_make_duplicate, WPML duplicate meta is removed so ongoing saves use Sync.
Parameters
- $postId : int
isExternalTranslationSyncDeferredForTerm()
Gate for `Sync::created_term()`: when `true`, Sync skips term sync for this write.
public
isExternalTranslationSyncDeferredForTerm(int $term_id, string $taxonomy) : mixed
Sync::created_term() calls this first and returns immediately when it is true — no
copyTermToOtherLanguage() for other languages on that hook. The external plugin already
inserted the translated term; applies sync copy rules later via
syncTermFromExternalSource() instead.
WPML example: Taxonomy Translation UI (e.g. Service groups → "Copy to all languages",
wp_ajax_wpml_save_term). Skipping avoids duplicate/orphan terms in the source language.
Parameters
- $term_id : int
- $taxonomy : string
syncPostFromExternalSource()
Apply sync copy rules after an external plugin created a post translation: taxonomies + translated columns.
public
syncPostFromExternalSource(int $from, int $to, string $locale[, array<string|int, string> $taxonomies = [] ][, array<string|int, mixed> $postConfiguration = [] ]) : mixed
Title/content/excerpt use the same rules as duplicatePost() (translateInput() without extra
contexts). Post meta is not read from the master again (large payloads). Values already on $to
from the external duplicate are passed through filterMetaValue() when a consumer registered
DevOwl/Multilingual/Copy/Meta/post/{key}.
Parameters
- $from : int
-
Source post id
- $to : int
-
Target post id
- $locale : string
-
Target language code
- $taxonomies : array<string|int, string> = []
-
Taxonomies to remap to the target locale (same as
copyPostToOtherLanguage) - $postConfiguration : array<string|int, mixed> = []
-
Sync options for the post type (from
Sync::getPostsConfiguration())
syncPostMetaFromExternalSource()
Run configured post meta through `filterMetaValue()` on the target translation.
public
syncPostMetaFromExternalSource(int $from, int $to, array<string|int, string> $metaKeys, string $locale[, bool $readValueFromTarget = false ]) : mixed
Parameters
- $from : int
-
Source post id
- $to : int
-
Target post id
- $metaKeys : array<string|int, string>
-
Meta keys registered for copy / copy-once sync
- $locale : string
-
Target language code
- $readValueFromTarget : bool = false
-
When true, read meta from
$to(WPML already copied) and update only if the filter changes the value
syncTermFromExternalSource()
Apply sync copy (meta + term columns) after an external plugin created the translation.
public
syncTermFromExternalSource(int $from, int $to, array<string|int, string> $metaKeys, string $locale) : mixed
Mirrors duplicateTerm(): snapshot source PO catalog via withSourceTranslationCatalog(),
switch target locale, translateInput.
Parameters
- $from : int
-
Source term id
- $to : int
-
Target term id
- $metaKeys : array<string|int, string>
-
Meta keys registered for copy / copy-once sync
- $locale : string
-
Target language code
syncTermMetaFromExternalSource()
Copy configured term meta from the source translation after an external plugin created the target.
public
syncTermMetaFromExternalSource(int $from, int $to, array<string|int, string> $metaKeys, string $locale) : mixed
Parameters
- $from : int
-
Source term id
- $to : int
-
Target term id
- $metaKeys : array<string|int, string>
-
Meta keys registered for copy / copy-once sync
- $locale : string
-
Target language code
whileApplyingExternalSourceSync()
Run callback while external-source sync writes the target translation only (no live meta fan-out).
protected
whileApplyingExternalSourceSync(callable $callback) : mixed
Parameters
- $callback : callable