Skip to content

Commit eac8fd2

Browse files
committed
One more place to fix
1 parent 7077112 commit eac8fd2

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

includes/Images/ImageService.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public function optimize_image( $image_url, $original_file_path ) {
113113
$monthly_request_count = ( '' !== $monthly_request_count ) ? intval( $monthly_request_count ) : null;
114114
$monthly_limit = ( '' !== $monthly_limit ) ? intval( $monthly_limit ) : null;
115115
if ( null !== $monthly_request_count && null !== $monthly_limit ) {
116-
$settings = ImageSettings::get();
116+
$settings = ImageSettings::get( $this->container, true );
117117
$settings['monthly_usage'] = array(
118118
'monthlyRequestCount' => $monthly_request_count,
119119
'maxRequestsPerMonth' => $monthly_limit,
@@ -232,7 +232,7 @@ public function optimize_image( $image_url, $original_file_path ) {
232232
* Permanently ban the site from accessing image optimization.
233233
*/
234234
private function ban_site() {
235-
$settings = ImageSettings::get();
235+
$settings = ImageSettings::get( $this->container, true );
236236
$settings['banned_status'] = true;
237237
$settings['bulk_optimization'] = false;
238238
$settings['auto_optimized_uploaded_images']['enabled'] = false;
@@ -504,7 +504,7 @@ public function get_monthly_usage_limit() {
504504
);
505505
}
506506

507-
$settings = ImageSettings::get( false );
507+
$settings = ImageSettings::get( $this->container, false );
508508
$settings['monthly_usage'] = $body;
509509
ImageSettings::update( $settings, $this->container );
510510

includes/Images/ImageSettings.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ private static function get_default_settings( $container = null ) {
7272
* @param \NewfoldLabs\WP\Container\Container $container Dependency injection container.
7373
*/
7474
public function __construct( $container ) {
75+
$this->container = $container;
7576
$this->default_settings = self::get_default_settings( $container );
7677
$this->register_settings( $container );
7778
$this->initialize_settings();
@@ -407,11 +408,12 @@ public static function get_monthly_usage() {
407408
/**
408409
* Retrieves the image optimization settings.
409410
*
410-
* @param bool $call_worker Whether to fetch the latest monthly usage from the worker. Default is true.
411+
* @param \NewfoldLabs\WP\Container\Container|null $container Dependency injection container (optional).
412+
* @param bool $call_worker Whether to fetch the latest monthly usage from the worker. Default is true.
411413
*
412414
* @return array The current image optimization settings, including monthly usage and banned status.
413415
*/
414-
public static function get( $call_worker = true ) {
416+
public static function get( $container, $call_worker = true ) {
415417
$settings = get_option( self::SETTING_KEY, array() );
416418

417419
if ( ! is_array( $settings ) ) {
@@ -423,7 +425,7 @@ public static function get( $call_worker = true ) {
423425
}
424426

425427
if ( $call_worker && ( empty( $settings['monthly_usage'] ) || ! is_array( $settings['monthly_usage'] ) ) ) {
426-
$usage_data = ( new ImageService() )->get_monthly_usage_limit( true );
428+
$usage_data = ( new ImageService( $container ) )->get_monthly_usage_limit( true );
427429
if ( ! is_wp_error( $usage_data ) ) {
428430
$settings['monthly_usage'] = $usage_data;
429431
update_option( self::SETTING_KEY, $settings );

0 commit comments

Comments
 (0)