wpml.php
1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
if ( ! defined( 'ABSPATH' ) ) exit;
if( !is_plugin_active( 'sitepress-multilingual-cms/sitepress.php' ) ){
return;
}
class ACUI_WPML{
function __construct(){
}
function hooks(){
add_filter( 'acui_import_email_body_source', array( $this, 'translated_body' ), 10, 5 );
add_filter( 'acui_import_email_subject_source', array( $this, 'translated_subject' ), 10, 5 );
}
function get_translated_template( $template_id, $locale ){
$translated_template_id = apply_filters( 'wpml_object_id', $template_id, 'acui_email_template', false, $locale );
if( empty( $translated_template_id ) )
return false;
return get_post( $translated_template_id );
}
function translated_body( $body, $headers, $data, $created, $user_id ){
$locale = ACUI_Helper::get_value_from_row( 'locale', $headers, $data );
if( empty( $locale ) )
$locale = apply_filters( 'wpml_current_language', NULL );
$template_id = get_option( "acui_mail_template_id" );
$locale = substr( $locale, 0, 2 );
$translated_template = $this->get_translated_template( $template_id, $locale );
if( empty( $translated_template ) )
return $body;
return $translated_template->post_content;
}
function translated_subject( $body, $headers, $data, $created, $user_id ){
$locale = ACUI_Helper::get_value_from_row( 'locale', $headers, $data, $user_id );
if( empty( $locale ) )
return $body;
$template_id = get_option( "acui_mail_template_id" );
$locale = substr( $locale, 0, 2 );
$translated_template = $this->get_translated_template( $template_id, $locale );
if( empty( $translated_template ) )
return $body;
return $translated_template->post_title;
}
}
$acui_wpml = new ACUI_WPML();
$acui_wpml->hooks();