Skip to content

Commit 6d91b12

Browse files
author
Jacob Middag
committed
Fix bug that does not save Tiny metadata when metadata is not an array
1 parent fe9aa6d commit 6d91b12

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

src/class-tiny-plugin.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ public function compress_attachment($metadata, $attachment_id) {
8989
}
9090
}
9191

92-
if (!is_array($metadata['sizes'])) {
92+
if (!isset($metadata['sizes']) || !is_array($metadata['sizes'])) {
93+
$tiny_metadata->update();
9394
return $metadata;
9495
}
9596

@@ -103,8 +104,8 @@ public function compress_attachment($metadata, $attachment_id) {
103104
}
104105
}
105106
}
106-
$tiny_metadata->update();
107107

108+
$tiny_metadata->update();
108109
return $metadata;
109110
}
110111

test/unit/TinyPluginTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,17 @@ public function testWrongMetadataShouldNotShowWarnings() {
119119

120120
$this->subject->compress_attachment($testmeta, 1);
121121
}
122+
123+
public function testWrongMetadataShouldSaveTinyMetadata() {
124+
$this->wp->stub('get_post_mime_type', create_function('$i', 'return "image/png";'));
125+
$this->compressor->expects($this->exactly(1))->method('compress_file')->will(
126+
$this->returnCallback('compressTestFile')
127+
);
128+
129+
$testmeta = getTestMetadata();
130+
$testmeta['sizes'] = 0;
131+
132+
$this->subject->compress_attachment($testmeta, 1);
133+
$this->assertEquals(1, count($this->wp->getCalls('update_post_meta')));
134+
}
122135
}

0 commit comments

Comments
 (0)