@@ -166,9 +166,9 @@ public function admin_init() {
166166 public function image_sizes_notice () {
167167 $ this ->render_image_sizes_notice (
168168 $ _GET ['image_sizes_selected ' ],
169- isset ( $ _GET ['resize_original ' ] )
169+ isset ( $ _GET ['resize_original ' ] ),
170+ isset ( $ _GET ['compress_wr2x ' ] )
170171 );
171-
172172 exit ();
173173 }
174174
@@ -356,12 +356,16 @@ public function render_sizes() {
356356 foreach ( $ this ->get_sizes () as $ size => $ option ) {
357357 $ this ->render_size_checkbox ( $ size , $ option );
358358 }
359+ if ( self ::wr2x_active () ) {
360+ $ this ->render_size_checkbox ( 'wr2x ' , $ this ->get_wr2x_option () );
361+ }
359362 echo '<br> ' ;
360363 echo '<div id="tiny-image-sizes-notice"> ' ;
361364
362365 $ this ->render_image_sizes_notice (
363366 count ( self ::get_active_tinify_sizes () ),
364- self ::get_resize_enabled ()
367+ self ::get_resize_enabled (),
368+ self ::compress_wr2x_images ()
365369 );
366370
367371 echo '</div> ' ;
@@ -374,6 +378,8 @@ private function render_size_checkbox( $size, $option ) {
374378 if ( Tiny_Image::is_original ( $ size ) ) {
375379 $ label = esc_html__ ( 'Original image ' , 'tiny-compress-images ' ) . ' ( ' .
376380 esc_html__ ( 'overwritten by compressed image ' , 'tiny-compress-images ' ) . ') ' ;
381+ } else if ( Tiny_Image::is_retina ( $ size ) ) {
382+ $ label = esc_html__ ( 'WP Retina 2x sizes ' , 'tiny-compress-images ' );
377383 } else {
378384 $ label = esc_html__ ( ucfirst ( $ size ) )
379385 . ' - ' . $ option ['width ' ] . 'x ' . $ option ['height ' ];
@@ -385,11 +391,15 @@ private function render_size_checkbox( $size, $option ) {
385391 echo '</p> ' ;
386392 }
387393
388- public function render_image_sizes_notice ( $ active_sizes_count , $ resize_original_enabled ) {
394+ public function render_image_sizes_notice (
395+ $ active_sizes_count , $ resize_original_enabled , $ compress_wr2x ) {
389396 echo '<p> ' ;
390397 if ( $ resize_original_enabled ) {
391398 $ active_sizes_count ++;
392399 }
400+ if ( $ compress_wr2x ) {
401+ $ active_sizes_count *= 2 ;
402+ }
393403
394404 if ( $ active_sizes_count < 1 ) {
395405 esc_html_e (
@@ -405,6 +415,20 @@ public function render_image_sizes_notice( $active_sizes_count, $resize_original
405415 '<strong> at least %s images </strong> for free each month. ' ,
406416 'tiny-compress-images '
407417 ), array ( 'strong ' => array () ) ), $ free_images_per_month );
418+
419+ if ( self ::wr2x_active () ) {
420+ echo '</p> ' ;
421+ echo '<p> ' ;
422+ esc_html_e (
423+ 'If selected, retina sizes will be compressed when generated by WP Retina 2x ' ,
424+ 'tiny-compress-images '
425+ );
426+ echo '<br> ' ;
427+ esc_html_e (
428+ 'Each retina size will count as an additional compression. ' ,
429+ 'tiny-compress-images '
430+ );
431+ }
408432 }
409433 echo '</p> ' ;
410434 }
@@ -659,4 +683,22 @@ public function update_api_key() {
659683 echo json_encode ( $ status );
660684 exit ();
661685 }
686+
687+ public static function wr2x_active () {
688+ return is_plugin_active ( 'wp-retina-2x/wp-retina-2x.php ' );
689+ }
690+
691+ public function get_wr2x_option () {
692+ $ setting = get_option ( self ::get_prefixed_name ( 'sizes ' ) );
693+ return array (
694+ 'width ' => null ,
695+ 'height ' => null ,
696+ 'tinify ' => ( isset ( $ setting ['wr2x ' ] ) && 'on ' === $ setting ['wr2x ' ] ),
697+ );
698+ }
699+
700+ public function compress_wr2x_images () {
701+ $ option = $ this ->get_wr2x_option ();
702+ return self ::wr2x_active () && $ option ['tinify ' ];
703+ }
662704}
0 commit comments