Skip to content

Commit f0bd7ca

Browse files
committed
WP_CLI adjusted
1 parent 2ead1fb commit f0bd7ca

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

MultisiteLanguageSwitcher.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,5 @@ function msls_get_query(): ?\lloc\Msls\MslsOptionsQuery {
231231
}
232232

233233
lloc\Msls\MslsPlugin::init();
234-
if ( defined( 'WP_CLI' ) && WP_CLI ) {
235-
lloc\Msls\MslsCli::init();
236-
}
234+
lloc\Msls\MslsCli::init();
237235
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"scripts": {
3737
"test": "vendor/bin/phpunit",
3838
"coverage": "@php -d xdebug.mode=coverage vendor/bin/phpunit --coverage-html tests/coverage",
39-
"analyze": "vendor/bin/phpstan analyze",
39+
"phpstan": "vendor/bin/phpstan analyze",
4040
"playwright": "npx playwright test",
4141
"php74": "phpcs -p ./*.php includes/ --standard=vendor/phpcompatibility/php-compatibility/PHPCompatibility --runtime-set testVersion 7.4",
4242
"php81": "phpcs -p ./*.php includes/ --standard=vendor/phpcompatibility/php-compatibility/PHPCompatibility --runtime-set testVersion 8.1",

includes/MslsCli.php

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,34 @@
22

33
namespace lloc\Msls;
44

5-
class MslsCli {
5+
final class MslsCli {
66

77
public static function init(): void {
8-
\WP_CLI::add_command( 'msls blog', array( __CLASS__, 'blog' ) );
8+
if ( defined( 'WP_CLI' ) && WP_CLI ) {
9+
\WP_CLI::add_command( 'msls', new self() );
10+
}
911
}
1012

13+
/**
14+
* Get the first blog that has a specific locale set.
15+
*
16+
* ## OPTIONS
17+
*
18+
* <locale>
19+
* : The locale e.g. de_DE.
20+
*
21+
* ## EXAMPLES
22+
*
23+
* $ wp msls blog <locale>
24+
*/
1125
public function blog( $args, $assoc_args ): void {
12-
$locale = $args[0] ?? $assoc_args['locale'] ?? null;
13-
14-
if ( is_null( $locale ) ) {
15-
\WP_CLI::error( 'Please, provide a locale!' );
16-
return;
17-
}
26+
list( $locale ) = $args;
27+
$blog = msls_blog( $locale );
1828

19-
$blog = msls_blog( $locale );
2029
if ( is_null( $blog ) ) {
21-
\WP_CLI::error( sprintf( 'No blog with locale %s found!', esc_attr( $locale ) ) );
22-
return;
30+
\WP_CLI::error( sprintf( 'No blog with locale %1$s found!', esc_attr( $locale ) ) );
2331
}
2432

25-
\WP_CLI::line( sprintf( 'Blog ID %$1d has locale %2s!', $blog->userblog_id, esc_attr( $locale ) ) );
33+
\WP_CLI::success( sprintf( 'Blog ID %1$d has locale %2$s!', $blog->userblog_id, esc_attr( $locale ) ) );
2634
}
2735
}

0 commit comments

Comments
 (0)