4
4
5
5
use NewfoldLabs \WP \Module \Performance \NFD_WPCLI ;
6
6
use NewfoldLabs \WP \Module \Performance \Images \ImageSettings ;
7
+ use function NewfoldLabs \WP \ModuleLoader \container ;
7
8
8
9
/**
9
10
* Handles WP-CLI commands for Image Optimization settings.
@@ -17,6 +18,21 @@ class ImageCommandHandler {
17
18
*/
18
19
private const VALID_STATUSES = array ( 'on ' , 'off ' );
19
20
21
+ /**
22
+ * Container.
23
+ *
24
+ * @var object Container
25
+ */
26
+ private $ container ;
27
+
28
+
29
+ /**
30
+ * Class constructor.
31
+ */
32
+ public function __construct () {
33
+ $ this ->container = container ();
34
+ }
35
+
20
36
/**
21
37
* Toggles the bulk optimization setting.
22
38
*
@@ -149,9 +165,9 @@ public function webp_preference( $args ) {
149
165
public function all ( $ args ) {
150
166
$ status = $ this ->validate_status ( isset ( $ args [0 ] ) ? $ args [0 ] : null );
151
167
$ enabled = ( 'on ' === $ status );
152
- $ settings = ImageSettings::get ();
168
+ $ settings = ImageSettings::get ( $ this -> container );
153
169
$ this ->set_all_values ( $ settings , $ enabled );
154
- ImageSettings::update ( $ settings );
170
+ ImageSettings::update ( $ settings, $ this -> container );
155
171
/* translators: %s is the on/off status. */
156
172
NFD_WPCLI ::success ( sprintf ( __ ( 'All image optimization settings have been turned %s. ' , 'wp-module-performance ' ), $ status ) );
157
173
}
@@ -166,7 +182,7 @@ public function all( $args ) {
166
182
*/
167
183
private function toggle_setting ( $ setting , $ status ) {
168
184
$ enabled = ( 'on ' === $ status );
169
- $ settings = ImageSettings::get ();
185
+ $ settings = ImageSettings::get ( $ this -> container );
170
186
171
187
// If a feature is turned on (except for the "all" command), enable overall image optimization.
172
188
if ( $ enabled ) {
@@ -184,7 +200,7 @@ private function toggle_setting( $setting, $status ) {
184
200
$ settings ['auto_optimized_uploaded_images ' ]['auto_delete_original_image ' ] = false ;
185
201
}
186
202
187
- ImageSettings::update ( $ settings );
203
+ ImageSettings::update ( $ settings, $ this -> container );
188
204
189
205
NFD_WPCLI ::success (
190
206
sprintf (
0 commit comments