Skip to content

Commit 41eca92

Browse files
committed
Add ThemesCommand
1 parent 7c9bef9 commit 41eca92

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

command.php

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use TypistTech\ImageOptimizeCommand\CLI\Commands\PluginsCommand;
1313
use TypistTech\ImageOptimizeCommand\CLI\Commands\ResetCommand;
1414
use TypistTech\ImageOptimizeCommand\CLI\Commands\RestoreCommand;
15+
use TypistTech\ImageOptimizeCommand\CLI\Commands\ThemesCommand;
1516
use TypistTech\ImageOptimizeCommand\CLI\Commands\WPAdminCommand;
1617
use WP_CLI;
1718

@@ -31,3 +32,4 @@
3132
WP_CLI::add_command('image-optimize wp-admin', WPAdminCommand::class);
3233
WP_CLI::add_command('image-optimize plugins', PluginsCommand::class);
3334
WP_CLI::add_command('image-optimize mu-plugins', MUPluginsCommand::class);
35+
WP_CLI::add_command('image-optimize themes', ThemesCommand::class);

src/CLI/Commands/CommandNamespace.php

+3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
* # Find and optimize images under wp-content/plugins.
3333
* $ wp image-optimize plugins
3434
*
35+
* # Find and optimize images under wp-content/themes
36+
* $ wp image-optimize themes
37+
*
3538
* # Find and optimize images under wp-admin.
3639
* $ wp image-optimize wp-admin
3740
*/

src/CLI/Commands/ThemesCommand.php

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace TypistTech\ImageOptimizeCommand\CLI\Commands;
5+
6+
class ThemesCommand
7+
{
8+
/**
9+
* Find and optimize images under wp-content/themes.
10+
*
11+
* ## OPTIONS
12+
*
13+
* [--extensions=<extensions>]
14+
* : File types to optimize, separated by commas.
15+
* Default: gif,jpeg,jpg,png
16+
*
17+
* ## EXAMPLES
18+
*
19+
* # Find and optimize images under wp-content/themes
20+
* $ wp image-optimize themes
21+
*
22+
* # Find and optimize SVGs,PNGs under wp-content/themes
23+
* $ wp image-optimize themes --extensions=svg,png
24+
*/
25+
public function __invoke($_, $assocArgs): void
26+
{
27+
$directory = get_theme_root();
28+
29+
$findCommand = new FindCommand();
30+
$findCommand([$directory], $assocArgs);
31+
}
32+
}

0 commit comments

Comments
 (0)