Skip to content

Commit fe9aa6d

Browse files
author
Edwin Westerhoud
committed
Small changes to the limit reach admin notice and translations of it.
1 parent fb0fc8e commit fe9aa6d

5 files changed

Lines changed: 21 additions & 9 deletions

File tree

src/class-tiny-settings.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ public function after_compress_callback($details, $headers) {
191191
update_option($field, $headers["Compression-Count"]);
192192

193193
if (isset($details['error']) && $details['error'] == 'TooManyRequests') {
194-
$link = '<a href="https://tinypng.com/developers" target="_blank">' . self::translate_escape('TinyPNG API subscription') . '</a>';
195-
$this->add_admin_notice('limit_reached', sprintf(self::translate_escape('You have reached your limit of %s compressions this month. Upgrade your %s if you like to compress more images') . '.', $headers["Compression-Count"], $link));
194+
$link = '<a href="https://tinypng.com/developers" target="_blank">' . self::translate_escape('subscription') . '</a>';
195+
$this->add_admin_notice('limit_reached', sprintf(self::translate_escape('you have reached your limit of %s compressions this month. Upgrade your %s if you like to compress more images') . '.', $headers["Compression-Count"], $link));
196196
} else {
197197
$this->remove_admin_notice('limit_reached');
198198
}

src/class-tiny-wp-base.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,6 @@ public function remove_admin_notice($name) {
118118
}
119119

120120
private function show_admin_notice($name, $message) {
121-
add_action('admin_notices', create_function('', "echo '<div class=\"error\"><p>Tiny Compress Images: $message | <a href=\"?$name=0\">Dismiss</a></p></div>';"));
121+
add_action('admin_notices', create_function('', "echo '<div class=\"updated\"><p>Compress JPEG & PNG images: $message &nbsp;<a href=\"?$name=0\">" . self::translate_escape('Dismiss') . "</a></p></div>';"));
122122
}
123123
}
39 Bytes
Binary file not shown.

src/languages/tiny-compress-images-nl_NL.po

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ msgstr "De API-sleutel is geconfigureerd in %s"
106106
msgid "Connection status"
107107
msgstr "Verbinding status"
108108

109+
msgid "Dismiss"
110+
msgstr "Negeer"
111+
109112
msgid "TinyPNG API subscription"
110113
msgstr "TinyPNG API subscription"
111114

@@ -127,5 +130,5 @@ msgstr "Je hebt je maandelijkse limiet van %s compressies bereikt"
127130
msgid "If you need to compress more images you can change your %s"
128131
msgstr "Als je meer plaatjes wilt comprimeren kun je je %s aanpassen"
129132

130-
msgid "You have reached your limit of %s compressions this month. Upgrade your %s if you like to compress more images"
131-
msgstr "Je hebt je maandelijkse limiet van %s compressies bereikt. Upgrade je %s als je meer plaatjes wilt comprimeren"
133+
msgid "you have reached your limit of %s compressions this month. Upgrade your %s if you like to compress more images"
134+
msgstr "je hebt je maandelijkse limiet van %s compressies bereikt. Upgrade je %s als je meer plaatjes wilt comprimeren"

test/integration/CompressIntegrationTest.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,27 @@ public function testShrink() {
3535
public function testLimitReached() {
3636
$this->set_api_key('LIMIT123');
3737
$this->upload_image(dirname(__FILE__) . '/../fixtures/example-tinypng.png');
38-
$elements = self::$driver->findElement(WebDriverBy::className('error'))->findElements(WebDriverBy::tagName('p'));
38+
$elements = self::$driver->findElement(WebDriverBy::className('updated'))->findElements(WebDriverBy::tagName('p'));
3939
$error_messages = array_map('innerText', $elements);
40-
$this->assertContains('Tiny Compress Images: You have reached your limit of 500 compressions this month. Upgrade your TinyPNG API subscription if you like to compress more images. | Dismiss', $error_messages);
40+
foreach ($error_messages as $error) {
41+
if (strpos($error, 'you have reached your limit of 500 compressions this month')) {
42+
return;
43+
}
44+
}
45+
$this->fail('Admin notice has not been found');
4146
}
4247

4348
public function testLimitReachedDismisses() {
4449
$this->set_api_key('LIMIT123');
4550
$this->upload_image(dirname(__FILE__) . '/../fixtures/example-tinypng.png');
4651
$dismiss_links = self::$driver->findElements(WebDriverBy::xpath('//a[contains(@href, "tinypng_limit_reached=0")]'));
4752
$dismiss_links[0]->click();
48-
$elements = self::$driver->findElement(WebDriverBy::className('error'))->findElements(WebDriverBy::tagName('p'));
53+
$elements = self::$driver->findElements(WebDriverBy::xpath('//a[contains(@href, "tinypng_limit_reached=0")]'));
4954
$error_messages = array_map('innerText', $elements);
50-
$this->assertNotContains('Tiny Compress Images: You have reached your limit of 500 compressions this month. Upgrade your TinyPNG API subscription if you like to compress more images. | Dismiss', $error_messages);
55+
foreach ($error_messages as $error) {
56+
if (strpos($error, 'Dismiss')) {
57+
$this->fail('Admin notice should not be shown');
58+
}
59+
}
5160
}
5261
}

0 commit comments

Comments
 (0)