Version Description
- Added indication of number of images you can compress for free each month.
- Added link to settings page from the plugin listing.
- Added clarification that by checking the original image size your original images will be overwritten.
Download this release
Release Info
Developer | TinyPNG |
Plugin | Compress JPEG & PNG images |
Version | 1.4.0 |
Comparing to | |
See all releases |
Code changes from version 1.3.2 to 1.4.0
- readme.txt +8 -3
- src/class-tiny-plugin.php +8 -0
- src/class-tiny-settings.php +32 -4
- src/languages/tiny-compress-images-nl_NL.mo +0 -0
- src/languages/tiny-compress-images-nl_NL.po +20 -2
- src/scripts/admin.js +6 -0
- test/integration/PluginIntegrationTest.php +21 -0
- test/integration/SettingsIntegrationTest.php +32 -0
- tiny-compress-images.php +1 -1
readme.txt
CHANGED
@@ -3,8 +3,8 @@ Contributors: TinyPNG
|
|
3 |
Donate link: https://tinypng.com/
|
4 |
Tags: compress, optimize, shrink, improve, images, tinypng, tinyjpg, jpeg, jpg, png, lossy, jpegmini, crunch, minify, smush, save, bandwidth, website, speed, faster, performance, panda
|
5 |
Requires at least: 3.0.6
|
6 |
-
Tested up to: 4.
|
7 |
-
Stable tag: 1.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -33,7 +33,7 @@ After you upload an image to your WordPress site, each resized image is uploaded
|
|
33 |
|
34 |
= Getting started =
|
35 |
|
36 |
-
Install this plugin and obtain your free API key from https://tinypng.com/developers.
|
37 |
|
38 |
= Multisite support =
|
39 |
|
@@ -98,6 +98,11 @@ A: Yes! After installing the plugin, go to Tools > Compress JPEG & PNG images, a
|
|
98 |
|
99 |
== Changelog ==
|
100 |
|
|
|
|
|
|
|
|
|
|
|
101 |
= 1.3.2 =
|
102 |
* In some cases a user would have different file sizes defined in Settings > Media which have the exact same pixel dimensions. Compressing images could then occasionally result in compressing the same image multiple times without being seen as 'compressed'. We now detect duplicate file sizes and don't compress them again.
|
103 |
|
3 |
Donate link: https://tinypng.com/
|
4 |
Tags: compress, optimize, shrink, improve, images, tinypng, tinyjpg, jpeg, jpg, png, lossy, jpegmini, crunch, minify, smush, save, bandwidth, website, speed, faster, performance, panda
|
5 |
Requires at least: 3.0.6
|
6 |
+
Tested up to: 4.4
|
7 |
+
Stable tag: 1.4.0
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
33 |
|
34 |
= Getting started =
|
35 |
|
36 |
+
Install this plugin and obtain your free API key from https://tinypng.com/developers. With a free account you can compress roughly 100 images each month (based on a regular WordPress installation). The exact number depends on the number of thumbnail sizes you use. You can change which of the generated thumbnail sizes should be compressed, because each one of them counts as a compression. And if you’re a heavy user, you can compress more images for a small additional fee per image.
|
37 |
|
38 |
= Multisite support =
|
39 |
|
98 |
|
99 |
== Changelog ==
|
100 |
|
101 |
+
= 1.4.0 =
|
102 |
+
* Added indication of number of images you can compress for free each month.
|
103 |
+
* Added link to settings page from the plugin listing.
|
104 |
+
* Added clarification that by checking the original image size your original images will be overwritten.
|
105 |
+
|
106 |
= 1.3.2 =
|
107 |
* In some cases a user would have different file sizes defined in Settings > Media which have the exact same pixel dimensions. Compressing images could then occasionally result in compressing the same image multiple times without being seen as 'compressed'. We now detect duplicate file sizes and don't compress them again.
|
108 |
|
src/class-tiny-plugin.php
CHANGED
@@ -54,6 +54,8 @@ class Tiny_Plugin extends Tiny_WP_Base {
|
|
54 |
add_action('wp_ajax_tiny_compress_image', $this->get_method('compress_image'));
|
55 |
add_action('admin_action_tiny_bulk_compress', $this->get_method('bulk_compress'));
|
56 |
add_action('admin_enqueue_scripts', $this->get_method('enqueue_scripts'));
|
|
|
|
|
57 |
}
|
58 |
|
59 |
public function admin_menu() {
|
@@ -64,6 +66,12 @@ class Tiny_Plugin extends Tiny_WP_Base {
|
|
64 |
|
65 |
}
|
66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
public function enqueue_scripts($hook) {
|
68 |
wp_enqueue_style(self::NAME .'_admin', plugins_url('/styles/admin.css', __FILE__),
|
69 |
array(), self::plugin_version());
|
54 |
add_action('wp_ajax_tiny_compress_image', $this->get_method('compress_image'));
|
55 |
add_action('admin_action_tiny_bulk_compress', $this->get_method('bulk_compress'));
|
56 |
add_action('admin_enqueue_scripts', $this->get_method('enqueue_scripts'));
|
57 |
+
$plugin = plugin_basename(dirname(dirname(__FILE__)) . '/tiny-compress-images.php');
|
58 |
+
add_filter("plugin_action_links_$plugin", $this->get_method('add_plugin_links'));
|
59 |
}
|
60 |
|
61 |
public function admin_menu() {
|
66 |
|
67 |
}
|
68 |
|
69 |
+
public function add_plugin_links($current_links) {
|
70 |
+
$additional[] = sprintf('<a href="options-media.php#%s">%s</a>', self::NAME,
|
71 |
+
self::translate_escape('Settings'));
|
72 |
+
return array_merge($additional, $current_links);
|
73 |
+
}
|
74 |
+
|
75 |
public function enqueue_scripts($hook) {
|
76 |
wp_enqueue_style(self::NAME .'_admin', plugins_url('/styles/admin.css', __FILE__),
|
77 |
array(), self::plugin_version());
|
src/class-tiny-settings.php
CHANGED
@@ -20,6 +20,7 @@
|
|
20 |
|
21 |
class Tiny_Settings extends Tiny_WP_Base {
|
22 |
const DUMMY_SIZE = '_tiny_dummy';
|
|
|
23 |
|
24 |
private $sizes;
|
25 |
private $tinify_sizes;
|
@@ -58,9 +59,15 @@ class Tiny_Settings extends Tiny_WP_Base {
|
|
58 |
register_setting('media', $field);
|
59 |
add_settings_field($field, self::translate('Connection status'), $this->get_method('render_pending_status'), 'media', $section);
|
60 |
|
|
|
61 |
add_action('wp_ajax_tiny_compress_status', $this->get_method('connection_status'));
|
62 |
}
|
63 |
|
|
|
|
|
|
|
|
|
|
|
64 |
public function connection_status() {
|
65 |
$this->render_status();
|
66 |
exit();
|
@@ -172,20 +179,23 @@ class Tiny_Settings extends Tiny_WP_Base {
|
|
172 |
}
|
173 |
|
174 |
public function render_sizes() {
|
175 |
-
echo '<p>' . self::translate_escape('
|
176 |
-
echo self::translate_escape('Remember each additional image size will affect your TinyPNG monthly usage') . "!";?>
|
177 |
<input type="hidden" name="<?php echo self::get_prefixed_name('sizes[' . self::DUMMY_SIZE .']'); ?>" value="on"/></p>
|
178 |
<?php
|
179 |
foreach ($this->get_sizes() as $size => $option) {
|
180 |
$this->render_size_checkbox($size, $option);
|
181 |
}
|
|
|
|
|
|
|
|
|
182 |
}
|
183 |
|
184 |
private function render_size_checkbox($size, $option) {
|
185 |
$id = self::get_prefixed_name("sizes_$size");
|
186 |
$field = self::get_prefixed_name("sizes[$size]");
|
187 |
if ($size === Tiny_Metadata::ORIGINAL) {
|
188 |
-
$label = self::translate_escape("original");
|
189 |
} else {
|
190 |
$label = $size . " - ${option['width']}x${option['height']}";
|
191 |
}?>
|
@@ -194,6 +204,24 @@ class Tiny_Settings extends Tiny_WP_Base {
|
|
194 |
<?php
|
195 |
}
|
196 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
197 |
public function get_compression_count() {
|
198 |
$field = self::get_prefixed_name('status');
|
199 |
return get_option($field);
|
@@ -241,7 +269,7 @@ class Tiny_Settings extends Tiny_WP_Base {
|
|
241 |
$compressions = self::get_compression_count();
|
242 |
echo '<p>';
|
243 |
// We currently have no way to check if a user is free or flexible.
|
244 |
-
if ($compressions ==
|
245 |
$link = '<a href="https://tinypng.com/developers" target="_blank">' . self::translate_escape('TinyPNG API account') . '</a>';
|
246 |
printf(self::translate_escape('You have reached your limit of %s compressions this month') . '.', $compressions);
|
247 |
echo '<br>';
|
20 |
|
21 |
class Tiny_Settings extends Tiny_WP_Base {
|
22 |
const DUMMY_SIZE = '_tiny_dummy';
|
23 |
+
const MONTHLY_FREE_COMPRESSIONS = 500;
|
24 |
|
25 |
private $sizes;
|
26 |
private $tinify_sizes;
|
59 |
register_setting('media', $field);
|
60 |
add_settings_field($field, self::translate('Connection status'), $this->get_method('render_pending_status'), 'media', $section);
|
61 |
|
62 |
+
add_action('wp_ajax_tiny_image_sizes_notice', $this->get_method('image_sizes_notice'));
|
63 |
add_action('wp_ajax_tiny_compress_status', $this->get_method('connection_status'));
|
64 |
}
|
65 |
|
66 |
+
public function image_sizes_notice() {
|
67 |
+
$this->render_image_sizes_notice($_GET["image_sizes_selected"]);
|
68 |
+
exit();
|
69 |
+
}
|
70 |
+
|
71 |
public function connection_status() {
|
72 |
$this->render_status();
|
73 |
exit();
|
179 |
}
|
180 |
|
181 |
public function render_sizes() {
|
182 |
+
echo '<p>' . self::translate_escape('Choose sizes to compress') . ':';?>
|
|
|
183 |
<input type="hidden" name="<?php echo self::get_prefixed_name('sizes[' . self::DUMMY_SIZE .']'); ?>" value="on"/></p>
|
184 |
<?php
|
185 |
foreach ($this->get_sizes() as $size => $option) {
|
186 |
$this->render_size_checkbox($size, $option);
|
187 |
}
|
188 |
+
|
189 |
+
echo '<div id="tiny-image-sizes-notice">';
|
190 |
+
$this->render_image_sizes_notice(count(self::get_active_tinify_sizes()));
|
191 |
+
echo '</div>';
|
192 |
}
|
193 |
|
194 |
private function render_size_checkbox($size, $option) {
|
195 |
$id = self::get_prefixed_name("sizes_$size");
|
196 |
$field = self::get_prefixed_name("sizes[$size]");
|
197 |
if ($size === Tiny_Metadata::ORIGINAL) {
|
198 |
+
$label = self::translate_escape("original") . ' (' . self::translate_escape('overwritten by compressed image') . ')';
|
199 |
} else {
|
200 |
$label = $size . " - ${option['width']}x${option['height']}";
|
201 |
}?>
|
204 |
<?php
|
205 |
}
|
206 |
|
207 |
+
public function render_image_sizes_notice($active_image_sizes_count) {
|
208 |
+
echo '<br/>';
|
209 |
+
if ($active_image_sizes_count < 1) {
|
210 |
+
echo '<p>' . self::translate_escape('With these settings no images will be compressed') . '.</p>';
|
211 |
+
}
|
212 |
+
else {
|
213 |
+
$free_images_per_month = floor(self::MONTHLY_FREE_COMPRESSIONS / $active_image_sizes_count);
|
214 |
+
|
215 |
+
echo '<p>';
|
216 |
+
echo self::translate_escape('With these settings you can compress');
|
217 |
+
echo ' <strong>';
|
218 |
+
printf(self::translate_escape('%s images'), $free_images_per_month);
|
219 |
+
echo '</strong> ';
|
220 |
+
echo self::translate_escape('for free each month') . '.';
|
221 |
+
echo '</p>';
|
222 |
+
}
|
223 |
+
}
|
224 |
+
|
225 |
public function get_compression_count() {
|
226 |
$field = self::get_prefixed_name('status');
|
227 |
return get_option($field);
|
269 |
$compressions = self::get_compression_count();
|
270 |
echo '<p>';
|
271 |
// We currently have no way to check if a user is free or flexible.
|
272 |
+
if ($compressions == self::MONTHLY_FREE_COMPRESSIONS) {
|
273 |
$link = '<a href="https://tinypng.com/developers" target="_blank">' . self::translate_escape('TinyPNG API account') . '</a>';
|
274 |
printf(self::translate_escape('You have reached your limit of %s compressions this month') . '.', $compressions);
|
275 |
echo '<br>';
|
src/languages/tiny-compress-images-nl_NL.mo
CHANGED
Binary file
|
src/languages/tiny-compress-images-nl_NL.po
CHANGED
@@ -19,8 +19,8 @@ msgstr "Bestandscompressie"
|
|
19 |
msgid "original"
|
20 |
msgstr "origineel"
|
21 |
|
22 |
-
msgid "
|
23 |
-
msgstr "
|
24 |
|
25 |
msgid "Remember each additional image size will affect your TinyPNG monthly usage"
|
26 |
msgstr "Elke afmetingen zal apart worden gecomprimeerd en telt mee voor je verbruik"
|
@@ -133,6 +133,21 @@ msgstr "Als je meer afbeeldingen wilt comprimeren kun je je %s aanpassen"
|
|
133 |
msgid "Upgrade your %s if you like to compress more images"
|
134 |
msgstr "Upgrade je %s als je meer afbeeldingen wilt comprimeren"
|
135 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
msgid "Please fill in an API key to start compressing images"
|
137 |
msgstr "Vul een API-sleutel in om te starten met comprimeren"
|
138 |
|
@@ -186,3 +201,6 @@ msgstr "Navigeer niet van deze pagina want daardoor stopt het proces"
|
|
186 |
|
187 |
msgid "You will be notified via this page when the processing is done"
|
188 |
msgstr "Je wordt genotificeerd op deze pagina bij voltooing"
|
|
|
|
|
|
19 |
msgid "original"
|
20 |
msgstr "origineel"
|
21 |
|
22 |
+
msgid "Choose sizes to compress"
|
23 |
+
msgstr "Kies afmetingen om te comprimeren"
|
24 |
|
25 |
msgid "Remember each additional image size will affect your TinyPNG monthly usage"
|
26 |
msgstr "Elke afmetingen zal apart worden gecomprimeerd en telt mee voor je verbruik"
|
133 |
msgid "Upgrade your %s if you like to compress more images"
|
134 |
msgstr "Upgrade je %s als je meer afbeeldingen wilt comprimeren"
|
135 |
|
136 |
+
msgid "With these settings you can compress"
|
137 |
+
msgstr "Met deze instellingen kun je elke maand"
|
138 |
+
|
139 |
+
msgid "%s images"
|
140 |
+
msgstr "%s afbeeldingen"
|
141 |
+
|
142 |
+
msgid "for free each month"
|
143 |
+
msgstr "gratis comprimeren"
|
144 |
+
|
145 |
+
msgid "With these settings no images will be compressed"
|
146 |
+
msgstr "Met deze instellingen worden geen afbeeldingen gecomprimeerd"
|
147 |
+
|
148 |
+
msgid "overwritten by compressed image"
|
149 |
+
msgstr "overschreven door gecomprimeerde afbeelding"
|
150 |
+
|
151 |
msgid "Please fill in an API key to start compressing images"
|
152 |
msgstr "Vul een API-sleutel in om te starten met comprimeren"
|
153 |
|
201 |
|
202 |
msgid "You will be notified via this page when the processing is done"
|
203 |
msgstr "Je wordt genotificeerd op deze pagina bij voltooing"
|
204 |
+
|
205 |
+
msgid "Settings"
|
206 |
+
msgstr "Instellingen"
|
src/scripts/admin.js
CHANGED
@@ -155,6 +155,12 @@
|
|
155 |
|
156 |
if (adminpage === "options-media-php") {
|
157 |
jQuery('#tiny-compress-status').load(ajaxurl + '?action=tiny_compress_status')
|
|
|
|
|
|
|
|
|
|
|
|
|
158 |
}
|
159 |
|
160 |
jQuery('.tiny-notice a.tiny-dismiss').click(dismiss_notice)
|
155 |
|
156 |
if (adminpage === "options-media-php") {
|
157 |
jQuery('#tiny-compress-status').load(ajaxurl + '?action=tiny_compress_status')
|
158 |
+
|
159 |
+
jQuery('input[name*="tinypng_sizes"]').on("click", function() {
|
160 |
+
// Unfortunately, we need some additional information to display the correct notice.
|
161 |
+
totalSelectedSizes = jQuery('input[name*="tinypng_sizes"]:checked').length
|
162 |
+
jQuery('#tiny-image-sizes-notice').load(ajaxurl + '?action=tiny_image_sizes_notice&image_sizes_selected=' + totalSelectedSizes)
|
163 |
+
})
|
164 |
}
|
165 |
|
166 |
jQuery('.tiny-notice a.tiny-dismiss').click(dismiss_notice)
|
test/integration/PluginIntegrationTest.php
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
require_once(dirname(__FILE__) . "/IntegrationTestCase.php");
|
4 |
+
|
5 |
+
class PluginIntegrationTest extends IntegrationTestCase {
|
6 |
+
|
7 |
+
public function setUp() {
|
8 |
+
parent::setUp();
|
9 |
+
self::$driver->get(wordpress('/wp-admin/plugins.php'));
|
10 |
+
}
|
11 |
+
|
12 |
+
public function tearDown() {
|
13 |
+
clear_settings();
|
14 |
+
}
|
15 |
+
|
16 |
+
public function testTitlePresence()
|
17 |
+
{
|
18 |
+
$element = self::$driver->findElements(WebDriverBy::xpath('//*[@id="compress-jpeg-png-images"]//a[text()="Settings"]'));
|
19 |
+
$this->assertStringEndsWith('options-media.php#tiny-compress-images', $element[0]->getAttribute('href'));
|
20 |
+
}
|
21 |
+
}
|
test/integration/SettingsIntegrationTest.php
CHANGED
@@ -86,6 +86,38 @@ class SettingsIntegrationTest extends IntegrationTestCase {
|
|
86 |
$this->assertEquals(0, count(array_map('elementName', $elements)));
|
87 |
}
|
88 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
public function testStatusPresenceOK() {
|
90 |
reset_webservice();
|
91 |
$this->set_api_key('PNG123');
|
86 |
$this->assertEquals(0, count(array_map('elementName', $elements)));
|
87 |
}
|
88 |
|
89 |
+
public function testShouldShowTotalImagesInfo() {
|
90 |
+
$elements = self::$driver->findElement(WebDriverBy::id('tiny-image-sizes-notice'))->findElements(WebDriverBy::tagName('p'));
|
91 |
+
$statuses = array_map('innerText', $elements);
|
92 |
+
$this->assertContains('With these settings you can compress 100 images for free each month.', $statuses);
|
93 |
+
}
|
94 |
+
|
95 |
+
public function testShouldUpdateTotalImagesInfo() {
|
96 |
+
$element = self::$driver->findElement(
|
97 |
+
WebDriverBy::xpath('//input[@type="checkbox" and @name="tinypng_sizes[0]" and @checked="checked"]'));
|
98 |
+
$element->click();
|
99 |
+
self::$driver->wait(2)->until(WebDriverExpectedCondition::textToBePresentInElement(
|
100 |
+
WebDriverBy::cssSelector('#tiny-image-sizes-notice'), 'With these settings you can compress 125 images for free each month.'));
|
101 |
+
// Not really necessary anymore to assert this.
|
102 |
+
$elements = self::$driver->findElement(WebDriverBy::id('tiny-image-sizes-notice'))->findElements(WebDriverBy::tagName('p'));
|
103 |
+
$statuses = array_map('innerText', $elements);
|
104 |
+
$this->assertContains('With these settings you can compress 125 images for free each month.', $statuses);
|
105 |
+
}
|
106 |
+
|
107 |
+
public function testShouldShowCorrectNoImageSizesInfo() {
|
108 |
+
$elements = self::$driver->findElements(
|
109 |
+
WebDriverBy::xpath('//input[@type="checkbox" and starts-with(@name, "tinypng_sizes") and @checked="checked"]'));
|
110 |
+
foreach ($elements as $element) {
|
111 |
+
$element->click();
|
112 |
+
}
|
113 |
+
self::$driver->wait(2)->until(WebDriverExpectedCondition::textToBePresentInElement(
|
114 |
+
WebDriverBy::cssSelector('#tiny-image-sizes-notice'), 'With these settings no images will be compressed.'));
|
115 |
+
// Not really necessary anymore to assert this.
|
116 |
+
$elements = self::$driver->findElement(WebDriverBy::id('tiny-image-sizes-notice'))->findElements(WebDriverBy::tagName('p'));
|
117 |
+
$statuses = array_map('innerText', $elements);
|
118 |
+
$this->assertContains('With these settings no images will be compressed.', $statuses);
|
119 |
+
}
|
120 |
+
|
121 |
public function testStatusPresenceOK() {
|
122 |
reset_webservice();
|
123 |
$this->set_api_key('PNG123');
|
tiny-compress-images.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
/**
|
3 |
* Plugin Name: Compress JPEG & PNG images
|
4 |
* Description: Speed up your website. Optimize your JPEG and PNG images automatically with TinyPNG.
|
5 |
-
* Version: 1.
|
6 |
* Author: TinyPNG
|
7 |
* Author URI: https://tinypng.com
|
8 |
* License: GPLv2 or later
|
2 |
/**
|
3 |
* Plugin Name: Compress JPEG & PNG images
|
4 |
* Description: Speed up your website. Optimize your JPEG and PNG images automatically with TinyPNG.
|
5 |
+
* Version: 1.4.0
|
6 |
* Author: TinyPNG
|
7 |
* Author URI: https://tinypng.com
|
8 |
* License: GPLv2 or later
|