Version Description
- Add new image size to attachment meta so WordPress can perform actions on the image
Download this release
Release Info
Developer | bfintal |
Plugin | OTF Regenerate Thumbnails |
Version | 0.3 |
Comparing to | |
See all releases |
Code changes from version 0.2 to 0.3
- otf_regen_thumbs.php +33 -26
- readme.txt +5 -1
otf_regen_thumbs.php
CHANGED
@@ -4,7 +4,7 @@ Plugin Name: OTF Regenerate Thumbnails
|
|
4 |
Plugin URI: http://github.com
|
5 |
Description: Automatically regenerates your thumbnails on the fly (OTF) after changing the thumbnail sizes or switching themes.
|
6 |
Author: Benjamin Intal - Gambit Technologies Inc
|
7 |
-
Version: 0.
|
8 |
Author URI: http://gambit.ph
|
9 |
*/
|
10 |
|
@@ -35,7 +35,7 @@ if ( ! function_exists( 'gambit_otf_regen_thumbs_media_downsize' ) ) {
|
|
35 |
// all the theme/plugin-introduced sizes.
|
36 |
global $_gambit_otf_regen_thumbs_all_image_sizes;
|
37 |
if ( ! isset( $_gambit_otf_regen_thumbs_all_image_sizes ) ) {
|
38 |
-
|
39 |
|
40 |
$_gambit_otf_regen_thumbs_all_image_sizes = array();
|
41 |
$interimSizes = get_intermediate_image_sizes();
|
@@ -57,8 +57,8 @@ if ( ! function_exists( 'gambit_otf_regen_thumbs_media_downsize' ) ) {
|
|
57 |
// This now contains all the data that we have for all the image sizes
|
58 |
$allSizes = $_gambit_otf_regen_thumbs_all_image_sizes;
|
59 |
|
60 |
-
|
61 |
-
|
62 |
|
63 |
// Image attachment doesn't exist
|
64 |
if ( ! is_array( $imagedata ) ) {
|
@@ -90,34 +90,34 @@ if ( ! function_exists( 'gambit_otf_regen_thumbs_media_downsize' ) ) {
|
|
90 |
return false;
|
91 |
}
|
92 |
}
|
93 |
-
|
94 |
-
|
95 |
|
96 |
// Resize the image
|
97 |
$resized = image_make_intermediate_size(
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
|
104 |
// Resize somehow failed
|
105 |
if ( ! $resized ) {
|
106 |
return false;
|
107 |
}
|
108 |
|
109 |
-
|
110 |
-
|
111 |
|
112 |
// Save some additional info so that we'll know next time whether we've resized this before
|
113 |
$imagedata['sizes'][ $size ]['width_query'] = $allSizes[ $size ]['width'];
|
114 |
$imagedata['sizes'][ $size ]['height_query'] = $allSizes[ $size ]['height'];
|
115 |
|
116 |
-
|
117 |
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
|
122 |
|
123 |
// If the size given is a custom array size
|
@@ -137,21 +137,28 @@ if ( ! function_exists( 'gambit_otf_regen_thumbs_media_downsize' ) ) {
|
|
137 |
|
138 |
// If not, resize the image...
|
139 |
$resized = image_make_intermediate_size(
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
146 |
// Resize somehow failed
|
147 |
if ( ! $resized ) {
|
148 |
return false;
|
149 |
}
|
150 |
|
151 |
-
|
152 |
-
|
153 |
}
|
154 |
|
155 |
return false;
|
156 |
}
|
157 |
-
}
|
4 |
Plugin URI: http://github.com
|
5 |
Description: Automatically regenerates your thumbnails on the fly (OTF) after changing the thumbnail sizes or switching themes.
|
6 |
Author: Benjamin Intal - Gambit Technologies Inc
|
7 |
+
Version: 0.3
|
8 |
Author URI: http://gambit.ph
|
9 |
*/
|
10 |
|
35 |
// all the theme/plugin-introduced sizes.
|
36 |
global $_gambit_otf_regen_thumbs_all_image_sizes;
|
37 |
if ( ! isset( $_gambit_otf_regen_thumbs_all_image_sizes ) ) {
|
38 |
+
global $_wp_additional_image_sizes;
|
39 |
|
40 |
$_gambit_otf_regen_thumbs_all_image_sizes = array();
|
41 |
$interimSizes = get_intermediate_image_sizes();
|
57 |
// This now contains all the data that we have for all the image sizes
|
58 |
$allSizes = $_gambit_otf_regen_thumbs_all_image_sizes;
|
59 |
|
60 |
+
// If image size exists let WP serve it like normally
|
61 |
+
$imagedata = wp_get_attachment_metadata( $id );
|
62 |
|
63 |
// Image attachment doesn't exist
|
64 |
if ( ! is_array( $imagedata ) ) {
|
90 |
return false;
|
91 |
}
|
92 |
}
|
93 |
+
|
94 |
+
}
|
95 |
|
96 |
// Resize the image
|
97 |
$resized = image_make_intermediate_size(
|
98 |
+
get_attached_file( $id ),
|
99 |
+
$allSizes[ $size ]['width'],
|
100 |
+
$allSizes[ $size ]['height'],
|
101 |
+
$allSizes[ $size ]['crop']
|
102 |
+
);
|
103 |
|
104 |
// Resize somehow failed
|
105 |
if ( ! $resized ) {
|
106 |
return false;
|
107 |
}
|
108 |
|
109 |
+
// Save the new size in WP
|
110 |
+
$imagedata['sizes'][ $size ] = $resized;
|
111 |
|
112 |
// Save some additional info so that we'll know next time whether we've resized this before
|
113 |
$imagedata['sizes'][ $size ]['width_query'] = $allSizes[ $size ]['width'];
|
114 |
$imagedata['sizes'][ $size ]['height_query'] = $allSizes[ $size ]['height'];
|
115 |
|
116 |
+
wp_update_attachment_metadata( $id, $imagedata );
|
117 |
|
118 |
+
// Serve the resized image
|
119 |
+
$att_url = wp_get_attachment_url( $id );
|
120 |
+
return array( dirname( $att_url ) . '/' . $resized['file'], $resized['width'], $resized['height'], true );
|
121 |
|
122 |
|
123 |
// If the size given is a custom array size
|
137 |
|
138 |
// If not, resize the image...
|
139 |
$resized = image_make_intermediate_size(
|
140 |
+
get_attached_file( $id ),
|
141 |
+
$size[0],
|
142 |
+
$size[1],
|
143 |
+
true
|
144 |
+
);
|
145 |
+
|
146 |
+
// Get attachment meta so we can add new size
|
147 |
+
$imagedata = wp_get_attachment_metadata( $id );
|
148 |
+
|
149 |
+
// Save the new size in WP so that it can also perform actions on it
|
150 |
+
$imagedata['sizes'][ $size[0] . 'x' . $size[1] ] = $resized;
|
151 |
+
wp_update_attachment_metadata( $id, $imagedata );
|
152 |
+
|
153 |
// Resize somehow failed
|
154 |
if ( ! $resized ) {
|
155 |
return false;
|
156 |
}
|
157 |
|
158 |
+
// Then serve it
|
159 |
+
return array( dirname( $att_url ) . '/' . $resized['file'], $resized['width'], $resized['height'], true );
|
160 |
}
|
161 |
|
162 |
return false;
|
163 |
}
|
164 |
+
}
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
|
|
4 |
Tags: thumbnail, thumbnails, resize, regenerate, automatic, featured image, feature image, on the fly, otf
|
5 |
Requires at least: 3.8
|
6 |
Tested up to: 4.1
|
7 |
-
Stable tag: 0.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -83,6 +83,10 @@ You can also add size *names* using [`add_image_size`](http://codex.wordpress.or
|
|
83 |
|
84 |
== Changelog ==
|
85 |
|
|
|
|
|
|
|
|
|
86 |
= 0.2 =
|
87 |
|
88 |
* Bug fix: image size names which do not exist
|
4 |
Tags: thumbnail, thumbnails, resize, regenerate, automatic, featured image, feature image, on the fly, otf
|
5 |
Requires at least: 3.8
|
6 |
Tested up to: 4.1
|
7 |
+
Stable tag: 0.3
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
83 |
|
84 |
== Changelog ==
|
85 |
|
86 |
+
= 0.3 =
|
87 |
+
|
88 |
+
* Add new image size to attachment meta so WordPress can perform actions on the image
|
89 |
+
|
90 |
= 0.2 =
|
91 |
|
92 |
* Bug fix: image size names which do not exist
|