-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathSite_Switch_Language_Command.php
More file actions
47 lines (38 loc) · 1017 Bytes
/
Site_Switch_Language_Command.php
File metadata and controls
47 lines (38 loc) · 1017 Bytes
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
<?php
class Site_Switch_Language_Command extends WP_CLI\CommandWithTranslation {
protected $obj_type = 'core';
/**
* Activates a given language.
*
* ## OPTIONS
*
* <language>
* : Language code to activate.
*
* ## EXAMPLES
*
* $ wp site switch-language ja
* Success: Language activated.
*
* @throws WP_CLI\ExitException
*
* @param array{0: string} $args Positional arguments.
* @param array<mixed> $assoc_args Associative arguments.
*/
public function __invoke( $args, $assoc_args ) {
list( $language_code ) = $args;
$available = $this->get_installed_languages();
if ( ! in_array( $language_code, $available, true ) ) {
WP_CLI::error( 'Language not installed.' );
}
if ( 'en_US' === $language_code ) {
$language_code = '';
}
if ( get_locale() === $language_code ) {
WP_CLI::warning( "Language '{$language_code}' already active." );
return;
}
update_option( 'WPLANG', $language_code );
WP_CLI::success( 'Language activated.' );
}
}