PluginProbe ʕ •ᴥ•ʔ
Robin Image Optimizer – Unlimited Image Optimization, WebP & AVIF / trunk
Robin Image Optimizer – Unlimited Image Optimization, WebP & AVIF vtrunk
2.0.5 trunk 1.3.7 1.4.0 1.4.1 1.4.2 1.4.6 1.5.0 1.5.3 1.5.6 1.5.8 1.6.5 1.6.6 1.6.9 1.7.0 1.7.4 1.8.1 1.8.2 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4
robin-image-optimizer / libs / addons / includes / classes / class.wpcli-optimize.php
robin-image-optimizer / libs / addons / includes / classes Last commit date
format 3 months ago helpers 5 months ago models 5 months ago webp 3 months ago class.backup.php 5 months ago class.custom-folders.php 5 months ago class.folder-image.php 5 months ago class.folder.php 5 months ago class.folders-list-table.php 5 months ago class.gallery-nextgen.php 5 months ago class.image-nextgen.php 5 months ago class.image-statistic-folders.php 5 months ago class.image-statistic-nextgen.php 5 months ago class.wpcli-optimize.php 5 months ago index.php 5 months ago
class.wpcli-optimize.php
136 lines
1 <?php
2
3 // Exit if accessed directly
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit;
6 }
7
8 /**
9 * WP CLI commands for optimize
10 *
11 * @version 1.0
12 */
13 class WRIO_CLI_Commands {
14
15 /**
16 * Start optimization
17 *
18 * ## OPTIONS
19 *
20 * <scope>
21 * : What to optimize?
22 *
23 * ## EXAMPLES
24 *
25 * wp robin optimize media-library
26 * wp robin optimize custom-folders
27 * wp robin optimize nextgen
28 *
29 * @when after_wp_load
30 */
31 public function optimize( $args, $assoc_args ) {
32 list( $scope ) = $args;
33 $process_running = WRIO_Plugin::app()->getPopulateOption( 'process_running', $scope );
34
35 if ( ! $process_running ) {
36 $processing = wrio_get_processing_class( $scope );
37 if ( $scope && is_object( $processing ) ) {
38 WP_CLI::log( "Scope: {$scope}" );
39 $push_items = $processing->push_items();
40 if ( $push_items ) {
41 WP_CLI::log( "Items pushed: {$push_items}" );
42 WRIO_Plugin::app()->updatePopulateOption( 'process_running', $scope );
43 $processing->save()->dispatch();
44 WP_CLI::log( 'Start optimize' );
45 }
46 } else {
47 WP_CLI::error( 'Undefined scope' );
48 }
49 } else {
50 WP_CLI::error( 'Optimize already running!' );
51 }
52 }
53
54 /**
55 * Stop optimization
56 *
57 * ## OPTIONS
58 *
59 * <scope>
60 * : What to stop to optimize?
61 *
62 * ## EXAMPLES
63 *
64 * wp robin stop media-library
65 * wp robin stop custom-folders
66 * wp robin stop nextgen
67 *
68 * @when after_wp_load
69 */
70 public function stop( $args, $assoc_args ) {
71 list( $scope ) = $args;
72
73 $process_running = WRIO_Plugin::app()->getPopulateOption( 'process_running', $scope );
74
75 if ( $process_running ) {
76 $processing = wrio_get_processing_class( $scope );
77 if ( $scope && $processing ) {
78 WP_CLI::log( "Current scope: {$scope}" );
79 WRIO_Plugin::app()->updatePopulateOption( 'process_running', false );
80 $processing->cancel_process();
81 WP_CLI::log( "Processing scope '{$scope}' is canceled!" );
82 } else {
83 WP_CLI::error( 'Undefined scope' );
84 }
85 } else {
86 WP_CLI::error( 'Optimize not running!' );
87 }
88 }
89
90 /**
91 * Start optimization
92 *
93 * ## OPTIONS
94 *
95 * <scope>
96 * : What to show status?
97 *
98 * ## EXAMPLES
99 *
100 * wp robin status media-library
101 * wp robin status custom-folders
102 * wp robin status nextgen
103 *
104 * @when after_wp_load
105 */
106 public function status( $args, $assoc_args ) {
107 list( $scope ) = $args;
108
109 $process_running = WRIO_Plugin::app()->getPopulateOption( 'process_running', false );
110
111 if ( $scope ) {
112 $unoptimized = '';
113 switch ( $scope ) {
114 case 'media-library':
115 $unoptimized = WRIO_Image_Statistic::get_unoptimized_count();
116 break;
117 case 'custom-folders':
118 $unoptimized = WRIO_Image_Statistic_Folders::get_unoptimized_count();
119 break;
120 case 'nextgen':
121 $unoptimized = WRIO_Image_Statistic_Nextgen::get_unoptimized_count();
122 break;
123 }
124
125 WP_CLI::log( "Scope: {$scope}" );
126 WP_CLI::log( 'Status: ' . ( $process_running ? 'running' : 'stopped' ) );
127 WP_CLI::log( "Remains to optimize: {$unoptimized}" );
128
129 } else {
130 WP_CLI::error( 'Undefined scope' );
131 }
132 }
133 }
134
135 WP_CLI::add_command( 'robin', 'WRIO_CLI_Commands' );
136