Skip to content

Commit 86b399f

Browse files
committed
Fix: wpcli image settings
1 parent 566d7b9 commit 86b399f

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

includes/Images/WPCLI/ImageCommandHandler.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use NewfoldLabs\WP\Module\Performance\NFD_WPCLI;
66
use NewfoldLabs\WP\Module\Performance\Images\ImageSettings;
7+
use function NewfoldLabs\WP\ModuleLoader\container;
78

89
/**
910
* Handles WP-CLI commands for Image Optimization settings.
@@ -17,6 +18,21 @@ class ImageCommandHandler {
1718
*/
1819
private const VALID_STATUSES = array( 'on', 'off' );
1920

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+
2036
/**
2137
* Toggles the bulk optimization setting.
2238
*
@@ -149,9 +165,9 @@ public function webp_preference( $args ) {
149165
public function all( $args ) {
150166
$status = $this->validate_status( isset( $args[0] ) ? $args[0] : null );
151167
$enabled = ( 'on' === $status );
152-
$settings = ImageSettings::get();
168+
$settings = ImageSettings::get( $this->container );
153169
$this->set_all_values( $settings, $enabled );
154-
ImageSettings::update( $settings );
170+
ImageSettings::update( $settings, $this->container );
155171
/* translators: %s is the on/off status. */
156172
NFD_WPCLI::success( sprintf( __( 'All image optimization settings have been turned %s.', 'wp-module-performance' ), $status ) );
157173
}
@@ -166,7 +182,7 @@ public function all( $args ) {
166182
*/
167183
private function toggle_setting( $setting, $status ) {
168184
$enabled = ( 'on' === $status );
169-
$settings = ImageSettings::get();
185+
$settings = ImageSettings::get( $this->container );
170186

171187
// If a feature is turned on (except for the "all" command), enable overall image optimization.
172188
if ( $enabled ) {
@@ -184,7 +200,7 @@ private function toggle_setting( $setting, $status ) {
184200
$settings['auto_optimized_uploaded_images']['auto_delete_original_image'] = false;
185201
}
186202

187-
ImageSettings::update( $settings );
203+
ImageSettings::update( $settings, $this->container );
188204

189205
NFD_WPCLI::success(
190206
sprintf(

0 commit comments

Comments
 (0)