Version Description
- New CORE to regenerate thumbnails
Download this release
Release Info
Developer | Pedro Elsner |
Plugin | Force Regenerate Thumbnails |
Version | 1.6 |
Comparing to | |
See all releases |
Code changes from version 1.5 to 1.6
- force-regenerate-thumbnails.php +90 -95
- readme.txt +6 -2
force-regenerate-thumbnails.php
CHANGED
@@ -2,8 +2,8 @@
|
|
2 |
/*
|
3 |
Plugin Name: Force Regenerate Thumbnails
|
4 |
Plugin URI: http://pedroelsner.com/2012/08/forcando-a-atualizacao-de-thumbnails-no-wordpress
|
5 |
-
Description: Delete and REALLY force the regenerate thumbnail.
|
6 |
-
Version: 1.
|
7 |
Author: Pedro Elsner
|
8 |
Author URI: http://www.pedroelsner.com/
|
9 |
*/
|
@@ -97,12 +97,13 @@ class ForceRegenerateThumbnails {
|
|
97 |
}
|
98 |
|
99 |
// WordPress 3.1 vs older version compatibility
|
100 |
-
if (wp_script_is('jquery-ui-widget', 'registered')) {
|
101 |
-
|
102 |
-
} else {
|
103 |
-
|
104 |
-
}
|
105 |
|
|
|
106 |
wp_enqueue_style('jquery-ui-regenthumbs', plugins_url('jquery-ui/redmond/jquery-ui-1.7.2.custom.css', __FILE__), array(), '1.7.2');
|
107 |
}
|
108 |
|
@@ -419,103 +420,97 @@ class ForceRegenerateThumbnails {
|
|
419 |
// Don't break the JSON result
|
420 |
@error_reporting(0);
|
421 |
|
422 |
-
header('Content-type: application/json');
|
423 |
|
424 |
-
|
425 |
-
$image = get_post($id);
|
426 |
|
427 |
-
|
428 |
-
die(json_encode(array('error' => sprintf(__('<span style="color: #FF3366;">Failed: %s is an invalid image ID.</span>', 'force-regenerate-thumbnails'), esc_html($_REQUEST['id'])))));
|
429 |
-
return;
|
430 |
-
}
|
431 |
|
432 |
-
|
433 |
-
$
|
434 |
-
return;
|
435 |
-
}
|
436 |
|
437 |
-
|
|
|
|
|
|
|
438 |
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
* Grant image deleted
|
451 |
-
* @since 1.1
|
452 |
-
*/
|
453 |
-
$message = '';
|
454 |
-
|
455 |
-
|
456 |
-
/**
|
457 |
-
* Fix for format JPEG
|
458 |
-
* 12-11-2012 11h AM
|
459 |
-
*/
|
460 |
-
$array_path = explode(DIRECTORY_SEPARATOR, $fullsizepath);
|
461 |
-
$array_file = explode('.', $array_path[count($array_path)-1]);
|
462 |
-
|
463 |
-
$imageFormat = $array_file[count($array_file)-1];
|
464 |
-
|
465 |
-
unset($array_path[count($array_path)-1]);
|
466 |
-
unset($array_file[count($array_file)-1]);
|
467 |
-
|
468 |
-
$imagePath = implode(DIRECTORY_SEPARATOR, $array_path) . DIRECTORY_SEPARATOR . implode('.', $array_file);
|
469 |
-
|
470 |
|
471 |
-
|
472 |
-
|
473 |
-
*/
|
474 |
-
$dirPath = explode(DIRECTORY_SEPARATOR, $imagePath);
|
475 |
-
$imageName = sprintf("%s-", $dirPath[count($dirPath)-1]);
|
476 |
-
unset($dirPath[count($dirPath)-1]);
|
477 |
-
$dirPath = sprintf("%s%s", implode(DIRECTORY_SEPARATOR, $dirPath), DIRECTORY_SEPARATOR);
|
478 |
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
496 |
}
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
/**
|
501 |
-
* Regenerate
|
502 |
-
*/
|
503 |
-
$metadata = wp_generate_attachment_metadata($image->ID, $fullsizepath);
|
504 |
-
|
505 |
-
if (is_wp_error($metadata)) {
|
506 |
-
$this->die_json_error_msg($image->ID, $metadata->get_error_message());
|
507 |
-
return;
|
508 |
-
}
|
509 |
-
|
510 |
-
if (empty($metadata)) {
|
511 |
-
$this->die_json_error_msg($image->ID, __('<span style="color: #FF3366;">Unknown failure reason.</span>', 'force-regenerate-thumbnails'));
|
512 |
-
return;
|
513 |
-
}
|
514 |
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
519 |
}
|
520 |
|
521 |
/**
|
2 |
/*
|
3 |
Plugin Name: Force Regenerate Thumbnails
|
4 |
Plugin URI: http://pedroelsner.com/2012/08/forcando-a-atualizacao-de-thumbnails-no-wordpress
|
5 |
+
Description: Delete and REALLY force the regenerate thumbnail.
|
6 |
+
Version: 1.6
|
7 |
Author: Pedro Elsner
|
8 |
Author URI: http://www.pedroelsner.com/
|
9 |
*/
|
97 |
}
|
98 |
|
99 |
// WordPress 3.1 vs older version compatibility
|
100 |
+
//if (wp_script_is('jquery-ui-widget', 'registered')) {
|
101 |
+
// wp_enqueue_script('jquery-ui-progressbar', plugins_url('jquery-ui/jquery.ui.progressbar.min.js', __FILE__), array('jquery-ui-core', 'jquery-ui-widget'), '1.8.6');
|
102 |
+
//} else {
|
103 |
+
// wp_enqueue_script('jquery-ui-progressbar', plugins_url('jquery-ui/jquery.ui.progressbar.min.1.7.2.js', __FILE__), array('jquery-ui-core'), '1.7.2');
|
104 |
+
//}
|
105 |
|
106 |
+
wp_enqueue_script('jquery-ui-progressbar', plugins_url('jquery-ui/jquery.ui.progressbar.min.1.7.2.js', __FILE__), array('jquery-ui-core'), '1.7.2');
|
107 |
wp_enqueue_style('jquery-ui-regenthumbs', plugins_url('jquery-ui/redmond/jquery-ui-1.7.2.custom.css', __FILE__), array(), '1.7.2');
|
108 |
}
|
109 |
|
420 |
// Don't break the JSON result
|
421 |
@error_reporting(0);
|
422 |
|
|
|
423 |
|
424 |
+
try {
|
|
|
425 |
|
426 |
+
header('Content-type: application/json');
|
|
|
|
|
|
|
427 |
|
428 |
+
$id = (int) $_REQUEST['id'];
|
429 |
+
$image = get_post($id);
|
|
|
|
|
430 |
|
431 |
+
if (!$image || 'attachment' != $image->post_type || 'image/' != substr($image->post_mime_type, 0, 6)) {
|
432 |
+
die(json_encode(array('error' => sprintf(__('<span style="color: #FF3366;">Failed: %s is an invalid image ID.</span>', 'force-regenerate-thumbnails'), esc_html($_REQUEST['id'])))));
|
433 |
+
return;
|
434 |
+
}
|
435 |
|
436 |
+
if (!current_user_can($this->capability)) {
|
437 |
+
$this->die_json_error_msg($image->ID, __('<span style="color: #FF3366;">Your user account does not have permission to regenerate images</span>', 'force-regenerate-thumbnails'));
|
438 |
+
return;
|
439 |
+
}
|
440 |
+
|
441 |
+
$fullsizepath = get_attached_file($image->ID);
|
442 |
+
|
443 |
+
if (false === $fullsizepath || !file_exists($fullsizepath)) {
|
444 |
+
$this->die_json_error_msg($image->ID, sprintf( __('<span style="color: #FF3366;">The originally uploaded image file cannot be found at %s</span>', 'force-regenerate-thumbnails'), '<code>' . esc_html($fullsizepath) . '</code>'));
|
445 |
+
return;
|
446 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
447 |
|
448 |
+
// 5 minutes per image should be PLENTY
|
449 |
+
@set_time_limit(900);
|
|
|
|
|
|
|
|
|
|
|
450 |
|
451 |
+
|
452 |
+
|
453 |
+
/**
|
454 |
+
* Grant image deleted
|
455 |
+
* @since 1.1
|
456 |
+
*/
|
457 |
+
$message = '';
|
458 |
+
|
459 |
+
|
460 |
+
/**
|
461 |
+
* New CORE 1.6 version
|
462 |
+
*/
|
463 |
+
$thumbnails = array();
|
464 |
+
$file_info = pathinfo($fullsizepath);
|
465 |
+
|
466 |
+
$message = '<br /> - Original file: ' . realpath($fullsizepath);
|
467 |
+
|
468 |
+
// Hack to find thumbnail
|
469 |
+
$file_info['filename'] .= '-';
|
470 |
+
|
471 |
+
$path = opendir($file_info['dirname']);
|
472 |
+
while (false !== ($thumb = readdir($path))) {
|
473 |
+
if (!(strrpos($thumb, $file_info['filename']) === false)) {
|
474 |
+
$thumb_fullpath = $file_info['dirname'] . DIRECTORY_SEPARATOR . $thumb;
|
475 |
+
$thumb_info = pathinfo($thumb_fullpath);
|
476 |
+
$valid_thumb = explode($file_info['filename'], $thumb_info['filename']);
|
477 |
+
if ($valid_thumb[0] == "") {
|
478 |
+
$dimension_thumb = explode('x', $valid_thumb[1]);
|
479 |
+
if (count($dimension_thumb) == 2) {
|
480 |
+
if (is_numeric($dimension_thumb[0]) && is_numeric($dimension_thumb[1])) {
|
481 |
+
$message .= sprintf('<br /> - ' . __("Thumbnail: %sx%s was deleted.", 'force-regenerate-thumbnails'), $dimension_thumb[0], $dimension_thumb[1]);
|
482 |
+
@unlink(realpath($thumb_fullpath));
|
483 |
+
}
|
484 |
+
}
|
485 |
+
}
|
486 |
+
}
|
487 |
}
|
488 |
+
closedir($path);
|
489 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
490 |
|
491 |
+
/**
|
492 |
+
* Regenerate
|
493 |
+
*/
|
494 |
+
$metadata = wp_generate_attachment_metadata($image->ID, $fullsizepath);
|
495 |
+
|
496 |
+
if (is_wp_error($metadata)) {
|
497 |
+
$this->die_json_error_msg($image->ID, $metadata->get_error_message());
|
498 |
+
return;
|
499 |
+
}
|
500 |
+
|
501 |
+
if (empty($metadata)) {
|
502 |
+
$this->die_json_error_msg($image->ID, __('<span style="color: #FF3366;">Unknown failure reason.</span>', 'force-regenerate-thumbnails'));
|
503 |
+
return;
|
504 |
+
}
|
505 |
+
|
506 |
+
wp_update_attachment_metadata($image->ID, $metadata);
|
507 |
+
|
508 |
+
$message = sprintf(__('<b>"%1$s" (ID %2$s): All thumbnails was successfully regenerated in %3$s seconds.</b>', 'force-regenerate-thumbnails'), esc_html(get_the_title($image->ID)), $image->ID, timer_stop()) . $message;
|
509 |
+
die(json_encode(array('success' => $message)));
|
510 |
+
|
511 |
+
} catch (Exception $e) {
|
512 |
+
die(json_encode(array('error' => "Fatal Error: " . $e->getMessage())));
|
513 |
+
}
|
514 |
}
|
515 |
|
516 |
/**
|
readme.txt
CHANGED
@@ -9,12 +9,13 @@ Delete and REALLY force the regenerate thumbnail.
|
|
9 |
|
10 |
== Description ==
|
11 |
|
12 |
-
* Based in plugin: Regenerate Thumbnails - All credits and thanks to Viper007Bond
|
13 |
-
|
14 |
Force Regenerate Thumbnails allows you to delete all old images size and REALLY regenerate the thumbnails for your image attachments.
|
15 |
|
16 |
See the [screenshots tab](http://wordpress.org/extend/plugins/force-regenerate-thumbnails/screenshots/) for more details.
|
17 |
|
|
|
|
|
|
|
18 |
== Installation ==
|
19 |
|
20 |
1. Go to your admin area and select Plugins -> Add new from the menu.
|
@@ -29,6 +30,9 @@ See the [screenshots tab](http://wordpress.org/extend/plugins/force-regenerate-t
|
|
29 |
|
30 |
== ChangeLog ==
|
31 |
|
|
|
|
|
|
|
32 |
= 1.5 =
|
33 |
* Reviewed some messages
|
34 |
|
9 |
|
10 |
== Description ==
|
11 |
|
|
|
|
|
12 |
Force Regenerate Thumbnails allows you to delete all old images size and REALLY regenerate the thumbnails for your image attachments.
|
13 |
|
14 |
See the [screenshots tab](http://wordpress.org/extend/plugins/force-regenerate-thumbnails/screenshots/) for more details.
|
15 |
|
16 |
+
* Regenerate Thumbnails improved - All credits and thanks to Viper007Bond
|
17 |
+
|
18 |
+
|
19 |
== Installation ==
|
20 |
|
21 |
1. Go to your admin area and select Plugins -> Add new from the menu.
|
30 |
|
31 |
== ChangeLog ==
|
32 |
|
33 |
+
= 1.6 =
|
34 |
+
* New CORE to regenerate thumbnails
|
35 |
+
|
36 |
= 1.5 =
|
37 |
* Reviewed some messages
|
38 |
|