|
| 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