Skip to content

Commit 546fe25

Browse files
Signature for compression only requires array of mimetypes, if empty, there will be no conversion
1 parent 8ed9026 commit 546fe25

File tree

4 files changed

+10
-18
lines changed

4 files changed

+10
-18
lines changed

src/class-tiny-compress-client.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ protected function validate() {
8888
}
8989
}
9090

91-
protected function compress( $input, $resize_opts, $preserve_opts, $convert_opts ) {
91+
protected function compress( $input, $resize_opts, $preserve_opts, $convert_to ) {
9292
try {
9393
$this->last_error_code = 0;
9494
$this->set_request_options( \Tinify\Tinify::getClient() );
@@ -121,8 +121,7 @@ protected function compress( $input, $resize_opts, $preserve_opts, $convert_opts
121121
$buffer = $compress_result->toBuffer();
122122
$result = array( $buffer, $meta, null );
123123

124-
if ( isset( $convert_opts['convert'] ) && true == $convert_opts['convert'] ) {
125-
$convert_to = $convert_opts['convert_to'];
124+
if ( count( $convert_to ) > 0 ) {
126125
$convert_source = $source->convert( array(
127126
'type' => $convert_to,
128127
) );

src/class-tiny-compress-fopen.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ protected function validate() {
8282
}
8383
}
8484

85-
protected function compress( $input, $resize_opts, $preserve_opts, $convert_opts ) {
85+
protected function compress( $input, $resize_opts, $preserve_opts, $convert_to ) {
8686
$params = $this->request_options( 'POST', $input );
8787
list($details, $headers, $status_code) = $this->request( $params );
8888

@@ -146,8 +146,7 @@ protected function compress( $input, $resize_opts, $preserve_opts, $convert_opts
146146

147147
$convert = null;
148148

149-
if ( isset( $convert_opts['convert'] ) && true === $convert_opts['convert'] ) {
150-
$convert_to = $convert_opts['convert_to'];
149+
if ( count( $convert_to ) > 0 ) {
151150
$convert_params = $this->request_options(
152151
'POST',
153152
array(

src/class-tiny-compress.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,14 @@ public function get_status() {
9999
* @param [type] $file
100100
* @param array $resize_opts
101101
* @param array $preserve_opts
102-
* @param array{ convert: bool, convert_to: string } conversion options
102+
* @param array{ string } conversion options
103103
* @return void
104104
*/
105105
public function compress_file(
106106
$file,
107107
$resize_opts = array(),
108108
$preserve_opts = array(),
109-
$convert_opts = array()
109+
$convert_to = array()
110110
) {
111111
if ( $this->get_key() == null ) {
112112
throw new Tiny_Exception( self::KEY_MISSING, 'KeyError' );
@@ -131,7 +131,7 @@ public function compress_file(
131131
$file_data,
132132
$resize_opts,
133133
$preserve_opts,
134-
$convert_opts
134+
$convert_to
135135
);
136136
} catch ( Tiny_Exception $err ) {
137137
$this->call_after_compress_callback();
@@ -172,7 +172,7 @@ protected abstract function compress(
172172
$input,
173173
$resize_options,
174174
$preserve_options,
175-
$convert_opts
175+
$convert_to
176176
);
177177

178178
protected static function identifier() {

test/unit/TinyCliTest.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,15 @@ public function test_will_compress_attachments_given_in_params()
5656
'file' => "vfs://root/wp-content/uploads/2025/07/test.png",
5757
'resize' => false,
5858
'preserve' => array(),
59-
'convert_opts' => array(
60-
'convert' => false,
61-
'convert_to' => array(
62-
'image/avif',
63-
'image/webp'
64-
)
65-
),
59+
'convert_to' => array(),
6660
);
6761
$mockCompressor->expects($this->once())
6862
->method('compress_file')
6963
->with(
7064
$expected['file'],
7165
$expected['resize'],
7266
$expected['preserve'],
73-
$expected['convert_opts']
67+
$expected['convert_to']
7468
);
7569
$settings->set_compressor($mockCompressor);
7670

0 commit comments

Comments
 (0)