Skip to content

Commit 7c9bef9

Browse files
committed
Add MUPluginsCommand
1 parent ec8a527 commit 7c9bef9

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

command.php

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use TypistTech\ImageOptimizeCommand\CLI\Commands\BatchCommand;
99
use TypistTech\ImageOptimizeCommand\CLI\Commands\CommandNamespace;
1010
use TypistTech\ImageOptimizeCommand\CLI\Commands\FindCommand;
11+
use TypistTech\ImageOptimizeCommand\CLI\Commands\MUPluginsCommand;
1112
use TypistTech\ImageOptimizeCommand\CLI\Commands\PluginsCommand;
1213
use TypistTech\ImageOptimizeCommand\CLI\Commands\ResetCommand;
1314
use TypistTech\ImageOptimizeCommand\CLI\Commands\RestoreCommand;
@@ -29,3 +30,4 @@
2930
WP_CLI::add_command('image-optimize find', FindCommand::class);
3031
WP_CLI::add_command('image-optimize wp-admin', WPAdminCommand::class);
3132
WP_CLI::add_command('image-optimize plugins', PluginsCommand::class);
33+
WP_CLI::add_command('image-optimize mu-plugins', MUPluginsCommand::class);

src/CLI/Commands/CommandNamespace.php

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
* # Find and optimize images under a given directory.
2727
* $ wp image-optimize find /path/to/my/directory
2828
*
29+
* # Find and optimize images under wp-content/mu-plugins
30+
* $ wp image-optimize mu-plugins
31+
*
2932
* # Find and optimize images under wp-content/plugins.
3033
* $ wp image-optimize plugins
3134
*

src/CLI/Commands/MUPluginsCommand.php

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace TypistTech\ImageOptimizeCommand\CLI\Commands;
5+
6+
use WP_CLI;
7+
8+
class MUPluginsCommand
9+
{
10+
/**
11+
* Find and optimize images under wp-content/mu-plugins.
12+
*
13+
* ## OPTIONS
14+
*
15+
* [--extensions=<extensions>]
16+
* : File types to optimize, separated by commas.
17+
* Default: gif,jpeg,jpg,png
18+
*
19+
* ## EXAMPLES
20+
*
21+
* # Find and optimize images under wp-content/mu-plugins
22+
* $ wp image-optimize mu-plugins
23+
*
24+
* # Find and optimize SVGs,PNGs under wp-content/mu-plugins
25+
* $ wp image-optimize mu-plugins --extensions=svg,png
26+
*/
27+
public function __invoke($_, $assocArgs): void
28+
{
29+
if (! defined('WPMU_PLUGIN_DIR')) {
30+
WP_CLI::error("Constant 'WPMU_PLUGIN_DIR' not defined. Is WordPress loaded?");
31+
}
32+
33+
$directory = constant('WPMU_PLUGIN_DIR');
34+
35+
$findCommand = new FindCommand();
36+
$findCommand([$directory], $assocArgs);
37+
}
38+
}

0 commit comments

Comments
 (0)