Version Description
Download this release
Release Info
Developer | turcuciprian |
Plugin | reGenerate Thumbnails Advanced |
Version | 1.1.1 |
Comparing to | |
See all releases |
Code changes from version 1.1 to 1.1.1
- abExport.php +54 -54
- readme.txt +1 -1
- regenerate-thumbnails-advanced.php +158 -169
abExport.php
CHANGED
@@ -3,62 +3,62 @@
|
|
3 |
|
4 |
$abError = false;
|
5 |
include_once ABSPATH.'wp-admin/includes/plugin.php';
|
6 |
-
if (!function_exists('
|
7 |
-
|
8 |
-
function sample_admin_notice__success()
|
9 |
-
{
|
10 |
-
$pluginInstalled = false;
|
11 |
-
if (!function_exists('get_plugins')) {
|
12 |
-
require_once ABSPATH.'wp-admin/includes/plugin.php';
|
13 |
-
}
|
14 |
-
$allPlugins = get_plugins();
|
15 |
-
foreach ($allPlugins as $key => $value) {
|
16 |
-
if ($key === 'admin-builder/admin_builder.php') {
|
17 |
-
$pluginInstalled = true;
|
18 |
-
}
|
19 |
-
# code...
|
20 |
-
}
|
21 |
-
if(isset($_GET['action']) && $_GET['action']==='install-plugin' && isset($_GET['plugin']) && $_GET['plugin']==='admin-builder'){return;}
|
22 |
-
if ($pluginInstalled) {
|
23 |
-
//check if plugin is activated:
|
24 |
-
if (!is_plugin_active('admin-builder/admin_builder.php')) {
|
25 |
-
$abError = true;
|
26 |
-
$url = admin_url();
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
|
47 |
-
|
48 |
-
|
49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
}
|
51 |
}
|
52 |
-
add_action('admin_notices', 'sample_admin_notice__success');
|
53 |
}
|
54 |
-
}
|
55 |
-
if(!$abError){
|
56 |
-
if (!$abError) {
|
57 |
-
if (class_exists('loadFromPlugin')) {
|
58 |
-
|
59 |
-
$theJson = '{"menus":[{"label":"Posts","type":"post","name":"posts","unique":true,"children":[],"$$hashKey":"object:66"},{"label":"Pages","type":"page","name":"pages","unique":true,"children":[],"$$hashKey":"object:67"},{"label":"Reg. Thumbnails","type":"cPage","name":"regenerateThumbnailsAdvanced","unique":false,"children":[{"label":"General Settings","name":"tab1","context":"normal","priority":"default","fields":[{"name":"rtaOTF","type":"checkbox","label":"Auto Regenerate","description":"Check this if you want missing thumbnails to be created on the fly, when needed.","extraText":"Activate","$$hashKey":"object:293"}],"$$hashKey":"object:92"}],"capability":"manage_options","handler":"ab_regenerateThumbnailsAdvanced","pageTitle":"regenerate Thumbnails Settings","$$hashKey":"object:89","pageDescription":"Configure if you want to regenerate thumbnails on the fly or not. Just make sure to check the checkbox if you do want everything to be taken care of regarding unexisting plugins."}]}';
|
60 |
-
$lfp = new loadFromPlugin();
|
61 |
-
$lfp->load($theJson);
|
62 |
-
}
|
63 |
-
}
|
64 |
-
}
|
3 |
|
4 |
$abError = false;
|
5 |
include_once ABSPATH.'wp-admin/includes/plugin.php';
|
6 |
+
if (!function_exists('ab_admin_notice_success')) {
|
7 |
+
if (!is_plugin_active('admin-builder/admin-builder.php')) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
+
function ab_admin_notice_success()
|
10 |
+
{
|
11 |
+
$pluginInstalled = false;
|
12 |
+
if (!function_exists('get_plugins')) {
|
13 |
+
require_once ABSPATH.'wp-admin/includes/plugin.php';
|
14 |
+
}
|
15 |
+
$allPlugins = get_plugins();
|
16 |
+
foreach ($allPlugins as $key => $value) {
|
17 |
+
if ($key === 'admin-builder/admin_builder.php') {
|
18 |
+
$pluginInstalled = true;
|
19 |
+
}
|
20 |
+
# code...
|
21 |
+
}
|
22 |
+
if (isset($_GET['action']) && $_GET['action'] === 'install-plugin' && isset($_GET['plugin']) && $_GET['plugin'] === 'admin-builder') {
|
23 |
+
return;
|
24 |
+
}
|
25 |
+
if ($pluginInstalled) {
|
26 |
+
//check if plugin is activated:
|
27 |
+
$abError = true;
|
28 |
+
$url = admin_url();
|
29 |
+
|
30 |
+
echo '<div class="notice notice-error is-dismissible">';
|
31 |
+
echo '<h3>Step 3(final): Activate Admin Builder!</h3>';
|
32 |
+
echo '<p>';
|
33 |
+
echo 'To get the full functionality , activate Admin Builder from the <a href="'.$url.'/plugins.php"><span class="button-primary">plugins directory</span></a>.';
|
34 |
+
echo '</p>';
|
35 |
+
echo '</div>';
|
36 |
+
//plugin is activated
|
37 |
+
} else {
|
38 |
+
$abError = true;
|
39 |
+
echo '<div class="notice notice-error is-dismissible">';
|
40 |
+
echo '<h3>Step 2: Install Admin Builder</h3>';
|
41 |
+
echo '<p>';
|
42 |
+
echo 'To get the full functionality , install Admin Builder.';
|
43 |
+
echo '</p>';
|
44 |
+
echo '<p>';
|
45 |
+
$plugin_name = 'admin-builder';
|
46 |
+
$install_link = '<a href="'.esc_url(network_admin_url('plugin-install.php?tab=plugin-information&plugin='.$plugin_name.'&TB_iframe=true&width=600&height=550')).'" class="thickbox" title="More info about '.$plugin_name.'"><span class="button-primary">Install '.$plugin_name.'</span></a>';
|
47 |
|
48 |
+
echo $install_link;
|
49 |
+
echo '</p>';
|
50 |
+
echo '</div>';
|
51 |
+
}
|
52 |
+
}
|
53 |
+
add_action('admin_notices', 'sample_admin_notice__success');
|
54 |
+
}
|
55 |
+
}
|
56 |
+
if (!$abError) {
|
57 |
+
if (!$abError) {
|
58 |
+
if (class_exists('loadFromPlugin')) {
|
59 |
+
$theJson = '{"menus":[{"label":"Posts","type":"post","name":"posts","unique":true,"children":[],"$$hashKey":"object:66"},{"label":"Pages","type":"page","name":"pages","unique":true,"children":[],"$$hashKey":"object:67"},{"label":"Reg. Thumbnails","type":"cPage","name":"regenerateThumbnailsAdvanced","unique":false,"children":[{"label":"General Settings","name":"tab1","context":"normal","priority":"default","fields":[{"name":"rtaOTF","type":"checkbox","label":"Auto Regenerate","description":"Check this if you want missing thumbnails to be created on the fly, when needed.","extraText":"Activate","$$hashKey":"object:293"}],"$$hashKey":"object:92"}],"capability":"manage_options","handler":"ab_regenerateThumbnailsAdvanced","pageTitle":"regenerate Thumbnails Settings","$$hashKey":"object:89","pageDescription":"Configure if you want to regenerate thumbnails on the fly or not. Just make sure to check the checkbox if you do want everything to be taken care of regarding unexisting plugins."}]}';
|
60 |
+
$lfp = new loadFromPlugin();
|
61 |
+
$lfp->load($theJson);
|
62 |
}
|
63 |
}
|
|
|
64 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
|
|
4 |
Tags: regenerate, thumbnails, advanced, easy, day, weeek, month
|
5 |
Requires at least: 3.1
|
6 |
Tested up to: 4.4.1
|
7 |
-
Stable tag: 1.1
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
4 |
Tags: regenerate, thumbnails, advanced, easy, day, weeek, month
|
5 |
Requires at least: 3.1
|
6 |
Tested up to: 4.4.1
|
7 |
+
Stable tag: 1.1.1
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
regenerate-thumbnails-advanced.php
CHANGED
@@ -3,187 +3,176 @@
|
|
3 |
Plugin Name: reGenerate Thumbnails - advanced
|
4 |
Plugin URI: http://turcuciprian.com
|
5 |
Description: A plugin that makes regenerating thumbnails even easier than before and more flexible.
|
6 |
-
Version: 1.1
|
7 |
Author: turcuciprian
|
8 |
Author URI: http://turcuciprian.com
|
9 |
License: GPLv2 or later
|
10 |
Text Domain: RTA
|
11 |
*/
|
|
|
12 |
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
19 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
}
|
27 |
-
wp_enqueue_script('jquery-ui-progressbar');
|
28 |
-
wp_enqueue_script('jquery-ui-datepicker');
|
29 |
-
wp_enqueue_style('rta-jquery-ui', plugin_dir_url(__FILE__) . 'jquery-ui.min.css');
|
30 |
-
wp_enqueue_style('rta', plugin_dir_url(__FILE__) . 'style.css');
|
31 |
-
wp_enqueue_script('rta', plugin_dir_url(__FILE__) . 'script.js');
|
32 |
-
}
|
33 |
-
}
|
34 |
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
add_action('init','rtaInit');
|
40 |
-
function rtaInit(){
|
41 |
-
global $abGen;
|
42 |
-
$rotf = $abGen->getField('abOption_cPage_regenerateThumbnailsAdvanced','tab1','rtaOTF');
|
43 |
-
if ( ! function_exists( 'gambit_otf_regen_thumbs_media_downsize' ) && $rotf=='on') {
|
44 |
-
add_filter( 'image_downsize', 'gambit_otf_regen_thumbs_media_downsize', 10, 3 );
|
45 |
-
|
46 |
-
/**
|
47 |
-
* The downsizer. This only does something if the existing image size doesn't exist yet.
|
48 |
-
*
|
49 |
-
* @param $out boolean false
|
50 |
-
* @param $id int Attachment ID
|
51 |
-
* @param $size mixed The size name, or an array containing the width & height
|
52 |
-
* @return mixed False if the custom downsize failed, or an array of the image if successful
|
53 |
-
*/
|
54 |
-
function gambit_otf_regen_thumbs_media_downsize( $out, $id, $size ) {
|
55 |
-
|
56 |
-
// Gather all the different image sizes of WP (thumbnail, medium, large) and,
|
57 |
-
// all the theme/plugin-introduced sizes.
|
58 |
-
global $_gambit_otf_regen_thumbs_all_image_sizes;
|
59 |
-
if ( ! isset( $_gambit_otf_regen_thumbs_all_image_sizes ) ) {
|
60 |
-
global $_wp_additional_image_sizes;
|
61 |
-
|
62 |
-
$_gambit_otf_regen_thumbs_all_image_sizes = array();
|
63 |
-
$interimSizes = get_intermediate_image_sizes();
|
64 |
-
|
65 |
-
foreach ( $interimSizes as $sizeName ) {
|
66 |
-
if ( in_array( $sizeName, array( 'thumbnail', 'medium', 'large' ) ) ) {
|
67 |
-
|
68 |
-
$_gambit_otf_regen_thumbs_all_image_sizes[ $sizeName ]['width'] = get_option( $sizeName . '_size_w' );
|
69 |
-
$_gambit_otf_regen_thumbs_all_image_sizes[ $sizeName ]['height'] = get_option( $sizeName . '_size_h' );
|
70 |
-
$_gambit_otf_regen_thumbs_all_image_sizes[ $sizeName ]['crop'] = (bool) get_option( $sizeName . '_crop' );
|
71 |
-
|
72 |
-
} elseif ( isset( $_wp_additional_image_sizes[ $sizeName ] ) ) {
|
73 |
-
|
74 |
-
$_gambit_otf_regen_thumbs_all_image_sizes[ $sizeName ] = $_wp_additional_image_sizes[ $sizeName ];
|
75 |
-
}
|
76 |
-
}
|
77 |
-
}
|
78 |
-
|
79 |
-
// This now contains all the data that we have for all the image sizes
|
80 |
-
$allSizes = $_gambit_otf_regen_thumbs_all_image_sizes;
|
81 |
-
|
82 |
-
// If image size exists let WP serve it like normally
|
83 |
-
$imagedata = wp_get_attachment_metadata( $id );
|
84 |
-
|
85 |
-
// Image attachment doesn't exist
|
86 |
-
if ( ! is_array( $imagedata ) ) {
|
87 |
-
return false;
|
88 |
-
}
|
89 |
-
|
90 |
-
// If the size given is a string / a name of a size
|
91 |
-
if ( is_string( $size ) ) {
|
92 |
-
|
93 |
-
// If WP doesn't know about the image size name, then we can't really do any resizing of our own
|
94 |
-
if ( empty( $allSizes[ $size ] ) ) {
|
95 |
-
return false;
|
96 |
-
}
|
97 |
-
|
98 |
-
// If the size has already been previously created, use it
|
99 |
-
if ( ! empty( $imagedata['sizes'][ $size ] ) && ! empty( $allSizes[ $size ] ) ) {
|
100 |
-
|
101 |
-
// But only if the size remained the same
|
102 |
-
if ( $allSizes[ $size ]['width'] == $imagedata['sizes'][ $size ]['width']
|
103 |
-
&& $allSizes[ $size ]['height'] == $imagedata['sizes'][ $size ]['height'] ) {
|
104 |
-
return false;
|
105 |
-
}
|
106 |
-
|
107 |
-
// Or if the size is different and we found out before that the size really was different
|
108 |
-
if ( ! empty( $imagedata['sizes'][ $size ][ 'width_query' ] )
|
109 |
-
&& ! empty( $imagedata['sizes'][ $size ]['height_query'] ) ) {
|
110 |
-
if ( $imagedata['sizes'][ $size ]['width_query'] == $allSizes[ $size ]['width']
|
111 |
-
&& $imagedata['sizes'][ $size ]['height_query'] == $allSizes[ $size ]['height'] ) {
|
112 |
-
return false;
|
113 |
-
}
|
114 |
-
}
|
115 |
-
|
116 |
-
}
|
117 |
-
|
118 |
-
// Resize the image
|
119 |
-
$resized = image_make_intermediate_size(
|
120 |
-
get_attached_file( $id ),
|
121 |
-
$allSizes[ $size ]['width'],
|
122 |
-
$allSizes[ $size ]['height'],
|
123 |
-
$allSizes[ $size ]['crop']
|
124 |
-
);
|
125 |
-
|
126 |
-
// Resize somehow failed
|
127 |
-
if ( ! $resized ) {
|
128 |
-
return false;
|
129 |
-
}
|
130 |
-
|
131 |
-
// Save the new size in WP
|
132 |
-
$imagedata['sizes'][ $size ] = $resized;
|
133 |
-
|
134 |
-
// Save some additional info so that we'll know next time whether we've resized this before
|
135 |
-
$imagedata['sizes'][ $size ]['width_query'] = $allSizes[ $size ]['width'];
|
136 |
-
$imagedata['sizes'][ $size ]['height_query'] = $allSizes[ $size ]['height'];
|
137 |
-
|
138 |
-
wp_update_attachment_metadata( $id, $imagedata );
|
139 |
-
|
140 |
-
// Serve the resized image
|
141 |
-
$att_url = wp_get_attachment_url( $id );
|
142 |
-
return array( dirname( $att_url ) . '/' . $resized['file'], $resized['width'], $resized['height'], true );
|
143 |
-
|
144 |
-
|
145 |
-
// If the size given is a custom array size
|
146 |
-
} else if ( is_array( $size ) ) {
|
147 |
-
$imagePath = get_attached_file( $id );
|
148 |
-
|
149 |
-
// This would be the path of our resized image if the dimensions existed
|
150 |
-
$imageExt = pathinfo( $imagePath, PATHINFO_EXTENSION );
|
151 |
-
$imagePath = preg_replace( '/^(.*)\.' . $imageExt . '$/', sprintf( '$1-%sx%s.%s', $size[0], $size[1], $imageExt ) , $imagePath );
|
152 |
-
|
153 |
-
$att_url = wp_get_attachment_url( $id );
|
154 |
-
|
155 |
-
// If it already exists, serve it
|
156 |
-
if ( file_exists( $imagePath ) ) {
|
157 |
-
return array( dirname( $att_url ) . '/' . basename( $imagePath ), $size[0], $size[1], true );
|
158 |
-
}
|
159 |
-
|
160 |
-
// If not, resize the image...
|
161 |
-
$resized = image_make_intermediate_size(
|
162 |
-
get_attached_file( $id ),
|
163 |
-
$size[0],
|
164 |
-
$size[1],
|
165 |
-
true
|
166 |
-
);
|
167 |
-
|
168 |
-
// Get attachment meta so we can add new size
|
169 |
-
$imagedata = wp_get_attachment_metadata( $id );
|
170 |
-
|
171 |
-
// Save the new size in WP so that it can also perform actions on it
|
172 |
-
$imagedata['sizes'][ $size[0] . 'x' . $size[1] ] = $resized;
|
173 |
-
wp_update_attachment_metadata( $id, $imagedata );
|
174 |
-
|
175 |
-
// Resize somehow failed
|
176 |
-
if ( ! $resized ) {
|
177 |
-
return false;
|
178 |
-
}
|
179 |
-
|
180 |
-
// Then serve it
|
181 |
-
return array( dirname( $att_url ) . '/' . $resized['file'], $resized['width'], $resized['height'], true );
|
182 |
-
}
|
183 |
-
|
184 |
-
return false;
|
185 |
-
}
|
186 |
-
}
|
187 |
}
|
188 |
|
189 |
include('abExport.php');
|
3 |
Plugin Name: reGenerate Thumbnails - advanced
|
4 |
Plugin URI: http://turcuciprian.com
|
5 |
Description: A plugin that makes regenerating thumbnails even easier than before and more flexible.
|
6 |
+
Version: 1.1.1
|
7 |
Author: turcuciprian
|
8 |
Author URI: http://turcuciprian.com
|
9 |
License: GPLv2 or later
|
10 |
Text Domain: RTA
|
11 |
*/
|
12 |
+
add_action('admin_enqueue_scripts', 'enqueue_admin');
|
13 |
|
14 |
+
function enqueue_admin($hook)
|
15 |
+
{
|
16 |
+
if (isset($_GET['page']) && isset($hook)) {
|
17 |
+
if ($_GET['page'] !== 'regenerate_thumbnails_advanced' && $hook != 'options-general.php ') {
|
18 |
+
return;
|
19 |
+
}
|
20 |
+
}
|
21 |
+
wp_enqueue_style('rta', plugin_dir_url(__FILE__).'style.css');
|
22 |
+
}
|
23 |
+
|
24 |
+
/* var @cc cc */
|
25 |
|
26 |
+
add_action('init', 'rtaInit');
|
27 |
+
function rtaInit()
|
28 |
+
{
|
29 |
+
global $abGen;
|
30 |
+
if (!function_exists($abGen,'getField')) {
|
31 |
+
return true;
|
32 |
}
|
33 |
+
$rotf = $abGen->getField('abOption_cPage_regenerateThumbnailsAdvanced', 'tab1', 'rtaOTF');
|
34 |
+
if (!function_exists('gambit_otf_regen_thumbs_media_downsize') && $rotf == 'on') {
|
35 |
+
add_filter('image_downsize', 'gambit_otf_regen_thumbs_media_downsize', 10, 3);
|
36 |
+
|
37 |
+
/**
|
38 |
+
* The downsizer. This only does something if the existing image size doesn't exist yet.
|
39 |
+
*
|
40 |
+
* @param $out boolean false
|
41 |
+
* @param $id int Attachment ID
|
42 |
+
* @param $size mixed The size name, or an array containing the width & height
|
43 |
+
*
|
44 |
+
* @return mixed False if the custom downsize failed, or an array of the image if successful
|
45 |
+
*/
|
46 |
+
function gambit_otf_regen_thumbs_media_downsize($out, $id, $size)
|
47 |
+
{
|
48 |
+
|
49 |
+
// Gather all the different image sizes of WP (thumbnail, medium, large) and,
|
50 |
+
// all the theme/plugin-introduced sizes.
|
51 |
+
global $_gambit_otf_regen_thumbs_all_image_sizes;
|
52 |
+
if (!isset($_gambit_otf_regen_thumbs_all_image_sizes)) {
|
53 |
+
global $_wp_additional_image_sizes;
|
54 |
+
|
55 |
+
$_gambit_otf_regen_thumbs_all_image_sizes = array();
|
56 |
+
$interimSizes = get_intermediate_image_sizes();
|
57 |
+
|
58 |
+
foreach ($interimSizes as $sizeName) {
|
59 |
+
if (in_array($sizeName, array('thumbnail', 'medium', 'large'))) {
|
60 |
+
$_gambit_otf_regen_thumbs_all_image_sizes[ $sizeName ]['width'] = get_option($sizeName.'_size_w');
|
61 |
+
$_gambit_otf_regen_thumbs_all_image_sizes[ $sizeName ]['height'] = get_option($sizeName.'_size_h');
|
62 |
+
$_gambit_otf_regen_thumbs_all_image_sizes[ $sizeName ]['crop'] = (bool) get_option($sizeName.'_crop');
|
63 |
+
} elseif (isset($_wp_additional_image_sizes[ $sizeName ])) {
|
64 |
+
$_gambit_otf_regen_thumbs_all_image_sizes[ $sizeName ] = $_wp_additional_image_sizes[ $sizeName ];
|
65 |
+
}
|
66 |
+
}
|
67 |
+
}
|
68 |
+
|
69 |
+
// This now contains all the data that we have for all the image sizes
|
70 |
+
$allSizes = $_gambit_otf_regen_thumbs_all_image_sizes;
|
71 |
|
72 |
+
// If image size exists let WP serve it like normally
|
73 |
+
$imagedata = wp_get_attachment_metadata($id);
|
74 |
+
|
75 |
+
// Image attachment doesn't exist
|
76 |
+
if (!is_array($imagedata)) {
|
77 |
+
return false;
|
78 |
+
}
|
79 |
+
|
80 |
+
// If the size given is a string / a name of a size
|
81 |
+
if (is_string($size)) {
|
82 |
+
|
83 |
+
// If WP doesn't know about the image size name, then we can't really do any resizing of our own
|
84 |
+
if (empty($allSizes[ $size ])) {
|
85 |
+
return false;
|
86 |
}
|
87 |
+
|
88 |
+
// If the size has already been previously created, use it
|
89 |
+
if (!empty($imagedata['sizes'][ $size ]) && !empty($allSizes[ $size ])) {
|
90 |
+
|
91 |
+
// But only if the size remained the same
|
92 |
+
if ($allSizes[ $size ]['width'] == $imagedata['sizes'][ $size ]['width']
|
93 |
+
&& $allSizes[ $size ]['height'] == $imagedata['sizes'][ $size ]['height']) {
|
94 |
+
return false;
|
95 |
+
}
|
96 |
+
|
97 |
+
// Or if the size is different and we found out before that the size really was different
|
98 |
+
if (!empty($imagedata['sizes'][ $size ][ 'width_query' ])
|
99 |
+
&& !empty($imagedata['sizes'][ $size ]['height_query'])) {
|
100 |
+
if ($imagedata['sizes'][ $size ]['width_query'] == $allSizes[ $size ]['width']
|
101 |
+
&& $imagedata['sizes'][ $size ]['height_query'] == $allSizes[ $size ]['height']) {
|
102 |
+
return false;
|
103 |
+
}
|
104 |
+
}
|
105 |
+
}
|
106 |
+
|
107 |
+
// Resize the image
|
108 |
+
$resized = image_make_intermediate_size(
|
109 |
+
get_attached_file($id),
|
110 |
+
$allSizes[ $size ]['width'],
|
111 |
+
$allSizes[ $size ]['height'],
|
112 |
+
$allSizes[ $size ]['crop']
|
113 |
+
);
|
114 |
+
|
115 |
+
// Resize somehow failed
|
116 |
+
if (!$resized) {
|
117 |
+
return false;
|
118 |
+
}
|
119 |
+
|
120 |
+
// Save the new size in WP
|
121 |
+
$imagedata['sizes'][ $size ] = $resized;
|
122 |
+
|
123 |
+
// Save some additional info so that we'll know next time whether we've resized this before
|
124 |
+
$imagedata['sizes'][ $size ]['width_query'] = $allSizes[ $size ]['width'];
|
125 |
+
$imagedata['sizes'][ $size ]['height_query'] = $allSizes[ $size ]['height'];
|
126 |
+
|
127 |
+
wp_update_attachment_metadata($id, $imagedata);
|
128 |
+
|
129 |
+
// Serve the resized image
|
130 |
+
$att_url = wp_get_attachment_url($id);
|
131 |
+
|
132 |
+
return array(dirname($att_url).'/'.$resized['file'], $resized['width'], $resized['height'], true);
|
133 |
+
|
134 |
+
// If the size given is a custom array size
|
135 |
+
} elseif (is_array($size)) {
|
136 |
+
$imagePath = get_attached_file($id);
|
137 |
+
|
138 |
+
// This would be the path of our resized image if the dimensions existed
|
139 |
+
$imageExt = pathinfo($imagePath, PATHINFO_EXTENSION);
|
140 |
+
$imagePath = preg_replace('/^(.*)\.'.$imageExt.'$/', sprintf('$1-%sx%s.%s', $size[0], $size[1], $imageExt), $imagePath);
|
141 |
+
|
142 |
+
$att_url = wp_get_attachment_url($id);
|
143 |
+
|
144 |
+
// If it already exists, serve it
|
145 |
+
if (file_exists($imagePath)) {
|
146 |
+
return array(dirname($att_url).'/'.basename($imagePath), $size[0], $size[1], true);
|
147 |
+
}
|
148 |
+
|
149 |
+
// If not, resize the image...
|
150 |
+
$resized = image_make_intermediate_size(
|
151 |
+
get_attached_file($id),
|
152 |
+
$size[0],
|
153 |
+
$size[1],
|
154 |
+
true
|
155 |
+
);
|
156 |
+
|
157 |
+
// Get attachment meta so we can add new size
|
158 |
+
$imagedata = wp_get_attachment_metadata($id);
|
159 |
+
|
160 |
+
// Save the new size in WP so that it can also perform actions on it
|
161 |
+
$imagedata['sizes'][ $size[0].'x'.$size[1] ] = $resized;
|
162 |
+
wp_update_attachment_metadata($id, $imagedata);
|
163 |
+
|
164 |
+
// Resize somehow failed
|
165 |
+
if (!$resized) {
|
166 |
+
return false;
|
167 |
+
}
|
168 |
+
|
169 |
+
// Then serve it
|
170 |
+
return array(dirname($att_url).'/'.$resized['file'], $resized['width'], $resized['height'], true);
|
171 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
172 |
|
173 |
+
return false;
|
174 |
+
}
|
175 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
176 |
}
|
177 |
|
178 |
include('abExport.php');
|