Skip to content

Commit d498407

Browse files
committed
Merge branch 'main' of https://github.com/newfold-labs/wp-module-performance into fix/link-prefetch
2 parents 969c44c + 7490da0 commit d498407

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

includes/Images/ImageManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ private function initialize_services( Container $container ) {
5454
* @param \NewfoldLabs\WP\Container\Container $container Dependency injection container.
5555
*/
5656
private function initialize_upload_listener( $container ) {
57-
new ImageUploadListener( ImageSettings::is_auto_delete_enabled(), $container );
57+
new ImageUploadListener( $container, ImageSettings::is_auto_delete_enabled() );
5858
}
5959

6060
/**

includes/Images/ImageUploadListener.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ class ImageUploadListener {
2626
/**
2727
* Constructor to initialize the listener.
2828
*
29-
* @param bool $delete_original Whether to delete the original file after optimization.
3029
* @param \NewfoldLabs\WP\Container\Container $container Dependency injection container.
30+
* @param bool $delete_original Whether to delete the original file after optimization.
3131
*/
32-
public function __construct( $delete_original = false, $container ) {
32+
public function __construct( $container, $delete_original = false ) {
3333
$this->image_service = new ImageService( $container );
3434
$this->delete_original = $delete_original;
3535
$this->register_hooks();

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)