2020
2121class Tiny_Settings extends Tiny_WP_Base {
2222 const PREFIX = 'tinypng_ ' ;
23+ const DUMMY_SIZE = '_tiny_dummy ' ;
2324
2425 protected static function get_prefixed_name ($ name ) {
2526 return self ::PREFIX . $ name ;
@@ -28,14 +29,6 @@ protected static function get_prefixed_name($name) {
2829 private $ sizes ;
2930 private $ tinify_sizes ;
3031
31- public function __construct () {
32- parent ::__construct ();
33- // if (is_multisite()) {
34- // add_action('network_admin_menu', $this->get_method('register_multisite_settings'));
35- // add_action('network_admin_edit_save_tinypng_multisite_settings', $this->get_method('save_multisite_settings'), 10, 0);
36- // }
37- }
38-
3932 public function admin_init () {
4033 $ section = self ::get_prefixed_name ('settings ' );
4134 add_settings_section ($ section , self ::translate ('PNG and JPEG compression ' ), $ this ->get_method ('render_section ' ), 'media ' );
@@ -100,10 +93,18 @@ public function get_sizes() {
10093 return $ this ->sizes ;
10194 }
10295
103- $ this ->sizes = array ();
10496 $ setting = get_option (self ::get_prefixed_name ('sizes ' ));
10597
98+ $ size = Tiny_Metadata::ORIGINAL ;
99+ $ this ->sizes = array ($ size => array (
100+ 'width ' => null , 'height ' => null ,
101+ 'tinify ' => !is_array ($ setting ) || (isset ($ setting [$ size ]) && $ setting [$ size ] === 'on ' ),
102+ ));
103+
106104 foreach (get_intermediate_image_sizes () as $ size ) {
105+ if ($ size === self ::DUMMY_SIZE ) {
106+ continue ;
107+ }
107108 list ($ width , $ height ) = self ::get_intermediate_size ($ size );
108109 if ($ width && $ height ) {
109110 $ this ->sizes [$ size ] = array (
@@ -168,14 +169,24 @@ public function render_api_key() {
168169
169170 public function render_sizes () {
170171 echo '<p> ' . self ::translate_escape ('You can choose to compress different image sizes created by WordPress here ' ) . '.<br/> ' ;
171- echo self ::translate_escape ('Remember each additional image size will affect your TinyPNG monthly usage ' ) . "!</p> \n" ;
172+ echo self ::translate_escape ('Remember each additional image size will affect your TinyPNG monthly usage ' ) . "! " ;?>
173+ <input type="hidden" name="<?php echo self ::get_prefixed_name ('sizes[ ' . self ::DUMMY_SIZE .'] ' ); ?> " value="on"/></p>
174+ <?php
172175 foreach ($ this ->get_sizes () as $ size => $ option ) {
173- $ id = self ::get_prefixed_name ("sizes_ $ size " );
174- $ field = self ::get_prefixed_name ("sizes[ $ size] " );
175- ?>
176+ $ this ->render_size_checkbox ($ size , $ option );
177+ }
178+ }
179+
180+ private function render_size_checkbox ($ size , $ option ) {
181+ $ id = self ::get_prefixed_name ("sizes_ $ size " );
182+ $ field = self ::get_prefixed_name ("sizes[ $ size] " );
183+ if ($ size === Tiny_Metadata::ORIGINAL ) {
184+ $ label = self ::translate_escape ("original " );
185+ } else {
186+ $ label = $ size . " - $ {option['width ' ]}x $ {option['height ' ]}" ;
187+ }?>
176188<p><input type="checkbox" id="<?php echo $ id ; ?> " name="<?php echo $ field ?> " value="on" <?php if ($ option ['tinify ' ]) { echo ' checked="checked" ' ; } ?> />
177- <label for="<?php echo $ id ; ?> "><?php echo $ size . " - $ {option[ ' width ' ]} x $ {option[ ' height ' ]}" ; ?> </label></p>
189+ <label for="<?php echo $ id ; ?> "><?php echo $ label ; ?> </label></p>
178190<?php
179- }
180191 }
181192}
0 commit comments