Skip to content

Commit 4df6281

Browse files
author
Jacob Middag
committed
Only show bulk action and button on upload page and make naming more consistent
1 parent 04d07e9 commit 4df6281

4 files changed

Lines changed: 30 additions & 25 deletions

File tree

src/class-tiny-plugin.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,20 @@ public function init() {
5353
public function admin_init() {
5454
add_filter('manage_media_columns', $this->get_method('add_media_columns'));
5555
add_action('manage_media_custom_column', $this->get_method('render_media_column'), 10, 2);
56-
add_action('wp_ajax_tinypng_compress_image', $this->get_method('compress_image'));
57-
add_action('admin_action_tinypng_bulk_compress', $this->get_method('bulk_compress'));
56+
add_action('wp_ajax_tiny_compress_image', $this->get_method('compress_image'));
57+
add_action('admin_action_tiny_bulk_compress', $this->get_method('bulk_compress'));
5858
add_action('admin_enqueue_scripts', $this->get_method('enqueue_scripts'));
5959
}
6060

61-
public function enqueue_scripts() {
61+
public function enqueue_scripts($hook) {
6262
wp_enqueue_style(self::NAME .'_admin', plugins_url('/styles/admin.css', __FILE__),
6363
array(), self::plugin_version());
6464

6565
$handle = self::NAME .'_admin';
6666
wp_register_script($handle, plugins_url('/scripts/admin.js', __FILE__),
6767
array(), self::plugin_version(), true);
68-
wp_localize_script($handle, 'tinypngImageCompressL10n', array(
68+
69+
wp_localize_script($handle, 'tinyCompressL10n', array(
6970
'bulkAction' => self::translate('Compress all uncompressed sizes'),
7071
));
7172
wp_enqueue_script($handle);
@@ -167,7 +168,7 @@ public function render_media_column($column, $id) {
167168
if (($error = $tiny_metadata->get_latest_error())) {
168169
echo '<span class="error">' . self::translate_escape('Latest error') . ': '. self::translate_escape($error) .'<br/>';
169170
}
170-
echo '<button type="button" class="tinypng-compress" data-id="' . $id . '">' .
171+
echo '<button type="button" class="tiny-compress" data-id="' . $id . '">' .
171172
self::translate_escape('Compress') . '</button>';
172173
echo '<div class="spinner"></div>';
173174
} else {

src/scripts/admin.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,33 @@
1-
(function () {
2-
var compress_image = function(event) {
1+
(function() {
2+
3+
function compress_image(event) {
34
var element = jQuery(event.target);
45
element.attr('disabled', 'disabled');
56
element.closest('td').find('.spinner').css('display', 'inline');
67
jQuery.post(
78
ajaxurl, {
8-
'action': 'tinypng_compress_image',
9+
'action': 'tiny_compress_image',
910
'id': element.data('id') || element.attr('data-id')
1011
}, function (response) {
1112
element.closest('td').html(response);
1213
}
1314
);
1415
}
15-
if (typeof jQuery.fn.on === "function") {
16-
jQuery('table').on('click', 'button.tinypng-compress', compress_image);
17-
} else {
18-
jQuery('button.tinypng-compress').live('click', compress_image);
19-
}
2016

21-
if (typeof jQuery.fn.prop === "function") {
22-
jQuery('button.tinypng-compress').prop('disabled', null)
23-
} else {
24-
jQuery('button.tinypng-compress').attr('disabled', null)
25-
}
17+
if (adminpage === "upload-php") {
18+
if (typeof jQuery.fn.on === "function") {
19+
jQuery('table').on('click', 'button.tiny-compress', compress_image);
20+
} else {
21+
jQuery('button.tiny-compress').live('click', compress_image);
22+
}
2623

27-
jQuery('<option>').val('tinypng_bulk_compress').text(tinypngImageCompressL10n.bulkAction).appendTo('select[name="action"]');
28-
jQuery('<option>').val('tinypng_bulk_compress').text(tinypngImageCompressL10n.bulkAction).appendTo('select[name="action2"]');
24+
if (typeof jQuery.fn.prop === "function") {
25+
jQuery('button.tiny-compress').prop('disabled', null)
26+
} else {
27+
jQuery('button.tiny-compress').attr('disabled', null)
28+
}
29+
30+
jQuery('<option>').val('tiny_bulk_compress').text(tinyCompressL10n.bulkAction).appendTo('select[name="action"]');
31+
jQuery('<option>').val('tiny_bulk_compress').text(tinyCompressL10n.bulkAction).appendTo('select[name="action2"]');
32+
}
2933
}).call();

src/styles/admin.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
.tinypng-image-compression .spinner {
1+
.tiny-compress-images .spinner {
22
display: none;
33
}

test/integration/BulkCompressIntegrationTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ public function testBulkCompressActionShouldBePresent()
1717
{
1818
$this->upload_image(dirname(__FILE__) . '/../fixtures/example-tinypng.png');
1919
self::$driver->get(wordpress('/wp-admin/upload.php?mode=list'));
20-
$this->assertEquals('tinypng_bulk_compress', self::$driver->findElement(
21-
WebDriverBy::cssSelector('select[name="action"] option[value="tinypng_bulk_compress"]')
22-
)->getAttribute('value'));
20+
$this->assertEquals('Compress all uncompressed sizes', self::$driver->findElement(
21+
WebDriverBy::cssSelector('select[name="action"] option[value="tiny_bulk_compress"]')
22+
)->getText());
2323
}
2424

2525
public function testBulkCompressShouldCompressUncompressedSizes() {
@@ -29,7 +29,7 @@ public function testBulkCompressShouldCompressUncompressedSizes() {
2929
$this->upload_image(dirname(__FILE__) . '/../fixtures/example-large.png');
3030

3131
$this->enable_compression_sizes(array('thumbnail', 'medium'));
32-
media_bulk_action(self::$driver, 'tinypng_bulk_compress');
32+
media_bulk_action(self::$driver, 'tiny_bulk_compress');
3333

3434
$this->assertContains('Compressed 2 out of 2 sizes', self::$driver->findElement(WebDriverBy::cssSelector('td.tiny-compress-images'))->getText());
3535
}

0 commit comments

Comments
 (0)