WPML
extends AbstractSyncPlugin
in package
WPML language handler.
Table of Contents
Constants
- MARKER_SPLIT_TRANSLATION_ENTRY : mixed = 'splitTranslationEntry'
- TEMPORARY_TEXT_DOMAIN_PREFIX : mixed = 'multilingual-temporary-text-domain'
Properties
- $copyToOtherLanguageMap : mixed
- `copyTermToOtherLanguage` and `copyPostToOtherLanguage` create a duplicate of a term and post. This map holds the mapping of original-ID to translation-ID. This map is filled with the translations like this:
- $currentTranslationEntries : mixed
- Current translations hold as an instance.
- $findI18nKeyOfTranslationCache : mixed
- $lockCurrentTranslations : mixed
- $splitTranslationEntriesCache : SplObjectStorage<Translation_Entry, array<string|int, Translation_Entry>>
- Cache for split translation entries.
- $taxonomySourceResolutionExcludePostId : int|null
- During `syncPostFromExternalSource()`, the duplicate post id excluded from WPML taxonomy sibling fallback (the in-progress translation must not supply term assignments as source).
- $translateArrayCache : mixed
- $applyingExternalSourceSync : mixed
- True while `syncPostFromExternalSource()` / `syncTermFromExternalSource()` write target fields. Suppresses live `updated_*_meta` fan-out in `Sync` for those writes.
- $disabledCopyAndSync : mixed
- $duplicateCreationInProgress : mixed
- True while `sitepress->make_duplicate()` runs (Translation Dashboard duplicate).
- $duplicateSourceTermsByMaster : array<int, array<string, array<string|int, int>>>
- Per-master taxonomy assignments captured at `icl_before_make_duplicate`.
- $wpmlTermSaveInProgress : mixed
- True while WPML taxonomy translation UI saves a term (`wp_ajax_wpml_save_term`).
Methods
- __construct() : mixed
- C'tor.
- beforeWpmlSaveTerm() : mixed
- Mark WPML taxonomy term save so `Sync::created_term` does not recurse.
- copyPostTaxonomies() : mixed
- Copy already existing taxonomies as it can be inserted with `tax_input` directly.
- copyPostToOtherLanguage() : int|bool
- Translate given post to other language.
- copyTermToOtherLanguage() : int|bool
- Translate given term to other language.
- createTemporaryTextDomain() : mixed
- Create a temporary text domain.
- determineImplementation() : AbstractLanguagePlugin
- Determine implementation class.
- disableCopyAndSync() : mixed
- Disable sync mechanism of our language plugin as it is handled by `Sync.php`.
- duplicatePostMeta() : mixed
- Copy already existing meta as it can be inserted with `meta_input` directly.
- endWpmlSaveTerm() : mixed
- Clear the WPML taxonomy save flag after the AJAX handler finishes.
- filterMetaValue() : mixed
- Apply a WordPress filter so a meta value can be modified for copy process to other languages.
- filterWithExistingTranslatedTextDomain() : mixed
- Filter a list of locales and check if translations from a PO/MO file exists.
- findI18nKeyOfTranslation() : mixed
- The same as `findI18nKeyOfTranslationRaw`, but with caching enabled as this could be called very often.
- findI18nKeyOfTranslationRaw() : mixed
- Find an i18n key for `__()` from a given translated string.
- getActiveCountriesFlags() : mixed
- Get the flags of all active languages.
- getActiveLanguages() : array<string|int, string>
- Get all active languages.
- getCountryFlag() : string|false
- Get a `src` compatible link to the country flag.
- getCurrentLanguage() : string
- Get current language.
- getCurrentLanguageFallback() : mixed
- Get current language or fallback to default language when the multilingual is in a state like "Show all languages" (option known in the admin toolbar).
- getCurrentPostId() : int
- Get current id of passed post id and fallback to passed id, when no translation found.
- getCurrentTermId() : int
- Get the term id for `$locale`; adapters fall back to `$id` when no translation exists.
- getDefaultLanguage() : string
- Get default language.
- getLanguageSwitcher() : array<string|int, array<string|int, mixed>>
- Get a language switcher for the current page.
- getLocalesBeforeSwitch() : mixed
- List of locales before switching locale via `switchToLanguage`.
- getObjectTermIdsForPostLanguage() : array<string|int, int>
- Term ids assigned to a post in a specific language context (avoids WPML read fallbacks).
- getOriginalPostId() : int
- Get original id of passed post id.
- getOriginalTermId() : int
- Get original id of passed term id.
- getOverrideClassInstance() : mixed
- Get an instance of the `overrideClass`.
- getPermalink() : string
- Get the URL of a given URL for another locale.
- getPostLanguage() : string
- Get language of passed post id.
- getPostTranslationIds() : array<string|int, int>
- Get all translations of a given post type.
- getSkipHTMLForTag() : string
- Get the HTML attribute so the "dynamic" replacement gets disabled on frontend side. This can be useful for texts which are directly translated in PHP already and gets translated via JavaScript again.
- getSync() : mixed
- Get `Sync` instance for this plugin. Can be `null` if not given.
- getTaxonomyTranslationIds() : array<string|int, int>
- Get all translations of a given taxonomy.
- getTemporaryTextDomainName() : mixed
- Get the current temporary text domain name which can be used for `__` when e.g. inside `switchToLanguage`.
- getTermLanguage() : string
- Get language of passed term.
- getTranslatedName() : string
- Get translated name for a given locale.
- getWordPressCompatibleLanguageCode() : string
- Get the WordPress compatible language code of a given locale.
- isActive() : mixed
- Is a multilingual plugin active?
- isApplyingExternalSourceSync() : mixed
- Whether `Sync::updated_postmeta()` / `Sync::updated_term_meta()` should skip.
- isCurrentlyInEditorPreview() : bool
- Check if the translate plugin is currently in edit mode (preview).
- isExternalTranslationSyncDeferredForPost() : mixed
- isExternalTranslationSyncDeferredForTerm() : mixed
- isPresent() : mixed
- Check if WPML is active.
- iterateAllLanguagesContext() : mixed
- Iterate all language contexts.
- iterateOtherLanguagesContext() : mixed
- Iterate all other languages than current one and get their context.
- lockCurrentTranslations() : mixed
- Do not allow to take another snapshot of current translations.
- matchLanguageCodeFromWordPressCompatibleLocale() : mixed
- Resolve the plugin language code (e.g. en, de) from a WordPress-compatible locale (e.g. en_US from {@see getWordPressCompatibleLanguageCode()}). Also accepts an already-short plugin code when it is listed in {@see getActiveLanguages()}.
- maybePersistTranslation() : mixed
- Maybe persist a translation in the database of available translations.
- onSetObjectTermsCopyPostTaxonomies() : mixed
- Copy taxonomy assignments from a master post to its translations when terms are set on the master.
- postCopiedToAllOtherLanguages() : mixed
- This method is called due to `Sync::save_post`. It allows you to get a list of all translations of a post in an associate array.
- remapPostId() : int
- Resolve a post id to its translation in `$locale`, if one should be stored on a translation post.
- rest_prepare_post() : mixed
- Add a `multilingual` section to a given post type.
- rest_prepare_taxonomy() : mixed
- Add a `multilingual` section to a given taxonomy.
- setPostLanguage() : mixed
- This method is called due to `Sync::save_post`. It allows you to assign a post to a given language.
- setSync() : mixed
- Set `Sync` instance for this plugin. Can be `null` if not given.
- setTermLanguage() : mixed
- This method is called due to `Sync::created_term`. It allows you to assign a term to a given language.
- snapshotCurrentTranslations() : mixed
- Snapshot the current translations.
- splitTranslationEntries() : mixed
- Split a translation entry key into multiple parts. This is useful when using e.g. TranslatePress and we need to find translations from MO file which is divided into multiple "parts" like `<strong>Text</strong>: Another text`.
- switch() : mixed
- Switch to a given language code. Please do not use this function directly, use `switchToLanguage` instead!
- switchToLanguage() : mixed
- Open given language and get their context. Context = switch to the language.
- 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.
- syncTermAfterWpmlTranslation() : mixed
- After WPML linked a new term translation, apply PO translations and copy meta from the source term.
- 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.
- teardownTemporaryTextDomain() : mixed
- Teardown the known temporary text domain.
- termCopiedToAllOtherLanguages() : mixed
- This method is called due to `Sync::created_term`. It allows you to get a list of all translations of a term in an associate array.
- translatableStrings() : array<string|int, array<string|int, string>>
- Extract translatable strings from a given content. The returned array is a map of the original strings to the translatable strings.
- translateArray() : array<string|int, mixed>
- Translate a complete array to a given locale (recursively). This is mostly implemented by output buffer plugins like TranslatePress or Weglot.
- translateInput() : mixed
- Translate a given input from known translations (.po, .pot).
- translateStrings() : mixed
- Translate strings to a given locale. Do not use this function directly, use `translateArray` instead!
- unsetCurrentTranslations() : mixed
- Unset current translations.
- withSourceTranslationCatalog() : mixed
- Run a callback with the source-language PO/MO catalog snapshotted (same as `CopyContent::copy`).
- duplicateMeta() : mixed
- Listen to meta (term, post, ...) addition and copy.
- duplicatePost() : mixed
- A simple `get_post` => `wp_insert_post` wrapper.
- duplicateTerm() : mixed
- A simple `get_term` => `wp_insert_term` wrapper.
- duplicateTermMeta() : mixed
- Listen to term meta addition and copy.
- fetchObjectTermIdsWithoutFilters() : array<string|int, int>
- Read assigned term ids bypassing WPML `get_object_terms` filters.
- getSourceLanguage() : mixed
- Get the source language of a given element id and element type.
- resolveSourceTermsByTaxonomyForPostCopy() : array<string, array<string|int, int>>
- Resolve source taxonomy ids for {@see AbstractSyncPlugin::copyPostTaxonomies()} (WPML).
- translateStringFromMo() : array<string|int, mixed>
- Translate string from `.mo` file. Please consider to create a temporary text domain before!
- whileApplyingExternalSourceSync() : mixed
- Run callback while external-source sync writes the target translation only (no live meta fan-out).
- getConfiguredPostMetaCopyKeys() : array<string|int, string>|null
- Meta keys configured for copy sync on the post's type, if any.
Constants
MARKER_SPLIT_TRANSLATION_ENTRY
public
mixed
MARKER_SPLIT_TRANSLATION_ENTRY
= 'splitTranslationEntry'
TEMPORARY_TEXT_DOMAIN_PREFIX
public
mixed
TEMPORARY_TEXT_DOMAIN_PREFIX
= 'multilingual-temporary-text-domain'
Properties
$copyToOtherLanguageMap
`copyTermToOtherLanguage` and `copyPostToOtherLanguage` create a duplicate of a term and post. This map holds the mapping of original-ID to translation-ID. This map is filled with the translations like this:
protected
mixed
$copyToOtherLanguageMap
= ['post' => [], 'term' => []]
{
"post": {
"de": {
800: 801
}
}
}
$currentTranslationEntries
Current translations hold as an instance.
protected
mixed
$currentTranslationEntries
= null
$findI18nKeyOfTranslationCache
protected
mixed
$findI18nKeyOfTranslationCache
= []
$lockCurrentTranslations
protected
mixed
$lockCurrentTranslations
= false
$splitTranslationEntriesCache
Cache for split translation entries.
protected
SplObjectStorage<Translation_Entry, array<string|int, Translation_Entry>>
$splitTranslationEntriesCache
= []
$taxonomySourceResolutionExcludePostId
During `syncPostFromExternalSource()`, the duplicate post id excluded from WPML taxonomy sibling fallback (the in-progress translation must not supply term assignments as source).
protected
int|null
$taxonomySourceResolutionExcludePostId
= null
$translateArrayCache
protected
mixed
$translateArrayCache
= []
$applyingExternalSourceSync
True while `syncPostFromExternalSource()` / `syncTermFromExternalSource()` write target fields. Suppresses live `updated_*_meta` fan-out in `Sync` for those writes.
private
mixed
$applyingExternalSourceSync
= false
$disabledCopyAndSync
private
mixed
$disabledCopyAndSync
= false
$duplicateCreationInProgress
True while `sitepress->make_duplicate()` runs (Translation Dashboard duplicate).
private
mixed
$duplicateCreationInProgress
= false
Sync::save_post must not create extra language copies during this window.
$duplicateSourceTermsByMaster
Per-master taxonomy assignments captured at `icl_before_make_duplicate`.
private
array<int, array<string, array<string|int, int>>>
$duplicateSourceTermsByMaster
= []
WPML can clear or rewrite wp_term_relationships on the master post before DevOwl
copyPostTaxonomies() runs. The snapshot preserves ids that were still on the master at
duplicate start (typical stack: DE translation still wired to EN rcb-cookie-group term ids).
Consumed once when resolving source terms during resolveSourceTermsByTaxonomyForPostCopy().
master post id => taxonomy => term ids
$wpmlTermSaveInProgress
True while WPML taxonomy translation UI saves a term (`wp_ajax_wpml_save_term`).
private
mixed
$wpmlTermSaveInProgress
= false
Sync::created_term must not spawn copies in other languages during this window.
Methods
__construct()
C'tor.
public
__construct(string $domain[, string $moFile = null ][, mixed $overrideClass = null ]) : mixed
Parameters
- $domain : string
-
Original text domain where
post_titleand so on are translated - $moFile : string = null
-
Needed for
TemporaryTextDomain. E. g./var/www/html/wp-content/plugins/real-cookie-banner/languages/real-cookie-banner-%s.mo - $overrideClass : mixed = null
-
A class with a
getPotLanguagesmethod
Tags
beforeWpmlSaveTerm()
Mark WPML taxonomy term save so `Sync::created_term` does not recurse.
public
beforeWpmlSaveTerm() : mixed
copyPostTaxonomies()
Copy already existing taxonomies as it can be inserted with `tax_input` directly.
public
copyPostTaxonomies(int $from, int $to, array<string|int, string> $taxonomies, string $locale) : mixed
Additionally listen to term additions and copy.
Parameters
- $from : int
- $to : int
- $taxonomies : array<string|int, string>
-
Taxonomy keys to copy
- $locale : string
-
The destination locale
copyPostToOtherLanguage()
Translate given post to other language.
public
copyPostToOtherLanguage(mixed $locale, mixed $currentLanguage, mixed $post_id, mixed $meta, mixed $taxonomies) : int|bool
Parameters
- $locale : mixed
- $currentLanguage : mixed
- $post_id : mixed
- $meta : mixed
-
The meta keys to copy
- $taxonomies : mixed
-
The taxonomies to copy
Return values
int|bool —The new created post id
copyTermToOtherLanguage()
Translate given term to other language.
public
copyTermToOtherLanguage(mixed $locale, mixed $currentLanguage, mixed $term_id, mixed $taxonomy, mixed $meta) : int|bool
Parameters
- $locale : mixed
- $currentLanguage : mixed
- $term_id : mixed
- $taxonomy : mixed
- $meta : mixed
-
The meta keys to copy
Return values
int|bool —The new created term id
createTemporaryTextDomain()
Create a temporary text domain.
public
createTemporaryTextDomain(string $locale[, bool $force = false ]) : mixed
Parameters
- $locale : string
- $force : bool = false
determineImplementation()
Determine implementation class.
public
static determineImplementation([string $domain = '' ][, string $moFile = null ][, mixed $overrideClass = null ]) : AbstractLanguagePlugin
Parameters
- $domain : string = ''
- $moFile : string = null
-
Needed for
TemporaryTextDomain. E. g./var/www/html/wp-content/plugins/real-cookie-banner/languages/real-cookie-banner-%s.mo - $overrideClass : mixed = null
-
A class with a
overridemethod (arguments:locale)
Return values
AbstractLanguagePlugindisableCopyAndSync()
Disable sync mechanism of our language plugin as it is handled by `Sync.php`.
public
disableCopyAndSync(mixed $sync) : mixed
Parameters
- $sync : mixed
duplicatePostMeta()
Copy already existing meta as it can be inserted with `meta_input` directly.
public
duplicatePostMeta(int $from, int $to, array<string|int, string> $meta) : mixed
Additionally listen to term meta addition and copy.
Parameters
- $from : int
- $to : int
- $meta : array<string|int, string>
-
Meta keys to copy
endWpmlSaveTerm()
Clear the WPML taxonomy save flag after the AJAX handler finishes.
public
endWpmlSaveTerm() : mixed
filterMetaValue()
Apply a WordPress filter so a meta value can be modified for copy process to other languages.
public
filterMetaValue(string $type, int $from, int $to, string $meta_key, mixed $meta_value, string $locale) : mixed
Parameters
- $type : string
-
E. g. 'post'
- $from : int
-
Object id of source language item
- $to : int
-
Object id of destination language item
- $meta_key : string
- $meta_value : mixed
- $locale : string
-
Destination locale
filterWithExistingTranslatedTextDomain()
Filter a list of locales and check if translations from a PO/MO file exists.
public
filterWithExistingTranslatedTextDomain(array<string|int, string> $locales[, array<string|int, string> $skip = [] ]) : mixed
Parameters
- $locales : array<string|int, string>
- $skip : array<string|int, string> = []
-
Allows to skip locales and they will never be in the result, e.g. minimal translations; the codes need to be compatible with the WordPress locale format.
findI18nKeyOfTranslation()
The same as `findI18nKeyOfTranslationRaw`, but with caching enabled as this could be called very often.
public
findI18nKeyOfTranslation(string $input, bool &$found, array<string|int, string> &$contexts) : mixed
Parameters
- $input : string
- $found : bool
- $contexts : array<string|int, string>
findI18nKeyOfTranslationRaw()
Find an i18n key for `__()` from a given translated string.
public
findI18nKeyOfTranslationRaw(string $input, bool &$found, array<string|int, string> &$contexts) : mixed
Parameters
- $input : string
- $found : bool
-
Sets to
truewhen a translation got found - $contexts : array<string|int, string>
getActiveCountriesFlags()
Get the flags of all active languages.
public
getActiveCountriesFlags() : mixed
getActiveLanguages()
Get all active languages.
public
getActiveLanguages() : array<string|int, string>
Return values
array<string|int, string>getCountryFlag()
Get a `src` compatible link to the country flag.
public
getCountryFlag(mixed $locale) : string|false
Parameters
- $locale : mixed
Return values
string|falsegetCurrentLanguage()
Get current language.
public
getCurrentLanguage() : string
Return values
stringgetCurrentLanguageFallback()
Get current language or fallback to default language when the multilingual is in a state like "Show all languages" (option known in the admin toolbar).
public
getCurrentLanguageFallback() : mixed
getCurrentPostId()
Get current id of passed post id and fallback to passed id, when no translation found.
public
getCurrentPostId(mixed $id, mixed $post_type[, mixed $locale = null ]) : int
Parameters
- $id : mixed
- $post_type : mixed
- $locale : mixed = null
-
Get item of this language;
null= active language
Return values
intgetCurrentTermId()
Get the term id for `$locale`; adapters fall back to `$id` when no translation exists.
public
getCurrentTermId(mixed $id, mixed $taxonomy[, mixed $locale = null ]) : int
Parameters
- $id : mixed
- $taxonomy : mixed
- $locale : mixed = null
-
Target language code
Return values
intgetDefaultLanguage()
Get default language.
public
getDefaultLanguage() : string
Return values
stringgetLanguageSwitcher()
Get a language switcher for the current page.
public
getLanguageSwitcher() : array<string|int, array<string|int, mixed>>
Return values
array<string|int, array<string|int, mixed>>getLocalesBeforeSwitch()
List of locales before switching locale via `switchToLanguage`.
public
getLocalesBeforeSwitch() : mixed
getObjectTermIdsForPostLanguage()
Term ids assigned to a post in a specific language context (avoids WPML read fallbacks).
public
getObjectTermIdsForPostLanguage(int $postId, string $taxonomy[, string|null $locale = null ]) : array<string|int, int>
Parameters
- $postId : int
- $taxonomy : string
- $locale : string|null = null
-
When empty, uses the post's language
Return values
array<string|int, int>getOriginalPostId()
Get original id of passed post id.
public
getOriginalPostId(mixed $id, mixed $post_type) : int
Parameters
- $id : mixed
- $post_type : mixed
Return values
intgetOriginalTermId()
Get original id of passed term id.
public
getOriginalTermId(mixed $id, mixed $taxonomy) : int
Parameters
- $id : mixed
- $taxonomy : mixed
Return values
intgetOverrideClassInstance()
Get an instance of the `overrideClass`.
public
getOverrideClassInstance() : mixed
getPermalink()
Get the URL of a given URL for another locale.
public
getPermalink(mixed $url, mixed $locale) : string
Parameters
- $url : mixed
- $locale : mixed
Return values
stringgetPostLanguage()
Get language of passed post id.
public
getPostLanguage(mixed $id) : string
Parameters
- $id : mixed
Return values
string —Returns empty string if no language is set or cannot be determined, otherwise the locale
getPostTranslationIds()
Get all translations of a given post type.
public
getPostTranslationIds(mixed $id, mixed $post_type) : array<string|int, int>
Parameters
- $id : mixed
- $post_type : mixed
Return values
array<string|int, int>getSkipHTMLForTag()
Get the HTML attribute so the "dynamic" replacement gets disabled on frontend side. This can be useful for texts which are directly translated in PHP already and gets translated via JavaScript again.
public
getSkipHTMLForTag([mixed $force = false ]) : string
Parameters
- $force : mixed = false
-
Pass
trueto get the attribute and do not respectisCurrentlyInEditorPreview
Return values
stringgetSync()
Get `Sync` instance for this plugin. Can be `null` if not given.
public
getSync() : mixed
getTaxonomyTranslationIds()
Get all translations of a given taxonomy.
public
getTaxonomyTranslationIds(mixed $id, mixed $taxonomy) : array<string|int, int>
Parameters
- $id : mixed
- $taxonomy : mixed
Return values
array<string|int, int>getTemporaryTextDomainName()
Get the current temporary text domain name which can be used for `__` when e.g. inside `switchToLanguage`.
public
getTemporaryTextDomainName() : mixed
getTermLanguage()
Get language of passed term.
public
getTermLanguage(mixed $termTaxonomyId, mixed $taxonomy) : string
Parameters
- $termTaxonomyId : mixed
-
term_taxonomy_id(WPML element id); resolved toterm_idwhere needed - $taxonomy : mixed
Return values
string —Returns empty string if no language is set or cannot be determined, otherwise the locale
getTranslatedName()
Get translated name for a given locale.
public
getTranslatedName(mixed $locale) : string
Parameters
- $locale : mixed
Return values
stringgetWordPressCompatibleLanguageCode()
Get the WordPress compatible language code of a given locale.
public
getWordPressCompatibleLanguageCode(mixed $locale) : string
Parameters
- $locale : mixed
Return values
stringisActive()
Is a multilingual plugin active?
public
isActive() : mixed
isApplyingExternalSourceSync()
Whether `Sync::updated_postmeta()` / `Sync::updated_term_meta()` should skip.
public
isApplyingExternalSourceSync() : mixed
See whileApplyingExternalSourceSync().
isCurrentlyInEditorPreview()
Check if the translate plugin is currently in edit mode (preview).
public
isCurrentlyInEditorPreview() : bool
Return values
boolisExternalTranslationSyncDeferredForPost()
public
isExternalTranslationSyncDeferredForPost(mixed $postId) : mixed
Parameters
- $postId : mixed
isExternalTranslationSyncDeferredForTerm()
public
isExternalTranslationSyncDeferredForTerm(mixed $term_id, mixed $taxonomy) : mixed
Parameters
- $term_id : mixed
- $taxonomy : mixed
isPresent()
Check if WPML is active.
public
static isPresent() : mixed
iterateAllLanguagesContext()
Iterate all language contexts.
public
iterateAllLanguagesContext(callable $callback[, array<string|int, string> $skip = [] ]) : mixed
Parameters
- $callback : callable
-
Arguments: $locale, $currentLanguage
- $skip : array<string|int, string> = []
-
Skip locales
iterateOtherLanguagesContext()
Iterate all other languages than current one and get their context.
public
iterateOtherLanguagesContext(callable $callback) : mixed
Context = switch to the language.
Attention: If you are using switchToLanguage in a REST API call, please consider
to pass the _wp_http_referer parameter. E.g. TranslatePress checks if the
referer is an admin page and behaves differently.
Parameters
- $callback : callable
-
Arguments: $locale, $currentLanguage
lockCurrentTranslations()
Do not allow to take another snapshot of current translations.
public
lockCurrentTranslations([bool $state = false ]) : mixed
Parameters
- $state : bool = false
matchLanguageCodeFromWordPressCompatibleLocale()
Resolve the plugin language code (e.g. en, de) from a WordPress-compatible locale (e.g. en_US from {@see getWordPressCompatibleLanguageCode()}). Also accepts an already-short plugin code when it is listed in {@see getActiveLanguages()}.
public
matchLanguageCodeFromWordPressCompatibleLocale(string $wordpressCompatibleLocale) : mixed
Parameters
- $wordpressCompatibleLocale : string
maybePersistTranslation()
Maybe persist a translation in the database of available translations.
public
maybePersistTranslation(mixed $sourceContent, mixed $content, mixed $sourceLocale, mixed $targetLocale[, mixed $force = false ]) : mixed
Parameters
- $sourceContent : mixed
- $content : mixed
-
Pass
nullto delete the translation - $sourceLocale : mixed
- $targetLocale : mixed
- $force : mixed = false
-
Pass
trueto force persist the translation
onSetObjectTermsCopyPostTaxonomies()
Copy taxonomy assignments from a master post to its translations when terms are set on the master.
public
onSetObjectTermsCopyPostTaxonomies(int $object_id, array<string|int, int>|array<string|int, string> $terms, array<string|int, int> $tt_ids, string $taxonomy, bool $append) : mixed
Parameters
- $object_id : int
- $terms : array<string|int, int>|array<string|int, string>
- $tt_ids : array<string|int, int>
- $taxonomy : string
- $append : bool
postCopiedToAllOtherLanguages()
This method is called due to `Sync::save_post`. It allows you to get a list of all translations of a post in an associate array.
public
postCopiedToAllOtherLanguages(array<string|int, int> $translations) : mixed
Parameters
- $translations : array<string|int, int>
remapPostId()
Resolve a post id to its translation in `$locale`, if one should be stored on a translation post.
public
remapPostId(int $postId, string $referent_post_type, string $locale) : int
Adapters return the source id when no translation exists; this helper still accepts that id when
the referenced post already belongs to $locale (same idea as taxonomy remapping on translation
posts). Callers that store lists (e.g. comma-separated meta) loop and collect non-zero results.
Parameters
- $postId : int
-
Referenced post id
- $referent_post_type : string
-
Post type of the referenced post
- $locale : string
-
Target language code
Return values
int —Translated post id, or 0 when nothing valid applies in $locale
rest_prepare_post()
Add a `multilingual` section to a given post type.
public
rest_prepare_post(WP_REST_Response $response, WP_Post $post, WP_REST_Request $request) : mixed
Usage:
add_filter('rest_prepare_my_cpt', [$this->getCompLanguage(), 'rest_prepare_post'], 10, 3);
Parameters
- $response : WP_REST_Response
- $post : WP_Post
- $request : WP_REST_Request
Tags
rest_prepare_taxonomy()
Add a `multilingual` section to a given taxonomy.
public
rest_prepare_taxonomy(WP_REST_Response $response, WP_Term $term, WP_REST_Request $request) : mixed
Usage:
add_filter('rest_prepare_my_taxonomy', [$this->getCompLanguage(), 'rest_prepare_taxonomy'], 10, 3);
Parameters
- $response : WP_REST_Response
- $term : WP_Term
- $request : WP_REST_Request
Tags
setPostLanguage()
This method is called due to `Sync::save_post`. It allows you to assign a post to a given language.
public
setPostLanguage(int $postId, string $locale) : mixed
Parameters
- $postId : int
- $locale : string
setSync()
Set `Sync` instance for this plugin. Can be `null` if not given.
public
setSync(Sync $sync) : mixed
Parameters
- $sync : Sync
setTermLanguage()
This method is called due to `Sync::created_term`. It allows you to assign a term to a given language.
public
setTermLanguage(int $termId, string $locale) : mixed
Parameters
- $termId : int
- $locale : string
snapshotCurrentTranslations()
Snapshot the current translations.
public
snapshotCurrentTranslations([bool $force = false ]) : mixed
Parameters
- $force : bool = false
splitTranslationEntries()
Split a translation entry key into multiple parts. This is useful when using e.g. TranslatePress and we need to find translations from MO file which is divided into multiple "parts" like `<strong>Text</strong>: Another text`.
public
splitTranslationEntries(array<string|int, Translation_Entry> &$entriesToSplit) : mixed
Parameters
- $entriesToSplit : array<string|int, Translation_Entry>
Tags
switch()
Switch to a given language code. Please do not use this function directly, use `switchToLanguage` instead!
public
switch(mixed $locale) : mixed
Parameters
- $locale : mixed
switchToLanguage()
Open given language and get their context. Context = switch to the language.
public
switchToLanguage(string $locale, callable $callback) : mixed
Attention: If you are using switchToLanguage in a REST API call, please consider
to pass the _wp_http_referer parameter. E.g. TranslatePress checks if the
referer is an admin page and behaves differently.
Parameters
- $locale : string
- $callback : callable
-
Arguments: $locale, $currentLanguage, $temporaryTextDomain
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
syncTermAfterWpmlTranslation()
After WPML linked a new term translation, apply PO translations and copy meta from the source term.
public
syncTermAfterWpmlTranslation(int $term_id, int $tt_id, string $taxonomy) : mixed
Runs on created_term (priority 20), after WPML's create_term language assignment (priority 1).
Uses wpml_element_language_details instead of $_POST so CLI/API paths work too.
Parameters
- $term_id : int
- $tt_id : int
- $taxonomy : string
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
teardownTemporaryTextDomain()
Teardown the known temporary text domain.
public
teardownTemporaryTextDomain() : mixed
termCopiedToAllOtherLanguages()
This method is called due to `Sync::created_term`. It allows you to get a list of all translations of a term in an associate array.
public
termCopiedToAllOtherLanguages(array<string|int, int> $translations) : mixed
Parameters
- $translations : array<string|int, int>
translatableStrings()
Extract translatable strings from a given content. The returned array is a map of the original strings to the translatable strings.
public
translatableStrings(mixed $content) : array<string|int, array<string|int, string>>
Parameters
- $content : mixed
Return values
array<string|int, array<string|int, string>>translateArray()
Translate a complete array to a given locale (recursively). This is mostly implemented by output buffer plugins like TranslatePress or Weglot.
public
translateArray(array<string|int, mixed> $content[, array<string|int, string> $skipKeys = [] ][, string $locale = null ][, array<string|int, string> $context = null ]) : array<string|int, mixed>
Parameters
- $content : array<string|int, mixed>
- $skipKeys : array<string|int, string> = []
- $locale : string = null
- $context : array<string|int, string> = null
Return values
array<string|int, mixed>translateInput()
Translate a given input from known translations (.po, .pot).
public
translateInput(string $input[, array<string|int, string> $contexts = null ]) : mixed
Parameters
- $input : string
- $contexts : array<string|int, string> = null
translateStrings()
Translate strings to a given locale. Do not use this function directly, use `translateArray` instead!
public
translateStrings(mixed &$content, mixed $locale[, mixed $context = null ]) : mixed
Parameters
- $content : mixed
-
This parameter needs to be passed as reference map, see also
translateArray. The implementation needs to update the references correctly - $locale : mixed
- $context : mixed = null
unsetCurrentTranslations()
Unset current translations.
public
unsetCurrentTranslations() : mixed
withSourceTranslationCatalog()
Run a callback with the source-language PO/MO catalog snapshotted (same as `CopyContent::copy`).
public
withSourceTranslationCatalog(string $sourceLocale, callable $callback) : mixed
While locked, translateInput() resolves msgids from the snapshot and translates via the active
target-language text domain inside nested switchToLanguage() calls.
Parameters
- $sourceLocale : string
- $callback : callable
duplicateMeta()
Listen to meta (term, post, ...) addition and copy.
protected
duplicateMeta(string $type, int $from, int $to, array<string|int, string> $meta) : mixed
Parameters
- $type : string
-
E. g. 'post'
- $from : int
- $to : int
- $meta : array<string|int, string>
-
Meta keys to copy
duplicatePost()
A simple `get_post` => `wp_insert_post` wrapper.
protected
duplicatePost(WP_Post $post) : mixed
Parameters
- $post : WP_Post
duplicateTerm()
A simple `get_term` => `wp_insert_term` wrapper.
protected
duplicateTerm(WP_Term $term, string $taxonomy) : mixed
Parameters
- $term : WP_Term
- $taxonomy : string
duplicateTermMeta()
Listen to term meta addition and copy.
protected
duplicateTermMeta(int $from, int $to, array<string|int, string> $meta) : mixed
Parameters
- $from : int
- $to : int
- $meta : array<string|int, string>
-
Meta keys to copy
fetchObjectTermIdsWithoutFilters()
Read assigned term ids bypassing WPML `get_object_terms` filters.
protected
fetchObjectTermIdsWithoutFilters(int $postId, string $taxonomy) : array<string|int, int>
Parameters
- $postId : int
- $taxonomy : string
Return values
array<string|int, int>getSourceLanguage()
Get the source language of a given element id and element type.
protected
getSourceLanguage(int $element_id, string $element_type[, mixed $fallback = null ]) : mixed
Parameters
- $element_id : int
- $element_type : string
- $fallback : mixed = null
resolveSourceTermsByTaxonomyForPostCopy()
Resolve source taxonomy ids for {@see AbstractSyncPlugin::copyPostTaxonomies()} (WPML).
protected
resolveSourceTermsByTaxonomyForPostCopy(int $from, array<string|int, string> $taxonomies) : array<string, array<string|int, int>>
Three fallbacks, first non-empty wins:
-
Live read (AbstractSyncPlugin::resolveSourceTermsByTaxonomyForPostCopy()):
fetchObjectTermIdsWithoutFilters()on$from. Succeeds when relationships are still on the master at copy time (normal duplicate, or cross-language term ids still stored). -
Duplicate snapshot (
$duplicateSourceTermsByMaster): ids captured on$frominicl_before_make_duplicatebefore WPML clears the master, then unset here. Needed when step 1 is empty because WPML already removed assignments (common for DE → EN duplicate of a DE cookie wired to EN group terms). Empty when no taxonomies were on the master at hook time or this master was not part of the current duplicate run. -
Translation sibling (trid scan below): read from another post in the same WPML trid when steps 1 and 2 are empty, but a sibling translation still has assignments (e.g. master already cleared, EN row not deleted yet). Does not help when every translation in the trid has empty taxonomies (e.g. EN master removed and only DE remains) — then step 2 must have captured terms at
icl_before_make_duplicate. Snapshot fixes “WPML cleared the master between hook and copy”; siblings fix “master empty, another language row still has groups”.
Parameters
- $from : int
-
Source post id (WPML master for the duplicate being built)
- $taxonomies : array<string|int, string>
-
Taxonomy slugs from Sync post configuration
Return values
array<string, array<string|int, int>> —taxonomy slug => term ids to remap onto the target locale
translateStringFromMo()
Translate string from `.mo` file. Please consider to create a temporary text domain before!
protected
translateStringFromMo(string $content, string $targetLocale[, array<string|int, string> $context = null ]) : array<string|int, mixed>
Parameters
- $content : string
- $targetLocale : string
- $context : array<string|int, string> = null
Return values
array<string|int, mixed> —[$found: boolean, $content: string]
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
getConfiguredPostMetaCopyKeys()
Meta keys configured for copy sync on the post's type, if any.
private
getConfiguredPostMetaCopyKeys(Sync $sync, int $post_id) : array<string|int, string>|null
Parameters
- $sync : Sync
- $post_id : int