Hi,
I have following scenario:
1- i create main Recipe language in arabic
2- with two different embed cred form buttons i can create secondary languages RU or EN
3-once one secondary language get created after button Submission i edit it and translate the cintent.
The issue is when i edit the main language AR all translation content of secondary languages i have made get deleted and the original language show instead. This way all the content of secondary languages will need to be edited again which is not ok.
I am using following snippets to manage the process described above.
<?php
toolset_snippet_security_check() or die( 'Direct access is not allowed' );
/**
* New custom code snippet.
*/
function wpml_make_post_duplicate_language( $master_post_id, $lang_to ) {
global $sitepress;
$master_post = get_post( $master_post_id );
if ( 'auto-draft' === $master_post->post_status || 'revision' === $master_post->post_type ) {
return;
}
$active_langs = $sitepress->get_active_languages();
if (array_key_exists($lang_to, $active_langs)) {
$trid = $sitepress->get_element_trid( $master_post->ID, 'post_' . $master_post->post_type );
$lang_from = $sitepress->get_source_language_by_trid( $trid );
if ( $lang_from == $lang_to ) {
return;
}
$sitepress->make_duplicate( $master_post_id, $lang_to );
}
}
add_action( 'wpml_make_post_duplicate_lang', 'wpml_make_post_duplicate_language', 10, 2 );
<?php
toolset_snippet_security_check() or die( 'Direct access is not allowed' );
/**
* New custom code snippet.
*/
function quick_duplicate_save_data_action( $post_id, $form_data ){
$form_langs = array(
383 => 'en',
404 => 'ru',
);
if( isset( $form_langs[$form_data['id']] ) ) {
global $sitepress;
$lang_to = $form_langs[$form_data['id']];
do_action( 'wpml_make_post_duplicate_lang', $post_id, $lang_to );
}
}
add_action( 'cred_save_data', 'quick_duplicate_save_data_action', 10, 2 );
You can login to the site and try modify one of the posts to secondary languages and after that try to edit the main AR language.. The secondary languages will have cintent from original again.
Here you can see the Recipes
hidden link
Here you can find the snippets: 11 + 12
hidden link
A ticket from before connected to this topic : https://toolset.com/forums/topic/duplicate-translation-for-specific-language-with-cred-form/