@@ -18,8 +18,14 @@ public function register( Service_Container $container ): void {}
1818 */
1919 public function boot ( Service_Container $ container ): void {
2020 $ this ->after_setup_theme ();
21- add_filter ( 'ari_responsive_image_default_img_path ' , [ $ this , 'set_ari_responsive_image_default_img_path ' ] );
22- add_filter ( 'ari_responsive_image_default_img_name ' , [ $ this , 'set_ari_responsive_image_default_img_name ' ] );
21+ /**
22+ * @psalm-suppress PossiblyInvalidMethodCall
23+ * @psalm-suppress UndefinedInterfaceMethod
24+ */
25+ if ( Framework::get_container ()->get_service ( 'assets ' )->is_minified () ) {
26+ add_filter ( 'ari_responsive_image_default_img_path ' , [ $ this , 'set_ari_responsive_image_default_img_path ' ] );
27+ add_filter ( 'ari_responsive_image_default_img_name ' , [ $ this , 'set_ari_responsive_image_default_img_name ' ] );
28+ }
2329 }
2430
2531 /**
@@ -86,14 +92,6 @@ private function i18n(): void {
8692 *
8793 */
8894 public function set_ari_responsive_image_default_img_path ( string $ attr ): string {
89- /**
90- * @psalm-suppress PossiblyInvalidMethodCall
91- * @psalm-suppress UndefinedInterfaceMethod
92- */
93- if ( ! Framework::get_container ()->get_service ( 'assets ' )->is_minified () ) {
94- return $ attr ;
95- }
96-
9795 return '/dist/ ' ;
9896 }
9997
@@ -106,15 +104,7 @@ public function set_ari_responsive_image_default_img_path( string $attr ): strin
106104 *
107105 */
108106 public function set_ari_responsive_image_default_img_name ( string $ default_img ): string {
109- /**
110- * @psalm-suppress PossiblyInvalidMethodCall
111- * @psalm-suppress UndefinedInterfaceMethod
112- */
113- if ( ! Framework::get_container ()->get_service ( 'assets ' )->is_minified () ) {
114- return $ default_img ;
115- }
116-
117- return $ this ->get_min_image ( $ default_img );
107+ return $ this ->get_min_default_image ( $ default_img );
118108 }
119109
120110 /**
@@ -124,24 +114,9 @@ public function set_ari_responsive_image_default_img_name( string $default_img )
124114 *
125115 * @return string
126116 *
117+ * @author Léonard Phoumpakka
127118 */
128- protected function get_min_image ( string $ original_image ): string {
129-
130- if ( empty ( $ original_image ) ) {
131- return $ original_image ;
132- }
133-
134- if ( ! file_exists ( \get_theme_file_path ( '/dist/assets.json ' ) ) ) {
135- return $ original_image ;
136- }
137-
138- $ json = file_get_contents ( \get_theme_file_path ( '/dist/assets.json ' ) ); //phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
139- $ assets = json_decode ( $ json , true );
140-
141- if ( empty ( $ assets ) || JSON_ERROR_NONE !== json_last_error () ) {
142- return $ original_image ;
143- }
144-
145- return $ assets [ 'assets/ ' . $ original_image ] ?: $ original_image ;
119+ public function get_min_default_image ( string $ original_image ): string {
120+ return Framework::get_container ()->get_service ( 'assets ' )->get_min_file ( 'assets/ ' . $ original_image );
146121 }
147122}
0 commit comments