Regenerate Thumbnails - Version 1.0.0

Version Description

Download this release

Release Info

Developer Viper007Bond
Plugin Icon 128x128 Regenerate Thumbnails
Version 1.0.0
Comparing to
See all releases

Version 1.0.0

Files changed (4) hide show
  1. readme.txt +44 -0
  2. regenerate-thumbnails.php +169 -0
  3. screenshot-1.png +0 -0
  4. screenshot-2.png +0 -0
readme.txt ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Regenerate Thumbnails ===
2
+ Contributors: Viper007Bond
3
+ Donate link: http://www.viper007bond.com/donate/
4
+ Tags: thumbnail, thumbnails
5
+ Requires at least: 2.5
6
+ Stable tag: trunk
7
+
8
+ Allows you to regenerate all attachment thumbnails in just one-click.
9
+
10
+ == Description ==
11
+
12
+ With just one click, Regenerate Thumbnails will allow you to regenerate both sized thumbnails for all attachments. This is very handy if you've changed either of your thumbnail dimensions (via Settings -> Miscellaneous) after uploading images.
13
+
14
+ == Installation ==
15
+
16
+ ###Updgrading From A Previous Version###
17
+
18
+ To upgrade from a previous version of this plugin, delete the entire folder and files from the previous version of the plugin and then follow the installation instructions below.
19
+
20
+ ###Installing The Plugin###
21
+
22
+ Extract all files from the ZIP file, making sure to keep the file structure intact, and then upload it to `/wp-content/plugins/`.
23
+
24
+ This should result in the following file structure:
25
+
26
+ `- wp-content
27
+ - plugins
28
+ - regenerate-thumbnails
29
+ | readme.txt
30
+ | regenerate-thumbnails.php`
31
+
32
+ Then just visit your admin area and activate the plugin.
33
+
34
+ ###Plugin Usage###
35
+
36
+ Visit Manage -> Thumbnails to get started.
37
+
38
+ **See Also:** ["Installing Plugins" article on the WP Codex](http://codex.wordpress.org/Managing_Plugins#Installing_Plugins)
39
+
40
+ == ChangeLog ==
41
+
42
+ **Version 1.0.0**
43
+
44
+ * Initial release.
regenerate-thumbnails.php ADDED
@@ -0,0 +1,169 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php /*
2
+
3
+ **************************************************************************
4
+
5
+ Plugin Name: Regenerate Thumbnails
6
+ Plugin URI: http://www.viper007bond.com/wordpress-plugins/regenerate-thumbnails/
7
+ Description: Allows you to regenerate all thumbnails after changing the thumbnail sizes.
8
+ Version: 1.0.0
9
+ Author: Viper007Bond
10
+ Author URI: http://www.viper007bond.com/
11
+
12
+ **************************************************************************
13
+
14
+ Copyright (C) 2008 Viper007Bond
15
+
16
+ This program is free software: you can redistribute it and/or modify
17
+ it under the terms of the GNU General Public License as published by
18
+ the Free Software Foundation, either version 3 of the License, or
19
+ (at your option) any later version.
20
+
21
+ This program is distributed in the hope that it will be useful,
22
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
23
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24
+ GNU General Public License for more details.
25
+
26
+ You should have received a copy of the GNU General Public License
27
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
28
+
29
+ **************************************************************************/
30
+
31
+ class RegenerateThumbnails {
32
+
33
+ // Plugin initialization
34
+ function RegenerateThumbnails() {
35
+ // Load up the localization file if we're using WordPress in a different language
36
+ // Place it in this plugin's folder and name it "regenerate-thumbnails-[value in wp-config].mo"
37
+ load_plugin_textdomain( 'regenerate-thumbnails', FALSE, '/regenerate-thumbnails' );
38
+
39
+ add_action( 'admin_menu', array(&$this, 'AddAdminMenu') );
40
+ }
41
+
42
+
43
+ // Register the management page
44
+ function AddAdminMenu() {
45
+ add_management_page( __( 'Regenerate Thumbnails', 'regenerate-thumbnails' ), __( 'Thumbnails', 'regenerate-thumbnails' ), 'manage_options', 'regenerate-thumbnails', array(&$this, 'ManagementPage') );
46
+ }
47
+
48
+
49
+ // The user interface plus thumbnail regenerator
50
+ function ManagementPage() { ?>
51
+
52
+ <div id="message" class="updated fade" style="display:none"></div>
53
+
54
+ <div class="wrap">
55
+ <h2><?php _e('Regenerate Thumbnails', 'regenerate-thumbnails'); ?></h2>
56
+
57
+ <?php
58
+
59
+ // If the button was clicked
60
+ if ( !empty($_POST['regenerate-thumbnails']) ) {
61
+ // Capability check
62
+ if ( !current_user_can('manage_options') )
63
+ wp_die( __('Cheatin&#8217; uh?') );
64
+
65
+ // Form nonce check
66
+ check_admin_referer('regenerate-thumbnails');
67
+
68
+ // Record start time
69
+ $rt_starttime = explode(' ', microtime() );
70
+ $rt_starttime = $rt_starttime[1] + $rt_starttime[0];
71
+
72
+ // Get all image attachments
73
+ $attachments = get_children( 'post_type=attachment&post_mime_type=image' );
74
+
75
+ // Check for results
76
+ if ( FALSE === $attachments ) {
77
+ echo ' <p>' . __( "No attachments were found. Go upload some!", 'regenerate-thumbnails' ) . "</p>\n\n";
78
+ }
79
+
80
+ // Valid results, process them
81
+ else {
82
+ echo ' <p>' . __( "Please be patient while all thumbnails are regenerated. This can take a while if your server is slow (cheap hosting) or if you have many attachments. Do not navigate away from this page until this script is done or all thumbnails won't be resized. You will be notified when all regenerating is completed.", 'regenerate-thumbnails' ) . "</p>\n\n";
83
+
84
+ // Find out the path to the upload directory (so we can hide it)
85
+ $upload = wp_upload_dir();
86
+ $uploadpath = $upload['basedir'];
87
+
88
+ // Output progress so far to browser
89
+ $this->flush();
90
+
91
+ // Loop through each attachment
92
+ $count = 0;
93
+ echo " <ol>\n";
94
+ foreach ( $attachments as $attachment ) {
95
+ $fullsizepath = get_attached_file( $attachment->ID );
96
+
97
+ // If the file exists, regenerate thumbnail and update attachment metadata in all one go
98
+ if ( FALSE !== $fullsizepath && @file_exists($fullsizepath) ) {
99
+ // Start the execution time limit over but only allow 30 seconds for the image to be resized.
100
+ // This is a better solution than just doing set_time_limit( 0 ); in my opinion.
101
+ set_time_limit( 30 );
102
+
103
+ wp_update_attachment_metadata( $attachment->ID, wp_generate_attachment_metadata( $attachment->ID, $fullsizepath ) );
104
+
105
+ echo ' <li>' . str_replace( $uploadpath, '', $fullsizepath ) . " processed.</code></li>\n";
106
+ $count++;
107
+ }
108
+
109
+ // Output progress so far to browser
110
+ $this->flush();
111
+ }
112
+ echo " </ol>\n\n";
113
+
114
+ // Calculate time taken
115
+ $rt_endtime = explode(' ', microtime() );
116
+ $rt_endtime = $rt_endtime[1] + $rt_endtime[0];
117
+ $rt_timetotal = number_format_i18n( $rt_endtime - $rt_starttime, 3 );
118
+
119
+ // Output the fallback for no-JS users
120
+ echo ' <p><noscript>' . sprintf( __( 'All done! Processed %d attachments in %s seconds.', 'regenerate-thumbnails' ), $count, $rt_timetotal ) . "</noscript></p>\n\n";
121
+
122
+ // Output the Javascript to show the success box
123
+ ?>
124
+ <script type="text/javascript">
125
+ // <![CDATA[
126
+ jQuery(document).ready(function() {
127
+ jQuery("#message").html("<p><strong><?php echo js_escape( sprintf( __( 'All done! Processed %d attachments in %s seconds.', 'regenerate-thumbnails' ), $count, $rt_timetotal ) ); ?></strong></p>");
128
+ jQuery("#message").show();
129
+ });
130
+ // ]]>
131
+ </script>
132
+ <?php
133
+ }
134
+ }
135
+
136
+ // No button click? Display the form.
137
+ else {
138
+ ?>
139
+ <p><?php printf( __( "After you've changed either of the thumbnail dimensions on the <a href='%s'>miscellaneous settings page</a>, click the button below to regenerate all thumbnails (both the small and medium sizes) for all attachments. The old thumbnails will be kept to avoid any broken images due to hard-coded URLs.", 'regenerate-thumbnails'), 'options-misc.php' ); ?></p>
140
+
141
+ <p><?php _e( "This process is not reversible, although you can just change your thumbnail dimensions to old values and click the button again if you don't like the results.", 'regenerate-thumbnails'); ?></p>
142
+
143
+ <form method="post" action="">
144
+ <?php wp_nonce_field('regenerate-thumbnails') ?>
145
+
146
+
147
+ <p><input type="submit" class="button" name="regenerate-thumbnails" id="regenerate-thumbnails" value="<?php _e( 'Regenerate All Thumbnails', 'regenerate-thumbnails' ) ?>" /></p>
148
+
149
+ </form>
150
+ <?php
151
+ } // End if button
152
+ ?>
153
+ </div>
154
+
155
+ <?php
156
+ }
157
+
158
+
159
+ // Outputs all HTML up to this point to the browser
160
+ function flush() {
161
+ ob_flush();
162
+ flush();
163
+ }
164
+ }
165
+
166
+ // Start this plugin once all other plugins are fully loaded
167
+ add_action( 'plugins_loaded', create_function( '', 'global $RegenerateThumbnails; $RegenerateThumbnails = new RegenerateThumbnails();' ) );
168
+
169
+ ?>
screenshot-1.png ADDED
Binary file
screenshot-2.png ADDED
Binary file