class-wpml-change-string-language-select.php
1.52 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
66
<?php
class WPML_Change_String_Language_Select {
/**
* @var wpdb
*/
private $wpdb;
/**
* @var SitePress
*/
private $sitepress;
/**
* @param wpdb $wpdb
* @param SitePress $sitepress
*/
public function __construct( wpdb $wpdb, SitePress $sitepress ) {
$this->wpdb = $wpdb;
$this->sitepress = $sitepress;
}
public function show() {
$lang_selector = new WPML_Simple_Language_Selector( $this->sitepress );
echo $lang_selector->render(
array(
'id' => 'icl_st_change_lang_selected',
'class' => 'wpml-select2-button',
'please_select_text' => __( 'Change the language of selected strings', 'wpml-string-translation' ),
'disabled' => true,
)
);
}
/**
* @param int[] $strings
* @param string $lang
*
* @return array
*/
public function change_language_of_strings( $strings, $lang ) {
$package_translation = new WPML_Package_Helper();
$response = $package_translation->change_language_of_strings( $strings, $lang );
if ( $response['success'] ) {
$strings_in = implode( ',', $strings );
$update_query = "UPDATE {$this->wpdb->prefix}icl_strings SET language=%s WHERE id IN ($strings_in)";
$update_prepare = $this->wpdb->prepare( $update_query, $lang );
$this->wpdb->query( $update_prepare );
$response['success'] = true;
foreach ( $strings as $string ) {
icl_update_string_status( $string );
}
do_action( 'wpml_st_language_of_strings_changed', $strings );
}
return $response;
}
}