Regenerate Thumbnails - Version 2.2.3

Version Description

Make the capability required to use this plugin filterable so themes and other plugins can change it. Props Jackson Whelan.

Download this release

Release Info

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

Code changes from version 2.2.0 to 2.2.3

Files changed (2) hide show
  1. readme.txt +25 -2
  2. regenerate-thumbnails.php +20 -13
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: Viper007Bond
3
  Donate link: http://www.viper007bond.com/donate/
4
  Tags: thumbnail, thumbnails
5
  Requires at least: 2.8
6
- Tested up to: 3.1
7
  Stable tag: trunk
8
 
9
  Allows you to regenerate your thumbnails after changing the thumbnail sizes.
@@ -31,6 +31,18 @@ See the [screenshots tab](http://wordpress.org/extend/plugins/regenerate-thumbna
31
 
32
  == ChangeLog ==
33
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  = Version 2.2.0 =
35
 
36
  * Changes to the Bulk Action functionality were made shortly before the release of WordPress 3.1 which broke the way I implemented the specific multiple image regeneration feature. This version adds to the Bulk Action menu using Javascript as that's the only way to do it currently.
@@ -85,4 +97,15 @@ Lots of new features!
85
 
86
  = Version 1.0.0 =
87
 
88
- * Initial release.
 
 
 
 
 
 
 
 
 
 
 
3
  Donate link: http://www.viper007bond.com/donate/
4
  Tags: thumbnail, thumbnails
5
  Requires at least: 2.8
6
+ Tested up to: 3.3
7
  Stable tag: trunk
8
 
9
  Allows you to regenerate your thumbnails after changing the thumbnail sizes.
31
 
32
  == ChangeLog ==
33
 
34
+ = Version 2.2.3 =
35
+
36
+ * Make the capability required to use this plugin filterable so themes and other plugins can change it. Props [Jackson Whelan](http://jacksonwhelan.com/).
37
+
38
+ = Version 2.2.2 =
39
+
40
+ * Don't check the nonce until we're sure that the action called was for this plugin. Fixes lots of "Are you sure you want to do this?" error messages.
41
+
42
+ = Version 2.2.1 =
43
+
44
+ * Fix the bottom bulk action dropdown. Thanks Stefan for pointing out the issue!
45
+
46
  = Version 2.2.0 =
47
 
48
  * Changes to the Bulk Action functionality were made shortly before the release of WordPress 3.1 which broke the way I implemented the specific multiple image regeneration feature. This version adds to the Bulk Action menu using Javascript as that's the only way to do it currently.
97
 
98
  = Version 1.0.0 =
99
 
100
+ * Initial release.
101
+
102
+ == Upgrade Notice ==
103
+
104
+ = 2.2.3 =
105
+ Make the capability required to use this plugin filterable so themes and other plugins can change it. Props [Jackson Whelan](http://jacksonwhelan.com/).
106
+
107
+ = 2.2.2 =
108
+ Fixes lots of "Are you sure you want to do this?" error messages.
109
+
110
+ = 2.2.1 =
111
+ Fix the bottom bulk action dropdown. Thanks Stefan for pointing out the issue!
regenerate-thumbnails.php CHANGED
@@ -5,13 +5,13 @@
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: 2.2.0
9
  Author: Viper007Bond
10
  Author URI: http://www.viper007bond.com/
11
 
12
  **************************************************************************
13
 
14
- Copyright (C) 2008-2010 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
@@ -33,9 +33,6 @@ class RegenerateThumbnails {
33
 
34
  // Plugin initialization
35
  function RegenerateThumbnails() {
36
- if ( ! function_exists( 'admin_url' ) )
37
- return false;
38
-
39
  // Load up the localization file if we're using WordPress in a different language
40
  // Place it in this plugin's "localization" folder and name it "regenerate-thumbnails-[value in wp-config].mo"
41
  load_plugin_textdomain( 'regenerate-thumbnails', false, '/regenerate-thumbnails/localization' );
@@ -45,14 +42,18 @@ class RegenerateThumbnails {
45
  add_action( 'wp_ajax_regeneratethumbnail', array( &$this, 'ajax_process_image' ) );
46
  add_filter( 'media_row_actions', array( &$this, 'add_media_row_action' ), 10, 2 );
47
  //add_filter( 'bulk_actions-upload', array( &$this, 'add_bulk_actions' ), 99 ); // A last minute change to 3.1 makes this no longer work
48
- add_action( 'admin_head-upload.php', array( &$this, 'add_bulk_actions_via_javascript' ) );
49
- add_action( 'admin_action_bulk_regenerate_thumbnails', array( &$this, 'bulk_action_handler' ) );
 
 
 
 
50
  }
51
 
52
 
53
  // Register the management page
54
  function add_admin_menu() {
55
- $this->menu_id = add_management_page( __( 'Regenerate Thumbnails', 'regenerate-thumbnails' ), __( 'Regen. Thumbnails', 'regenerate-thumbnails' ), 'manage_options', 'regenerate-thumbnails', array(&$this, 'regenerate_interface') );
56
  }
57
 
58
 
@@ -73,7 +74,7 @@ class RegenerateThumbnails {
73
 
74
  // Add a "Regenerate Thumbnails" link to the media row actions
75
  function add_media_row_action( $actions, $post ) {
76
- if ( 'image/' != substr( $post->post_mime_type, 0, 6 ) )
77
  return $actions;
78
 
79
  $url = wp_nonce_url( admin_url( 'tools.php?page=regenerate-thumbnails&goback=1&ids=' . $post->ID ), 'regenerate-thumbnails' );
@@ -102,7 +103,10 @@ class RegenerateThumbnails {
102
 
103
  // Add new items to the Bulk Actions using Javascript
104
  // A last minute change to the "bulk_actions-xxxxx" filter in 3.1 made it not possible to add items using that
105
- function add_bulk_actions_via_javascript() { ?>
 
 
 
106
  <script type="text/javascript">
107
  jQuery(document).ready(function($){
108
  $('select[name^="action"] option:last-child').before('<option value="bulk_regenerate_thumbnails"><?php echo esc_attr( __( 'Regenerate Thumbnails', 'regenerate-thumbnails' ) ); ?></option>');
@@ -114,11 +118,14 @@ class RegenerateThumbnails {
114
 
115
  // Handles the bulk actions POST
116
  function bulk_action_handler() {
117
- check_admin_referer( 'bulk-media' );
 
118
 
119
  if ( empty( $_REQUEST['media'] ) || ! is_array( $_REQUEST['media'] ) )
120
  return;
121
 
 
 
122
  $ids = implode( ',', array_map( 'intval', $_REQUEST['media'] ) );
123
 
124
  // Can't use wp_nonce_url() as it escapes HTML entities
@@ -143,7 +150,7 @@ class RegenerateThumbnails {
143
  // If the button was clicked
144
  if ( ! empty( $_POST['regenerate-thumbnails'] ) || ! empty( $_REQUEST['ids'] ) ) {
145
  // Capability check
146
- if ( !current_user_can( 'manage_options' ) )
147
  wp_die( __( 'Cheatin&#8217; uh?' ) );
148
 
149
  // Form nonce check
@@ -346,7 +353,7 @@ class RegenerateThumbnails {
346
  if ( ! $image || 'attachment' != $image->post_type || 'image/' != substr( $image->post_mime_type, 0, 6 ) )
347
  die( json_encode( array( 'error' => sprintf( __( 'Failed resize: %s is an invalid image ID.', 'regenerate-thumbnails' ), esc_html( $_REQUEST['id'] ) ) ) ) );
348
 
349
- if ( !current_user_can( 'manage_options' ) )
350
  $this->die_json_error_msg( $image->ID, __( "Your user account doesn't have permission to resize images", 'regenerate-thumbnails' ) );
351
 
352
  $fullsizepath = get_attached_file( $image->ID );
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: 2.2.3
9
  Author: Viper007Bond
10
  Author URI: http://www.viper007bond.com/
11
 
12
  **************************************************************************
13
 
14
+ Copyright (C) 2008-2011 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
33
 
34
  // Plugin initialization
35
  function RegenerateThumbnails() {
 
 
 
36
  // Load up the localization file if we're using WordPress in a different language
37
  // Place it in this plugin's "localization" folder and name it "regenerate-thumbnails-[value in wp-config].mo"
38
  load_plugin_textdomain( 'regenerate-thumbnails', false, '/regenerate-thumbnails/localization' );
42
  add_action( 'wp_ajax_regeneratethumbnail', array( &$this, 'ajax_process_image' ) );
43
  add_filter( 'media_row_actions', array( &$this, 'add_media_row_action' ), 10, 2 );
44
  //add_filter( 'bulk_actions-upload', array( &$this, 'add_bulk_actions' ), 99 ); // A last minute change to 3.1 makes this no longer work
45
+ add_action( 'admin_head-upload.php', array( &$this, 'add_bulk_actions_via_javascript' ) );
46
+ add_action( 'admin_action_bulk_regenerate_thumbnails', array( &$this, 'bulk_action_handler' ) ); // Top drowndown
47
+ add_action( 'admin_action_-1', array( &$this, 'bulk_action_handler' ) ); // Bottom dropdown (assumes top dropdown = default value)
48
+
49
+ // Allow people to change what capability is required to use this plugin
50
+ $this->capability = apply_filters( 'regenerate_thumbs_cap', 'manage_options' );
51
  }
52
 
53
 
54
  // Register the management page
55
  function add_admin_menu() {
56
+ $this->menu_id = add_management_page( __( 'Regenerate Thumbnails', 'regenerate-thumbnails' ), __( 'Regen. Thumbnails', 'regenerate-thumbnails' ), $this->capability, 'regenerate-thumbnails', array(&$this, 'regenerate_interface') );
57
  }
58
 
59
 
74
 
75
  // Add a "Regenerate Thumbnails" link to the media row actions
76
  function add_media_row_action( $actions, $post ) {
77
+ if ( 'image/' != substr( $post->post_mime_type, 0, 6 ) || ! current_user_can( $this->capability ) )
78
  return $actions;
79
 
80
  $url = wp_nonce_url( admin_url( 'tools.php?page=regenerate-thumbnails&goback=1&ids=' . $post->ID ), 'regenerate-thumbnails' );
103
 
104
  // Add new items to the Bulk Actions using Javascript
105
  // A last minute change to the "bulk_actions-xxxxx" filter in 3.1 made it not possible to add items using that
106
+ function add_bulk_actions_via_javascript() {
107
+ if ( ! current_user_can( $this->capability ) )
108
+ return;
109
+ ?>
110
  <script type="text/javascript">
111
  jQuery(document).ready(function($){
112
  $('select[name^="action"] option:last-child').before('<option value="bulk_regenerate_thumbnails"><?php echo esc_attr( __( 'Regenerate Thumbnails', 'regenerate-thumbnails' ) ); ?></option>');
118
 
119
  // Handles the bulk actions POST
120
  function bulk_action_handler() {
121
+ if ( empty( $_REQUEST['action'] ) || ( 'bulk_regenerate_thumbnails' != $_REQUEST['action'] && 'bulk_regenerate_thumbnails' != $_REQUEST['action2'] ) )
122
+ return;
123
 
124
  if ( empty( $_REQUEST['media'] ) || ! is_array( $_REQUEST['media'] ) )
125
  return;
126
 
127
+ check_admin_referer( 'bulk-media' );
128
+
129
  $ids = implode( ',', array_map( 'intval', $_REQUEST['media'] ) );
130
 
131
  // Can't use wp_nonce_url() as it escapes HTML entities
150
  // If the button was clicked
151
  if ( ! empty( $_POST['regenerate-thumbnails'] ) || ! empty( $_REQUEST['ids'] ) ) {
152
  // Capability check
153
+ if ( ! current_user_can( $this->capability ) )
154
  wp_die( __( 'Cheatin&#8217; uh?' ) );
155
 
156
  // Form nonce check
353
  if ( ! $image || 'attachment' != $image->post_type || 'image/' != substr( $image->post_mime_type, 0, 6 ) )
354
  die( json_encode( array( 'error' => sprintf( __( 'Failed resize: %s is an invalid image ID.', 'regenerate-thumbnails' ), esc_html( $_REQUEST['id'] ) ) ) ) );
355
 
356
+ if ( ! current_user_can( $this->capability ) )
357
  $this->die_json_error_msg( $image->ID, __( "Your user account doesn't have permission to resize images", 'regenerate-thumbnails' ) );
358
 
359
  $fullsizepath = get_attached_file( $image->ID );