Skip to content

Commit a004ab1

Browse files
authored
Merge pull request #534 from Codeinwp/fix/issue-695
Add option to disable strip_metadata
2 parents 2ab05dd + 644c1f1 commit a004ab1

File tree

6 files changed

+59
-1
lines changed

6 files changed

+59
-1
lines changed

assets/vue/components/compression.vue

+34-1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,29 @@
8080
</div>
8181
</div>
8282
<hr/>
83+
<!-- Use strip metadata toggle button -->
84+
<div class="field columns">
85+
<label class="label column has-text-grey-dark optml-custom-label-margin">
86+
{{ strings.strip_meta_title }}
87+
88+
<p class="optml-settings-desc-margin has-text-weight-normal">
89+
{{ strings.strip_meta_desc }}
90+
</p>
91+
</label>
92+
93+
<div class="column is-1 ">
94+
<toggle-button
95+
v-model="stripMetadataStatus"
96+
:class="'has-text-dark'"
97+
:disabled="this.$store.state.loading"
98+
:width="37"
99+
:height="20"
100+
color="#577BF9"
101+
/>
102+
</div>
103+
</div>
104+
<hr/>
105+
<!-- Use ML toggle button -->
83106
<div class="field columns">
84107
<label class="label column has-text-grey-dark optml-custom-label-margin">
85108
{{ strings.quality_title }}
@@ -100,8 +123,8 @@
100123
color="#577BF9"
101124
/>
102125
</div>
103-
104126
</div>
127+
105128
<div class="field columns" v-if="showManualQuality">
106129

107130
<div class="column">
@@ -333,6 +356,16 @@ export default {
333356
return !(this.site_settings.autoquality === 'disabled');
334357
}
335358
},
359+
stripMetadataStatus: {
360+
set: function (value) {
361+
this.showSave = true;
362+
this.new_data.strip_metadata = value ? 'enabled' : 'disabled';
363+
},
364+
get: function () {
365+
return !(this.site_settings.strip_metadata === 'disabled');
366+
367+
}
368+
},
336369
compressionRatio() {
337370
if (this.sample_images.optimized_size > this.sample_images.original_size) {
338371
return Math.floor(Math.random() * 60) + 10;

inc/admin.php

+2
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,8 @@ private function get_dashboard_strings() {
963963
'quality_selected_value' => __( 'Selected value', 'optimole-wp' ),
964964
'quality_slider_desc' => __( 'See one sample image which will help you choose the right quality of the compression.', 'optimole-wp' ),
965965
'quality_title' => __( 'Enable Auto Quality powered by ML(Machine Learning)', 'optimole-wp' ),
966+
'strip_meta_title' => __( 'Strip Image Metadata', 'optimole-wp' ),
967+
'strip_meta_desc' => __( 'When enabled, Optimole will strip the metadata (EXIF, IPTC, etc.) from output images.', 'optimole-wp' ),
966968
'replacer_desc' => __( 'Replace all the image urls from your website with the ones optimized by Optimole.', 'optimole-wp' ),
967969
'sample_image_loading' => __( 'Loading a sample image. ', 'optimole-wp' ),
968970
'save_changes' => __( 'Save changes', 'optimole-wp' ),

inc/image.php

+4
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ public function get_url( $params = [] ) {
100100
$path = '/f:' . $params['format'] . '/' . $this->source_url;
101101
}
102102

103+
if ( isset( $params['strip_metadata'] ) && '0' === $params['strip_metadata'] ) {
104+
$path = '/sm:' . $params['strip_metadata'] . $path;
105+
}
106+
103107
if ( apply_filters( 'optml_keep_copyright', false ) === true ) {
104108
$path = '/keep_copyright:true' . $path;
105109
}

inc/settings.php

+3
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ class Optml_Settings {
8686
'native_lazyload' => 'disabled',
8787
'offload_media' => 'disabled',
8888
'cloud_images' => 'disabled',
89+
'strip_metadata' => 'enabled',
8990
'skip_lazyload_images' => 3,
9091
'defined_image_sizes' => [ ],
9192

@@ -243,6 +244,7 @@ public function parse_settings( $new_settings ) {
243244
case 'css_minify':
244245
case 'js_minify':
245246
case 'native_lazyload':
247+
case 'strip_metadata':
246248
case 'no_script':
247249
$sanitized_value = $this->to_map_values( $value, [ 'enabled', 'disabled' ], 'enabled' );
248250
break;
@@ -443,6 +445,7 @@ public function get_site_settings() {
443445
'autoquality' => $this->get( 'autoquality' ),
444446
'offload_media' => $this->get( 'offload_media' ),
445447
'cloud_images' => $this->get( 'cloud_images' ),
448+
'strip_metadata' => $this->get( 'strip_metadata' ),
446449
'whitelist_domains' => $whitelist,
447450
];
448451
}

inc/url_replacer.php

+4
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,10 @@ private function normalize_image( $url, $original_url, $args, $is_uploaded = fal
256256
$arguments['format'] = 'avif';
257257
}
258258

259+
if ( $this->settings->get( 'strip_metadata' ) === 'disabled' ) {
260+
$arguments['strip_metadata'] = '0';
261+
}
262+
259263
return ( new Optml_Image( $url, $args, $this->active_cache_buster ) )->get_url( $arguments );
260264

261265
}

tests/test-replacer.php

+12
Original file line numberDiff line numberDiff line change
@@ -639,4 +639,16 @@ public function test_class_exclusion()
639639
$this->assertStringNotContainsString('data-opt-src', $replaced_content);
640640
}
641641

642+
public function test_strip_metadata() {
643+
$replaced_content = Optml_Manager::instance()->replace_content( self::IMG_URLS );
644+
$this->assertStringNotContainsString( '/sm:0/', $replaced_content );
645+
646+
// To do same check but after we've disabled the strip metadata option.
647+
$settings = new Optml_Settings();
648+
$settings->update( 'strip_metadata', 'disabled' );
649+
Optml_Manager::instance()->init();
650+
$replaced_content = Optml_Manager::instance()->replace_content( self::IMG_URLS );
651+
$this->assertEquals( 27, substr_count( $replaced_content, '/sm:0/' ) );
652+
}
653+
642654
}

0 commit comments

Comments
 (0)