Skip to content

Commit 0823ba9

Browse files
refactor: default settings for compression
1 parent 387be28 commit 0823ba9

File tree

3 files changed

+36
-16
lines changed

3 files changed

+36
-16
lines changed

assets/src/dashboard/parts/connected/settings/Compression.js

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ const Compression = ({
140140
setCanSave( true );
141141
const data = { ...settings };
142142
if ( 'speed_optimized' === value ) {
143-
data[ 'best_format' ] = 'disabled';
143+
data[ 'best_format' ] = 'enabled';
144144
data[ 'retina_images' ] = 'disabled';
145145
data[ 'network_optimization' ] = 'enabled';
146146
data.avif = 'mauto';
@@ -280,20 +280,25 @@ const Compression = ({
280280
<hr className="my-8 border-grayish-blue"/>
281281

282282

283-
<ToggleControl
284-
label={ optimoleDashboardApp.strings.options_strings.enable_avif_title }
285-
help={ () => <p dangerouslySetInnerHTML={ { __html: optimoleDashboardApp.strings.options_strings.enable_avif_desc } } /> }
286-
checked={ isAVIFEnabled }
287-
disabled={ isLoading }
288-
className={ classnames(
289-
{
290-
'is-disabled': isLoading
291-
}
292-
) }
293-
onChange={ value => updateOption( 'avif', value ) }
294-
/>
283+
{ optimoleDashboardApp?.enableAVIF && (
284+
<>
285+
286+
<ToggleControl
287+
label={ optimoleDashboardApp.strings.options_strings.enable_avif_title }
288+
help={ () => <p dangerouslySetInnerHTML={ { __html: optimoleDashboardApp.strings.options_strings.enable_avif_desc } } /> }
289+
checked={ isAVIFEnabled }
290+
disabled={ isLoading }
291+
className={ classnames(
292+
{
293+
'is-disabled': isLoading
294+
}
295+
) }
296+
onChange={ value => updateOption( 'avif', value ) }
297+
/>
298+
<hr className="my-8 border-grayish-blue"/>
299+
</>
300+
) }
295301

296-
<hr className="my-8 border-grayish-blue"/>
297302

298303
<ToggleControl
299304
label={ optimoleDashboardApp.strings.options_strings.strip_meta_title }

inc/admin.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,6 +1326,7 @@ private function localize_dashboard_app() {
13261326
return [
13271327
'strings' => $this->get_dashboard_strings(),
13281328
'assets_url' => OPTML_URL . 'assets/',
1329+
'enableAVIF' => apply_filters( 'optml_show_avif_setting', false ),
13291330
'dam_url' => 'admin.php?page=optimole-dam',
13301331
'connection_status' => empty( $service_data ) ? 'no' : 'yes',
13311332
'has_application' => isset( $service_data['app_count'] ) && $service_data['app_count'] >= 1 ? 'yes' : 'no',
@@ -1720,7 +1721,7 @@ private function get_dashboard_strings() {
17201721
'best_format_title' => __( 'Automatic Best Image Format Selection', 'optimole-wp' ),
17211722
'best_format_desc' => sprintf(
17221723
/* translators: 1 is the starting anchor tag, 2 is the ending anchor tag */
1723-
__( 'When enabled, Optimole picks the ideal format for your images, balancing quality and speed. It tests different formats, like AVIF and WebP, ensuring images look good and load quickly. %1$sLearn more%2$s.', 'optimole-wp' ),
1724+
__( 'When enabled, Optimole chooses the best format for your images, balancing quality with speed. It tries options like AVIF and WebP to keep visuals sharp and pages fast, though uncached images may take a bit longer to process. %1$sLearn more%2$s.', 'optimole-wp' ),
17241725
'<a class="inline-block text-purple-gray underline" target=”_blank” href="https://docs.optimole.com/article/1942-best-format">',
17251726
'</a>'
17261727
),
@@ -1826,7 +1827,7 @@ private function get_dashboard_strings() {
18261827
'enable_resize_smart_title' => __( 'Smart Cropping', 'optimole-wp' ),
18271828
'enable_retina_desc' => sprintf(
18281829
/* translators: 1 is the starting anchor tag, 2 is the ending anchor tag */
1829-
__( 'Enable this feature to optimize your images for Retina displays. Retina-ready images are optimized to look sharp on screens with higher pixel density, offering viewers enhanced visual quality. %1$sLearn more%2$s', 'optimole-wp' ),
1830+
__( 'Optimizes images for Retina (high-DPI) screens for sharper results. Always enabled for images under 150px wide. %1$sLearn more%2$s', 'optimole-wp' ),
18301831
'<a class="inline-block text-purple-gray underline" target=”_blank” href="https://docs.optimole.com/article/1391-what-is-a-retina-image">',
18311832
'</a>'
18321833
),

inc/url_replacer.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,20 @@ private function normalize_image( $url, $original_url, $args, $is_uploaded = fal
226226
$args['resize']['gravity'] = GravityProperty::SMART;
227227
}
228228

229+
$is_retina_enabled = $this->settings->get( 'retina_images' ) !== 'disabled';
230+
$max_dimension = max( $args['width'], $args['height'] );
231+
$should_apply_dpr = false;
232+
233+
if ( $is_retina_enabled || ( $max_dimension > 0 && $max_dimension < 150 ) ) {
234+
$should_apply_dpr = true;
235+
}
236+
237+
$should_apply_dpr = apply_filters( 'optml_should_apply_dpr', $should_apply_dpr, $args, $url );
238+
239+
if ( $should_apply_dpr && ! isset( $args['dpr'] ) ) {
240+
$args['dpr'] = 2;
241+
}
242+
229243
$args = apply_filters( 'optml_image_args', $args, $original_url );
230244
$image = Optimole::image( apply_filters( 'optml_processed_url', $url ), self::get_active_cache_booster( $url, $this->active_cache_buster ) );
231245

0 commit comments

Comments
 (0)