Skip to content

Commit 3509bff

Browse files
author
Edwin Westerhoud
committed
2 parents 80f31a5 + f70fa92 commit 3509bff

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

src/class-tiny-plugin.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ public function compress_attachment($metadata, $attachment_id) {
8989
}
9090
}
9191

92+
if (!is_array($metadata['sizes'])) {
93+
return $metadata;
94+
}
95+
9296
foreach ($metadata['sizes'] as $size => $info) {
9397
if (isset($settings[$size]) && $settings[$size]['tinify'] && !$tiny_metadata->is_compressed($size)) {
9498
try {

test/unit/TinyPluginTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,16 @@ public function testShouldReturnIfNoImage() {
107107

108108
$this->subject->compress_attachment(getTestMetadata(), 1);
109109
}
110+
111+
public function testWrongMetadataShouldNotShowWarnings() {
112+
$this->wp->stub('get_post_mime_type', create_function('$i', 'return "image/png";'));
113+
$this->compressor->expects($this->exactly(1))->method('compress_file')->will(
114+
$this->returnCallback('compressTestFile')
115+
);
116+
117+
$testmeta = getTestMetadata();
118+
$testmeta['sizes'] = 0;
119+
120+
$this->subject->compress_attachment($testmeta, 1);
121+
}
110122
}

0 commit comments

Comments
 (0)