Plugin Author:
As a good start, In case of WPML compatible workspace something like this should do the trick to reach all siblings WPML/ Translated posts and do whatever your plugin in does with the original post.
First call, check if there is translations, just a root function example for the second function below:
function ua_wpml_clone stuff($post_id){
$translated_ids = ua_wpml_get_translated_ids($post_id);
if(!isset($translated_ids[0])){
// No translations;
} else {
// Loop the $translated_ids and clone each of them
}
}
The WPML check function:
REMARK, You must pass post_type, and the post_type name, in this example a Woocommerce product is in use, and pasted directly into the function ('post_product'
and 'product'
) for easier understanding this “$trid
” is in use.
function ua_wpml_get_translated_ids($post_id){
global $sitepress;
$translated_ids = Array();
if(!isset($sitepress)) return $translated_ids;
$trid = $sitepress->get_element_trid($post_id, 'post_product');
$translations = $sitepress->get_element_translations($trid, 'product');
foreach( $translations as $lang=>$translation){
$translated_ids[] = $translation->element_id;
}
return $translated_ids;
}
Hope this is a good start. Great if your plugin would be WPML friendly!