Skip to content

Commit 2fb187f

Browse files
committed
Add WPIncludesCommand
1 parent 41eca92 commit 2fb187f

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

command.php

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use TypistTech\ImageOptimizeCommand\CLI\Commands\RestoreCommand;
1515
use TypistTech\ImageOptimizeCommand\CLI\Commands\ThemesCommand;
1616
use TypistTech\ImageOptimizeCommand\CLI\Commands\WPAdminCommand;
17+
use TypistTech\ImageOptimizeCommand\CLI\Commands\WPIncludesCommand;
1718
use WP_CLI;
1819

1920
if (! class_exists('WP_CLI')) {
@@ -33,3 +34,4 @@
3334
WP_CLI::add_command('image-optimize plugins', PluginsCommand::class);
3435
WP_CLI::add_command('image-optimize mu-plugins', MUPluginsCommand::class);
3536
WP_CLI::add_command('image-optimize themes', ThemesCommand::class);
37+
WP_CLI::add_command('image-optimize wp-includes', WPIncludesCommand::class);

src/CLI/Commands/CommandNamespace.php

+3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
*
3838
* # Find and optimize images under wp-admin.
3939
* $ wp image-optimize wp-admin
40+
*
41+
* # Find and optimize images under wp-includes.
42+
* $ wp image-optimize wp-includes
4043
*/
4144
class CommandNamespace extends BaseCommandNamespace
4245
{
+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace TypistTech\ImageOptimizeCommand\CLI\Commands;
5+
6+
use Symfony\Component\Filesystem\Filesystem;
7+
use Symfony\Component\Finder\Finder;
8+
use TypistTech\ImageOptimizeCommand\CLI\LoggerFactory;
9+
use TypistTech\ImageOptimizeCommand\Operations\Find;
10+
use TypistTech\ImageOptimizeCommand\Operations\Optimize;
11+
use TypistTech\ImageOptimizeCommand\OptimizerChainFactory;
12+
use WP_CLI;
13+
14+
class WPIncludesCommand
15+
{
16+
/**
17+
* Find and optimize images under wp-includes.
18+
*
19+
* ## OPTIONS
20+
*
21+
* [--extensions=<extensions>]
22+
* : File types to optimize, separated by commas.
23+
* Default: gif,jpeg,jpg,png
24+
*
25+
* ## EXAMPLES
26+
*
27+
* # Find and optimize images under wp-includes
28+
* $ wp image-optimize wp-includes
29+
*
30+
* # Find and optimize SVGs,PNGs under wp-includes
31+
* $ wp image-optimize wp-includes --extensions=svg,png
32+
*/
33+
public function __invoke($_, $assocArgs): void
34+
{
35+
if (! defined('ABSPATH')) {
36+
WP_CLI::error("Constant 'ABSPATH' not defined. Is WordPress loaded?");
37+
}
38+
39+
if (! defined('WPINC')) {
40+
WP_CLI::error("Constant 'WPINC' not defined. Is WordPress loaded?");
41+
}
42+
43+
$directory = constant('ABSPATH') . constant('WPINC');
44+
45+
$findCommand = new FindCommand();
46+
$findCommand([$directory], $assocArgs);
47+
}
48+
}

0 commit comments

Comments
 (0)