4b9d6dc7 by Jeff Balicki

media fix

Signed-off-by: Jeff <jeff@gotenzing.com>
1 parent 8bf74f6c
1 /* This is based on jQuery UI */
2 #regenerate-thumbnails-app .ui-progressbar {
3 height: 2em;
4 text-align: center;
5 overflow: hidden;
6 }
7 #regenerate-thumbnails-app .ui-progressbar .ui-progressbar-value {
8 margin: -1px;
9 height: 100%;
10 transition-duration: 0.5s;
11 }
12 #regenerate-thumbnails-app .ui-widget.ui-widget-content {
13 border: 1px solid #c5dbec;
14 }
15 #regenerate-thumbnails-app .ui-widget-content {
16 border: 1px solid #a6c9e2;
17 background: #fcfdfd url("images/ui-bg_inset-hard_100_fcfdfd_1x100.png") 50% bottom repeat-x;
18 color: #222222;
19 }
20 #regenerate-thumbnails-app .ui-widget-header {
21 border: 1px solid #4297d7;
22 background: #5c9ccc url("images/ui-bg_gloss-wave_55_5c9ccc_500x100.png") 50% 50% repeat-x;
23 color: #ffffff;
24 font-weight: bold;
25 }
26 #regenerate-thumbnails-app .ui-corner-all {
27 border-radius: 5px;
28 }
29 #regenerate-thumbnails-app .ui-corner-left {
30 border-top-left-radius: 5px;
31 border-bottom-left-radius: 5px;
32 }
This diff could not be displayed because it is too large.
1 /*!
2 * Vue.js v2.6.11
3 * (c) 2014-2019 Evan You
4 * Released under the MIT License.
5 */
1 <?php
2 /**
3 * Regenerate Thumbnails: REST API controller class
4 *
5 * @package RegenerateThumbnails
6 * @since 3.0.0
7 */
8
9 /**
10 * Registers new REST API endpoints.
11 *
12 * @since 3.0.0
13 */
14 class RegenerateThumbnails_REST_Controller extends WP_REST_Controller {
15 /**
16 * The namespace for the REST API routes.
17 *
18 * @since 3.0.0
19 *
20 * @var string
21 */
22 public $namespace = 'regenerate-thumbnails/v1';
23
24 /**
25 * Register the new routes and endpoints.
26 *
27 * @since 3.0.0
28 */
29 public function register_routes() {
30 register_rest_route( $this->namespace, '/regenerate/(?P<id>[\d]+)', array(
31 array(
32 'methods' => WP_REST_Server::ALLMETHODS,
33 'callback' => array( $this, 'regenerate_item' ),
34 'permission_callback' => array( $this, 'permissions_check' ),
35 'args' => array(
36 'only_regenerate_missing_thumbnails' => array(
37 'description' => __( "Whether to only regenerate missing thumbnails. It's faster with this enabled.", 'regenerate-thumbnails' ),
38 'type' => 'boolean',
39 'default' => true,
40 ),
41 'delete_unregistered_thumbnail_files' => array(
42 'description' => __( 'Whether to delete any old, now unregistered thumbnail files.', 'regenerate-thumbnails' ),
43 'type' => 'boolean',
44 'default' => false,
45 ),
46 'update_usages_in_posts' => array(
47 'description' => __( 'Whether to update the image tags in any posts that make use of this attachment.', 'regenerate-thumbnails' ),
48 'type' => 'boolean',
49 'default' => true,
50 ),
51 'update_usages_in_posts_post_type' => array(
52 'description' => __( 'The types of posts to update. Defaults to all public post types.', 'regenerate-thumbnails' ),
53 'type' => 'array',
54 'default' => array(),
55 'validate_callback' => array( $this, 'is_array' ),
56 ),
57 'update_usages_in_posts_post_ids' => array(
58 'description' => __( 'Specific post IDs to update rather than any posts that use this attachment.', 'regenerate-thumbnails' ),
59 'type' => 'array',
60 'default' => array(),
61 'validate_callback' => array( $this, 'is_array' ),
62 ),
63 'update_usages_in_posts_posts_per_loop' => array(
64 'description' => __( "Posts to process per loop. This is to control memory usage and you likely don't need to adjust this.", 'regenerate-thumbnails' ),
65 'type' => 'integer',
66 'default' => 10,
67 'sanitize_callback' => 'absint',
68 ),
69 ),
70 ),
71 ) );
72
73 register_rest_route( $this->namespace, '/attachmentinfo/(?P<id>[\d]+)', array(
74 array(
75 'methods' => WP_REST_Server::READABLE,
76 'callback' => array( $this, 'attachment_info' ),
77 'permission_callback' => array( $this, 'permissions_check' ),
78 ),
79 ) );
80
81 register_rest_route( $this->namespace, '/featuredimages', array(
82 array(
83 'methods' => WP_REST_Server::READABLE,
84 'callback' => array( $this, 'featured_images' ),
85 'permission_callback' => array( $this, 'permissions_check' ),
86 'args' => $this->get_paging_collection_params(),
87 ),
88 ) );
89 }
90
91 /**
92 * Register a filter to allow excluding site icons via a query parameter.
93 *
94 * @since 3.0.0
95 */
96 public function register_filters() {
97 add_filter( 'rest_attachment_query', array( $this, 'maybe_filter_out_site_icons' ), 10, 2 );
98 add_filter( 'rest_attachment_query', array( $this, 'maybe_filter_mimes_types' ), 10, 2 );
99 }
100
101 /**
102 * If the exclude_site_icons parameter is set on a media (attachment) request,
103 * filter out any attachments that are or were being used as a site icon.
104 *
105 * @param array $args Key value array of query var to query value.
106 * @param WP_REST_Request $request The request used.
107 *
108 * @return array Key value array of query var to query value.
109 */
110 public function maybe_filter_out_site_icons( $args, $request ) {
111 if ( empty( $request['exclude_site_icons'] ) ) {
112 return $args;
113 }
114
115 if ( ! isset( $args['meta_query'] ) ) {
116 $args['meta_query'] = array();
117 }
118
119 $args['meta_query'][] = array(
120 'key' => '_wp_attachment_context',
121 'value' => 'site-icon',
122 'compare' => 'NOT EXISTS',
123 );
124
125 return $args;
126 }
127
128 /**
129 * If the is_regeneratable parameter is set on a media (attachment) request,
130 * filter results to only include images and PDFs.
131 *
132 * @param array $args Key value array of query var to query value.
133 * @param WP_REST_Request $request The request used.
134 *
135 * @return array Key value array of query var to query value.
136 */
137 public function maybe_filter_mimes_types( $args, $request ) {
138 if ( empty( $request['is_regeneratable'] ) ) {
139 return $args;
140 }
141
142 $args['post_mime_type'] = array();
143 foreach ( get_allowed_mime_types() as $mime_type ) {
144 if ( 'image/svg+xml' === $mime_type ) {
145 continue;
146 }
147
148 if ( 'application/pdf' == $mime_type || 'image/' == substr( $mime_type, 0, 6 ) ) {
149 $args['post_mime_type'][] = $mime_type;
150 }
151 }
152
153 return $args;
154 }
155
156 /**
157 * Retrieves the paging query params for the collections.
158 *
159 * @since 3.0.0
160 *
161 * @return array Query parameters for the collection.
162 */
163 public function get_paging_collection_params() {
164 return array_intersect_key(
165 parent::get_collection_params(),
166 array_flip( array( 'page', 'per_page' ) )
167 );
168 }
169
170 /**
171 * Regenerate the thumbnails for a specific media item.
172 *
173 * @since 3.0.0
174 *
175 * @param WP_REST_Request $request Full data about the request.
176 *
177 * @return true|WP_Error True on success, otherwise a WP_Error object.
178 */
179 public function regenerate_item( $request ) {
180 $regenerator = RegenerateThumbnails_Regenerator::get_instance( $request->get_param( 'id' ) );
181
182 if ( is_wp_error( $regenerator ) ) {
183 return $regenerator;
184 }
185
186 $result = $regenerator->regenerate( array(
187 'only_regenerate_missing_thumbnails' => $request->get_param( 'only_regenerate_missing_thumbnails' ),
188 'delete_unregistered_thumbnail_files' => $request->get_param( 'delete_unregistered_thumbnail_files' ),
189 ) );
190
191 if ( is_wp_error( $result ) ) {
192 return $result;
193 }
194
195 if ( $request->get_param( 'update_usages_in_posts' ) ) {
196 $posts_updated = $regenerator->update_usages_in_posts( array(
197 'post_type' => $request->get_param( 'update_usages_in_posts_post_type' ),
198 'post_ids' => $request->get_param( 'update_usages_in_posts_post_ids' ),
199 'posts_per_loop' => $request->get_param( 'update_usages_in_posts_posts_per_loop' ),
200 ) );
201
202 // If wp_update_post() failed for any posts, return that error.
203 foreach ( $posts_updated as $post_updated_result ) {
204 if ( is_wp_error( $post_updated_result ) ) {
205 return $post_updated_result;
206 }
207 }
208 }
209
210 return $this->attachment_info( $request );
211 }
212
213 /**
214 * Return a bunch of information about the current attachment for use in the UI
215 * including details about the thumbnails.
216 *
217 * @since 3.0.0
218 *
219 * @param WP_REST_Request $request Full data about the request.
220 *
221 * @return array|WP_Error The data array or a WP_Error object on error.
222 */
223 public function attachment_info( $request ) {
224 $regenerator = RegenerateThumbnails_Regenerator::get_instance( $request->get_param( 'id' ) );
225
226 if ( is_wp_error( $regenerator ) ) {
227 return $regenerator;
228 }
229
230 return $regenerator->get_attachment_info();
231 }
232
233 /**
234 * Return attachment IDs that are being used as featured images.
235 *
236 * @since 3.0.0
237 *
238 * @param WP_REST_Request $request Full data about the request.
239 *
240 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
241 */
242 public function featured_images( $request ) {
243 global $wpdb;
244
245 $page = $request->get_param( 'page' );
246 $per_page = $request->get_param( 'per_page' );
247
248 if ( 0 == $per_page ) {
249 $per_page = 10;
250 }
251
252 $featured_image_ids = $wpdb->get_results( $wpdb->prepare(
253 "SELECT SQL_CALC_FOUND_ROWS meta_value AS id FROM {$wpdb->postmeta} WHERE meta_key = '_thumbnail_id' GROUP BY meta_value ORDER BY MIN(meta_id) LIMIT %d OFFSET %d",
254 $per_page,
255 ( $per_page * $page ) - $per_page
256 ) );
257
258 $total = $wpdb->get_var( "SELECT FOUND_ROWS()" );
259 $max_pages = ceil( $total / $per_page );
260
261 if ( $page > $max_pages && $total > 0 ) {
262 return new WP_Error( 'rest_post_invalid_page_number', __( 'The page number requested is larger than the number of pages available.' ), array( 'status' => 400 ) );
263 }
264
265 $response = rest_ensure_response( $featured_image_ids );
266
267 $response->header( 'X-WP-Total', (int) $total );
268 $response->header( 'X-WP-TotalPages', (int) $max_pages );
269
270 $request_params = $request->get_query_params();
271 $base = add_query_arg( $request_params, rest_url( $this->namespace . '/featuredimages' ) );
272
273 if ( $page > 1 ) {
274 $prev_page = $page - 1;
275
276 if ( $prev_page > $max_pages ) {
277 $prev_page = $max_pages;
278 }
279
280 $prev_link = add_query_arg( 'page', $prev_page, $base );
281 $response->link_header( 'prev', $prev_link );
282 }
283
284 if ( $max_pages > $page ) {
285 $next_page = $page + 1;
286 $next_link = add_query_arg( 'page', $next_page, $base );
287
288 $response->link_header( 'next', $next_link );
289 }
290
291 return $response;
292 }
293
294 /**
295 * Check to see if the current user is allowed to use this endpoint.
296 *
297 * @since 3.0.0
298 *
299 * @param WP_REST_Request $request Full data about the request.
300 *
301 * @return bool Whether the current user has permission to regenerate thumbnails.
302 */
303 public function permissions_check( $request ) {
304 return current_user_can( RegenerateThumbnails()->capability );
305 }
306
307 /**
308 * Returns whether a variable is an array or not. This is needed because 3 arguments are
309 * passed to validation callbacks but is_array() only accepts one argument.
310 *
311 * @since 3.0.0
312 *
313 * @see https://core.trac.wordpress.org/ticket/34659
314 *
315 * @param mixed $param The parameter value to validate.
316 * @param WP_REST_Request $request The REST request.
317 * @param string $key The parameter name.
318 *
319 * @return bool Whether the parameter is an array or not.
320 */
321 public function is_array( $param, $request, $key ) {
322 return is_array( $param );
323 }
324 }
1 !function(a){function b(a){return a=b.buildAjaxOptions(a),b.transport(a)}var c=window.wpApiSettings;b.buildAjaxOptions=function(b){var d,e,f,g,h,i=b.url,j=b.path;if("string"==typeof b.namespace&&"string"==typeof b.endpoint&&(d=b.namespace.replace(/^\/|\/$/g,""),e=b.endpoint.replace(/^\//,""),j=e?d+"/"+e:d),"string"==typeof j&&(i=c.root+j.replace(/^\//,"")),g=!(b.data&&b.data._wpnonce),f=b.headers||{},g)for(h in f)if(f.hasOwnProperty(h)&&"x-wp-nonce"===h.toLowerCase()){g=!1;break}return g&&(f=a.extend({"X-WP-Nonce":c.nonce},f)),b=a.extend({},b,{headers:f,url:i}),delete b.path,delete b.namespace,delete b.endpoint,b},b.transport=a.ajax,window.wp=window.wp||{},window.wp.apiRequest=b}(jQuery);
...\ No newline at end of file ...\ No newline at end of file
1 === Regenerate Thumbnails ===
2 Contributors: Viper007Bond
3 Tags: thumbnail, thumbnails, post thumbnail, post thumbnails
4 Requires at least: 4.7
5 Tested up to: 6.3
6 Requires PHP: 5.2.4
7 Stable tag: 3.1.6
8 License: GPLv2 or later
9 License URI: https://www.gnu.org/licenses/gpl-2.0.html
10
11 Regenerate the thumbnails for one or more of your image uploads. Useful when changing their sizes or your theme.
12
13 == Description ==
14
15 Regenerate Thumbnails allows you to regenerate all thumbnail sizes for one or more images that have been uploaded to your Media Library.
16
17 This is useful for situations such as:
18
19 * A new thumbnail size has been added and you want past uploads to have a thumbnail in that size.
20 * You've changed the dimensions of an existing thumbnail size, for example via Settings → Media.
21 * You've switched to a new WordPress theme that uses featured images of a different size.
22
23 It also offers the ability to delete old, unused thumbnails in order to free up server space.
24
25 = In Memory of Alex Mills =
26
27 In February 2019 Alex Mills, the author of this plugin, [passed away](https://alex.blog/2019/02/27/from-alexs-family/). He leaves behind a number of plugins which will be maintained by Automattic and members of the WordPress community. If this plugin is useful to you please consider donating to the Oregon Health and Science University. You can find more information [here](https://alex.blog/2019/03/13/in-memory-of-alex-donation-link-update/).
28
29 = Alternatives =
30
31 **WP-CLI**
32
33 If you have command line access to your server, I highly recommend using [WP-CLI](https://wp-cli.org/) instead of this plugin as it's faster (no HTTP requests overhead) and can be run inside of a `screen` for those with many thumbnails. For details, see the documentation of its [`media regenerate` command](https://developer.wordpress.org/cli/commands/media/regenerate/).
34
35 **Jetpack's Photon Module**
36
37 [Jetpack](https://jetpack.com/) is a plugin by Automattic, makers of WordPress.com. It gives your self-hosted WordPress site some of the functionality that is available to WordPress.com-hosted sites.
38
39 [The Photon module](https://jetpack.com/support/photon/) makes the images on your site be served from WordPress.com's global content delivery network (CDN) which should speed up the loading of images. Importantly though it can create thumbnails on the fly which means you'll never need to use this plugin.
40
41 I personally use Photon on my own website.
42
43 *Disclaimer: I work for Automattic but I would recommend Photon even if I didn't.*
44
45 = Need Help? Found A Bug? Want To Contribute Code? =
46
47 Support for this plugin is provided via the [WordPress.org forums](https://wordpress.org/support/plugin/regenerate-thumbnails).
48
49 The source code for this plugin is available on [GitHub](https://github.com/automattic/regenerate-thumbnails).
50
51 == Installation ==
52
53 1. Go to your admin area and select Plugins → Add New from the menu.
54 2. Search for "Regenerate Thumbnails".
55 3. Click install.
56 4. Click activate.
57 5. Navigate to Tools → Regenerate Thumbnails.
58
59 == Frequently Asked Questions ==
60
61 = Is this plugin [GDPR](https://en.wikipedia.org/wiki/General_Data_Protection_Regulation) compliant? =
62
63 This plugin does not log nor transmit any user data. Infact it doesn't even do anything on the user-facing part of your website, only in the admin area. This means it should be compliant but I'm not a lawyer.
64
65 == Screenshots ==
66
67 1. The main plugin interface.
68 2. Regenerating in progress.
69 3. Interface for regenerating a single attachment.
70 4. Individual images can be regenerated from the media library in list view.
71 5. They can also be regenerated from the edit attachment screen.
72
73 == ChangeLog ==
74
75 = Version 3.1.6 =
76
77 * Fix: Respect "Skip regenerating existing correctly sized thumbnails" setting.
78 * Fix: Don't delete all thumbnails when deleting old unregistered thumbnails size.
79
80 = Version 3.1.5 =
81
82 * Fix: Don't overwrite 'All X Attachment' button label with featured images count.
83 * Tested successfully with PHP 8.1.
84 * Tested successfully with PHP 8.2.
85
86 = Version 3.1.4 =
87
88 * Fix: Don't attempt to regenerate SVG's.
89 * Bump tested version.
90 * Update dependencies.
91
92 = Version 3.1.3 =
93
94 * Update plugin dependencies to the latest version.
95
96 = Version 3.1.2 =
97 * Use wp_get_original_image_path() in WordPress 5.3
98
99 = Version 3.1.1 =
100
101 * Minor fix to avoid a divide by zero error when displaying thumbnail filenames.
102
103 = Version 3.1.0 =
104
105 * Bring back the ability to delete old, unregistered thumbnail sizes. Support for updating post contents is still disabled (too buggy).
106 * Various code improvements including string localization disambiguation.
107
108 = Version 3.0.2 =
109
110 * Fix slowdown in certain cases in the media library.
111 * Fix not being able to regenerate existing thumbnails for single images. Props @idofri.
112 * Fix JavaScript error that could occur if the REST API response was unexpected (empty or PHP error).
113 * Fix bug related to multibyte filenames.
114 * If an image is used as the featured image on multiple posts, only regenerate it once instead of once per post.
115
116 = Version 3.0.1 =
117
118 * Temporarily disable the update post functionality. I tested it a lot but it seems there's still some bugs.
119 * Temporarily disable the delete old thumbnails functionality. It seems to work fine but without the update post functionality, it's not as useful.
120 * Try to more gracefully handle cases where there's missing metadata for attachments.
121 * Wait until `init` to initialize the plugin so themes can filter the plugin's capability. `plugins_loaded` is too early.
122 * Fix a JavaScript error that would cause the whole regeneration process to stop if an individual image returned non-JSON, such as a 500 error code.
123 * Accept GET requests for the regenerate REST API endpoint instead of just POSTs. For some reasons some people's sites are using GET despite the code saying use POST.
124 * Make the attachment ID clickable in error messages.
125 * Fetch 25 attachments at a time instead of 5. I was using 5 for testing.
126 * PHP notice fixes.
127
128 = Version 3.0.0 =
129
130 * Complete rewrite from scratch using Vue.js and the WordPress REST API.
131
132 = Version 2.2.4 =
133
134 * Better AJAX response error handling in the JavaScript. This should fix a long-standing bug in this plugin. Props Hew Sutton.
135
136 = Version 2.2.3 =
137
138 * Make the capability required to use this plugin filterable so themes and other plugins can change it. Props [Jackson Whelan](http://jacksonwhelan.com/).
139
140 = Version 2.2.2 =
141
142 * 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.
143
144 = Version 2.2.1 =
145
146 * Fix the bottom bulk action dropdown. Thanks Stefan for pointing out the issue!
147
148 = Version 2.2.0 =
149
150 * 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.
151
152 = Version 2.1.3 =
153
154 * Move the `error_reporting()` call in the AJAX handler to the beginning so that we're more sure that no PHP errors are outputted. Some hosts disable usage of `set_time_limit()` and calling it was causing a PHP warning to be outputted.
155
156 = Version 2.1.2 =
157
158 * When regenerating all images, newest images are done first rather than the oldest.
159 * Fixed a bug with regeneration error reporting in some browsers. Thanks to pete-sch for reporting the error.
160 * Supress PHP errors in the AJAX handler to avoid sending an invalid JSON response. Thanks to pete-sch for reporting the error.
161 * Better and more detailed error reporting for when `wp_generate_attachment_metadata()` fails.
162
163 = Version 2.1.1 =
164
165 * Clean up the wording a bit to better match the new features and just be easier to understand.
166 * Updated screenshots.
167
168 = Version 2.1.0 =
169
170 Lots of new features!
171
172 * Thanks to a lot of jQuery help from [Boris Schapira](http://borisschapira.com/), a failed image regeneration will no longer stop the whole process.
173 * The results of each image regeneration is now outputted. You can easily see which images were successfully regenerated and which failed. Was inspired by a concept by Boris.
174 * There is now a button on the regeneration page that will allow you to abort resizing images for any reason. Based on code by Boris.
175 * You can now regenerate single images from the Media page. The link to do so will show up in the actions list when you hover over the row.
176 * You can now bulk regenerate multiple from the Media page. Check the boxes and then select "Regenerate Thumbnails" form the "Bulk Actions" dropdown. WordPress 3.1+ only.
177 * The total time that the regeneration process took is now displayed in the final status message.
178 * jQuery UI Progressbar version upgraded.
179
180 = Version 2.0.3 =
181
182 * Switch out deprecated function call.
183
184 = Version 2.0.2 =
185
186 * Directly query the database to only fetch what the plugin needs (the attachment ID). This will reduce the memory required as it's not storing the whole row for each attachment.
187
188 = Version 2.0.1 =
189
190 * I accidentally left a `check_admin_referer()` (nonce check) commented out.
191
192 = Version 2.0.0 =
193
194 * Recoded from scratch. Now uses an AJAX request per attachment to do the resizing. No more PHP maximum execution time errors or anything like that. Also features a pretty progress bar to let the user know how it's going.
195
196 = Version 1.1.0 =
197
198 * WordPress 2.7 updates -- code + UI. Thanks to jdub and Patrick F.
199
200 = Version 1.0.0 =
201
202 * Initial release.
203
204 = Upgrade Notice =
205 Support for WordPress 5.3
...@@ -94,3 +94,20 @@ function set_exclude_from_search() ...@@ -94,3 +94,20 @@ function set_exclude_from_search()
94 } 94 }
95 } 95 }
96 } 96 }
97
98 add_action('init','delete_exclude_from_search');
99 function delete_exclude_from_search()
100 {
101 if ($_GET['var'] =='delete_wpml_from_search') {
102 $args = array( 'posts_per_page' => -1, 'post_type' => 'attachment');
103 $pages = get_posts( $args );
104 foreach ( $pages as $page ){
105 $exclude_from_search = get_post_meta($page->ID, 'exclude_from_search', true);
106 if($exclude_from_search == '0'){
107 wp_delete_attachment( $page->ID, true );
108 //error_log($page->ID);
109 }
110 }
111 }
112
113 }
...\ No newline at end of file ...\ No newline at end of file
......