Version Description
Download this release
Release Info
Developer | Rahe |
Plugin | Simple Image Sizes |
Version | 3.0.4 |
Comparing to | |
See all releases |
Code changes from version 3.0.3 to 3.0.4
- README +197 -192
- classes/admin/main.php +330 -307
- classes/admin/media.php +525 -479
- classes/admin/post.php +265 -251
- classes/main.php +60 -51
- readme.txt +179 -177
- simple_image_sizes.php +62 -60
README
CHANGED
@@ -1,192 +1,197 @@
|
|
1 |
-
# Simple Image Sizes #
|
2 |
-
**Contributors:** Rahe
|
3 |
-
|
4 |
-
**Donate link:** http://www.beapi.fr/donate/
|
5 |
-
|
6 |
-
**Tags:** images, image, custom sizes, custom images, thumbnail regenerate, thumbnail, regenerate, cropping
|
7 |
-
|
8 |
-
**Requires at least:** 3.5
|
9 |
-
|
10 |
-
**Tested up to:**
|
11 |
-
|
12 |
-
**Stable tag:** 3.0.
|
13 |
-
|
14 |
-
|
15 |
-
## Description ##
|
16 |
-
|
17 |
-
This plugin allow create custom image sizes for your site. Override your theme sizes directly on the media option page.
|
18 |
-
You can regenerate all the sizes you have just created and choose which one you wanted to regenerate.
|
19 |
-
You can now get all the code to copy and paste to your function theme file.
|
20 |
-
Now you can use the generated sizes directly into your posts and insert images at the right size !
|
21 |
-
Now you choose if you want display the size in the post insert image.
|
22 |
-
Now you can regenerate the images one by one in the 'Medias' general pane.
|
23 |
-
Now you can regenerate the images by bulk action in the 'Medias' general pane.
|
24 |
-
Now you can regenerate the image sizes on single attachment edit page.
|
25 |
-
|
26 |
-
I have added a timer so when you regeneration your thumbnails, you can know approximately when the regeneration will be ended.
|
27 |
-
I have improved the php and javascript, you can know if the image have been regenerated or not or if there is an error and which one.
|
28 |
-
|
29 |
-
Contribute on https://github.com/Rahe/Simple-image-sizes
|
30 |
-
|
31 |
-
## Installation ##
|
32 |
-
**PHP5 Required.**
|
33 |
-
|
34 |
-
1. Download, unzip and upload to your WordPress plugins directory
|
35 |
-
2. Activate the plugin within you WordPress Administration Backend
|
36 |
-
3. Go to Settings > Medias
|
37 |
-
4. Configure your new image sizes and regenerate the thumbnails !
|
38 |
-
|
39 |
-
|
40 |
-
## Frequently Asked Questions ##
|
41 |
-
|
42 |
-
### Where can I add image sizes ? ####
|
43 |
-
Go to Settings -> Media then you can add a image size. You have to add a unique custom name without any spaces or special chars.
|
44 |
-
The best is to use something like my-custom-size.
|
45 |
-
Then you have several fields for configuring the image size, the widht, the height, cropping.
|
46 |
-
And then you can choose if the image is displayed on the media insertion or not ( this will be displayed on the dropdown list ).
|
47 |
-
|
48 |
-
|
49 |
-
## Screenshots ##
|
50 |
-
|
51 |
-
###1. Settings page
|
52 |
-
###
|
53 |
-
![Settings page
|
54 |
-
](http://s.wordpress.org/extend/plugins/simple-image-sizes/screenshot-1.png)
|
55 |
-
|
56 |
-
###2. Get PHP for the theme
|
57 |
-
###
|
58 |
-
![Get PHP for the theme
|
59 |
-
](http://s.wordpress.org/extend/plugins/simple-image-sizes/screenshot-2.png)
|
60 |
-
|
61 |
-
###3. Choose the sizes to regenerate and regenerate them
|
62 |
-
###
|
63 |
-
![Choose the sizes to regenerate
|
64 |
-
](http://s.wordpress.org/extend/plugins/simple-image-sizes/screenshot-3.png)
|
65 |
-
|
66 |
-
## Changelog ##
|
67 |
-
* 3.0.
|
68 |
-
* Fix
|
69 |
-
* 3.0.
|
70 |
-
*
|
71 |
-
|
72 |
-
*
|
73 |
-
*
|
74 |
-
* 3.0
|
75 |
-
*
|
76 |
-
*
|
77 |
-
*
|
78 |
-
*
|
79 |
-
|
80 |
-
*
|
81 |
-
*
|
82 |
-
*
|
83 |
-
*
|
84 |
-
*
|
85 |
-
* 2.4.
|
86 |
-
* Remove
|
87 |
-
*
|
88 |
-
|
89 |
-
*
|
90 |
-
|
91 |
-
* Remove
|
92 |
-
|
93 |
-
*
|
94 |
-
*
|
95 |
-
|
96 |
-
*
|
97 |
-
*
|
98 |
-
*
|
99 |
-
|
100 |
-
*
|
101 |
-
*
|
102 |
-
|
103 |
-
*
|
104 |
-
*
|
105 |
-
|
106 |
-
*
|
107 |
-
*
|
108 |
-
*
|
109 |
-
|
110 |
-
*
|
111 |
-
*
|
112 |
-
*
|
113 |
-
*
|
114 |
-
*
|
115 |
-
* Remove
|
116 |
-
* 2.2.
|
117 |
-
*
|
118 |
-
|
119 |
-
*
|
120 |
-
*
|
121 |
-
* 2.2
|
122 |
-
*
|
123 |
-
* Add
|
124 |
-
*
|
125 |
-
*
|
126 |
-
|
127 |
-
* Add
|
128 |
-
*
|
129 |
-
*
|
130 |
-
*
|
131 |
-
*
|
132 |
-
*
|
133 |
-
*
|
134 |
-
*
|
135 |
-
|
136 |
-
*
|
137 |
-
*
|
138 |
-
*
|
139 |
-
*
|
140 |
-
*
|
141 |
-
*
|
142 |
-
* Remove
|
143 |
-
*
|
144 |
-
* 2.0.
|
145 |
-
* Resolve
|
146 |
-
|
147 |
-
*
|
148 |
-
*
|
149 |
-
|
150 |
-
*
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
*
|
155 |
-
*
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
*
|
160 |
-
*
|
161 |
-
*
|
162 |
-
*
|
163 |
-
*
|
164 |
-
*
|
165 |
-
*
|
166 |
-
*
|
167 |
-
*
|
168 |
-
*
|
169 |
-
|
170 |
-
*
|
171 |
-
*
|
172 |
-
*
|
173 |
-
* 1.0.
|
174 |
-
*
|
175 |
-
*
|
176 |
-
*
|
177 |
-
*
|
178 |
-
|
179 |
-
*
|
180 |
-
|
181 |
-
*
|
182 |
-
* Add
|
183 |
-
*
|
184 |
-
*
|
185 |
-
*
|
186 |
-
*
|
187 |
-
* Add
|
188 |
-
*
|
189 |
-
* 1.0
|
190 |
-
*
|
191 |
-
|
192 |
-
*
|
|
|
|
|
|
|
|
|
|
1 |
+
# Simple Image Sizes #
|
2 |
+
**Contributors:** Rahe
|
3 |
+
|
4 |
+
**Donate link:** http://www.beapi.fr/donate/
|
5 |
+
|
6 |
+
**Tags:** images, image, custom sizes, custom images, thumbnail regenerate, thumbnail, regenerate, cropping
|
7 |
+
|
8 |
+
**Requires at least:** 3.5
|
9 |
+
|
10 |
+
**Tested up to:** 4.2.1
|
11 |
+
|
12 |
+
**Stable tag:** 3.0.4
|
13 |
+
|
14 |
+
|
15 |
+
## Description ##
|
16 |
+
|
17 |
+
This plugin allow create custom image sizes for your site. Override your theme sizes directly on the media option page.
|
18 |
+
You can regenerate all the sizes you have just created and choose which one you wanted to regenerate.
|
19 |
+
You can now get all the code to copy and paste to your function theme file.
|
20 |
+
Now you can use the generated sizes directly into your posts and insert images at the right size !
|
21 |
+
Now you choose if you want display the size in the post insert image.
|
22 |
+
Now you can regenerate the images one by one in the 'Medias' general pane.
|
23 |
+
Now you can regenerate the images by bulk action in the 'Medias' general pane.
|
24 |
+
Now you can regenerate the image sizes on single attachment edit page.
|
25 |
+
|
26 |
+
I have added a timer so when you regeneration your thumbnails, you can know approximately when the regeneration will be ended.
|
27 |
+
I have improved the php and javascript, you can know if the image have been regenerated or not or if there is an error and which one.
|
28 |
+
|
29 |
+
Contribute on https://github.com/Rahe/Simple-image-sizes
|
30 |
+
|
31 |
+
## Installation ##
|
32 |
+
**PHP5 Required.**
|
33 |
+
|
34 |
+
1. Download, unzip and upload to your WordPress plugins directory
|
35 |
+
2. Activate the plugin within you WordPress Administration Backend
|
36 |
+
3. Go to Settings > Medias
|
37 |
+
4. Configure your new image sizes and regenerate the thumbnails !
|
38 |
+
|
39 |
+
|
40 |
+
## Frequently Asked Questions ##
|
41 |
+
|
42 |
+
### Where can I add image sizes ? ####
|
43 |
+
Go to Settings -> Media then you can add a image size. You have to add a unique custom name without any spaces or special chars.
|
44 |
+
The best is to use something like my-custom-size.
|
45 |
+
Then you have several fields for configuring the image size, the widht, the height, cropping.
|
46 |
+
And then you can choose if the image is displayed on the media insertion or not ( this will be displayed on the dropdown list ).
|
47 |
+
|
48 |
+
|
49 |
+
## Screenshots ##
|
50 |
+
|
51 |
+
###1. Settings page
|
52 |
+
###
|
53 |
+
![Settings page
|
54 |
+
](http://s.wordpress.org/extend/plugins/simple-image-sizes/screenshot-1.png)
|
55 |
+
|
56 |
+
###2. Get PHP for the theme
|
57 |
+
###
|
58 |
+
![Get PHP for the theme
|
59 |
+
](http://s.wordpress.org/extend/plugins/simple-image-sizes/screenshot-2.png)
|
60 |
+
|
61 |
+
###3. Choose the sizes to regenerate and regenerate them
|
62 |
+
###
|
63 |
+
![Choose the sizes to regenerate
|
64 |
+
](http://s.wordpress.org/extend/plugins/simple-image-sizes/screenshot-3.png)
|
65 |
+
|
66 |
+
## Changelog ##
|
67 |
+
* 3.0.4
|
68 |
+
* Fix global add_image_size
|
69 |
+
* 3.0.3
|
70 |
+
* Add Hebrew translations thanks to Atar4U
|
71 |
+
* 3.0.2
|
72 |
+
* Fix version check for the image crop positions
|
73 |
+
* Add Hebrew translations thanks to Atar4U
|
74 |
+
* 3.0.1
|
75 |
+
* Change the template render method for non apache webservers : https://wordpress.org/support/topic/fatal-error-1190?replies=6
|
76 |
+
* Remove ambigious ids for the css bugging WooCommerce : https://wordpress.org/support/topic/bad-css-style-administration and
|
77 |
+
* Right code for counting the elements on backoffice : https://github.com/Rahe/Simple-image-sizes/issues/20
|
78 |
+
* Fix bug on regenation and _e instead of __ : https://plugins.trac.wordpress.org/ticket/2259
|
79 |
+
* 3.0
|
80 |
+
* Revamping all the code, change classes and structure
|
81 |
+
* Use grunt for compiling files
|
82 |
+
* Handle the 3.9 new cropping position
|
83 |
+
* Remove aristo css
|
84 |
+
* Use UI from WordPress
|
85 |
+
* 2.4.3
|
86 |
+
* Remove some php notices
|
87 |
+
* Remove notice when wrong image size
|
88 |
+
* 2.4.2
|
89 |
+
* Selective regeneration fix by g100g on http://wordpress.org/support/topic/regenerating-fix
|
90 |
+
* 2.4.1
|
91 |
+
* Remove function not working on admin file
|
92 |
+
* 2.4
|
93 |
+
* Made for 3.5 and up
|
94 |
+
* Refactoring PHP/Javascript code
|
95 |
+
* Javascript improvements
|
96 |
+
* Remove useless UI
|
97 |
+
* UI improvements
|
98 |
+
* Global PHP performance improvements
|
99 |
+
* 2.3.1
|
100 |
+
* Add Ajax bulk actions on medias list
|
101 |
+
* Add ajax thumbnail rebuild on single media
|
102 |
+
* 2.3
|
103 |
+
* Add the custom size name in the attachment insertion
|
104 |
+
* Exclude post_type wich do not support the post-thumbnail feature
|
105 |
+
* 2.2.5
|
106 |
+
* Debug the regeneration buggy !
|
107 |
+
* Complete the french translation
|
108 |
+
* Security update for single regeneration, include the nonce this time :)
|
109 |
+
* 2.2.4
|
110 |
+
* Add security nonces for every actions
|
111 |
+
* Put the messages at the begining of the log
|
112 |
+
* Add a select all checkbox Thank to cocola
|
113 |
+
* Add the german translation thanks to glueckpress
|
114 |
+
* Remove notice tnahks to christianwach
|
115 |
+
* Remove useless and buggy for my scripting pointers
|
116 |
+
* 2.2.3
|
117 |
+
* Do not force network usage
|
118 |
+
* 2.2.2
|
119 |
+
* Debug js for the buttons
|
120 |
+
* Remove console.log calls
|
121 |
+
* 2.2.1
|
122 |
+
* Use buttonset for the checkboxes
|
123 |
+
* Add Pointer for WordPress 3.3
|
124 |
+
* Fix translation in French
|
125 |
+
* Some medias queries for small windows ( change size of buttons and alignment )
|
126 |
+
* 2.2
|
127 |
+
* Add new version of css aristo
|
128 |
+
* Add some icons
|
129 |
+
* Display button for saving changes only when changes detected
|
130 |
+
* Display message when a size is modified but not saved and wanted to regenerate
|
131 |
+
* Debug functionnality when regenerating only some sizes, metas not crushed
|
132 |
+
* Add solo regenerating
|
133 |
+
* Remove displaying for theme/not theme sizes
|
134 |
+
* Use WordPress class for small inputs
|
135 |
+
* 2.1
|
136 |
+
* Add javascript timer
|
137 |
+
* Improve javascript and more IE friendly
|
138 |
+
* You can now choose if you want to display the image sizes in image insertion or not
|
139 |
+
* Handle errors and messages
|
140 |
+
* Remove some css useless rules
|
141 |
+
* Fix bad translation for french
|
142 |
+
* Remove accents in image sizes
|
143 |
+
* Do not update size properties if there is an ajax query for an another size name
|
144 |
+
* 2.0.3
|
145 |
+
* Resolve issue with theme sizes witch by default are displayed as not cropped. Thanks to momo360modena for the bug signalment.
|
146 |
+
* 2.0.2
|
147 |
+
* Remove debug on php for javascript
|
148 |
+
* Resolve issue with the different versions on jquery ( like in WP3.2 ) with attr return for checked components
|
149 |
+
* 2.0.1
|
150 |
+
* Resolve javascript issue when clicking on delete button
|
151 |
+
* Resolve issue of never unchecking crop button
|
152 |
+
* 2.0
|
153 |
+
* Code refactoring
|
154 |
+
* Update translations
|
155 |
+
* Ajaxification of the process
|
156 |
+
* Deleting by Ajax
|
157 |
+
* Updating by Ajax
|
158 |
+
* Adding by Ajax
|
159 |
+
* Change UI
|
160 |
+
* Change theme
|
161 |
+
* Handle ajax errors
|
162 |
+
* Handle not modified sizes, cropped
|
163 |
+
* Handle same names
|
164 |
+
* Sanitize the names
|
165 |
+
* Customize jQuery ui
|
166 |
+
* Customize jQuery ui theme
|
167 |
+
* HTML5 Elements
|
168 |
+
* CSS3 Animations
|
169 |
+
* 1.0.6
|
170 |
+
* Minify javascript names
|
171 |
+
* Change progressbar style
|
172 |
+
* Add animations on progressbar
|
173 |
+
* 1.0.5
|
174 |
+
* Only add css and js script in the media page to avoid any javascript error in other pages
|
175 |
+
* Rectify css
|
176 |
+
* Add function to get the code for the function.php file of the theme
|
177 |
+
* Don't redefine the Wordpress basic size names
|
178 |
+
* 1.0.4
|
179 |
+
* Fix the add_image_size issue ( height and width reversed )
|
180 |
+
* 1.0.3
|
181 |
+
* Fix the plugin language
|
182 |
+
* Add some translations
|
183 |
+
* Externalise some css
|
184 |
+
* Add sizes in the image adding to an article
|
185 |
+
* Add setting link in the plugins list
|
186 |
+
* Use admin_url instead of home_url
|
187 |
+
* Add legend for colors
|
188 |
+
* Some code refactoring
|
189 |
+
* 1.0.2
|
190 |
+
* Fix the plugin license
|
191 |
+
* 1.0.1
|
192 |
+
* Add POT file
|
193 |
+
* Add french translation
|
194 |
+
* 1.0
|
195 |
+
* First release
|
196 |
+
* Thumbnail regenerate
|
197 |
+
* Image size generation
|
classes/admin/main.php
CHANGED
@@ -1,308 +1,331 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
wp_register_script( '
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
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 |
-
'
|
53 |
-
'
|
54 |
-
'
|
55 |
-
'
|
56 |
-
'
|
57 |
-
'
|
58 |
-
'
|
59 |
-
'
|
60 |
-
'
|
61 |
-
'
|
62 |
-
'
|
63 |
-
'
|
64 |
-
'
|
65 |
-
'
|
66 |
-
'
|
67 |
-
'
|
68 |
-
'
|
69 |
-
'
|
70 |
-
'
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
$
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
*
|
193 |
-
*
|
194 |
-
*
|
195 |
-
* @
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
*
|
210 |
-
*
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
*
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
//
|
276 |
-
|
277 |
-
$
|
278 |
-
}
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
308 |
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
Class SIS_Admin_Main {
|
4 |
+
|
5 |
+
public function __construct() {
|
6 |
+
add_action( 'admin_init', array( __CLASS__, 'register_assets' ) );
|
7 |
+
}
|
8 |
+
|
9 |
+
/**
|
10 |
+
*
|
11 |
+
*/
|
12 |
+
public static function register_assets() {
|
13 |
+
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG === true ? '' : '.min';
|
14 |
+
// Add javascript
|
15 |
+
wp_register_script( 'underscore', '//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.6.0/underscore-min.js', array(), '1.6.0' );
|
16 |
+
wp_register_script( 'sis_js', SIS_URL . '/assets/js/sis' . $suffix . '.js', array(
|
17 |
+
'jquery',
|
18 |
+
'jquery-ui-button',
|
19 |
+
'jquery-ui-progressbar',
|
20 |
+
'underscore'
|
21 |
+
), SIS_VERSION );
|
22 |
+
|
23 |
+
// Differencitate the scripts
|
24 |
+
wp_register_script( 'sis_js_attachments', SIS_URL . '/assets/js/sis-attachments' . $suffix . '.js', array( 'jquery' ), SIS_VERSION );
|
25 |
+
|
26 |
+
// Add javascript translation
|
27 |
+
wp_localize_script( 'sis_js', 'sis', self::localize_vars() );
|
28 |
+
wp_localize_script( 'sis_js_attachments', 'sis', self::localize_vars() );
|
29 |
+
|
30 |
+
// Add CSS
|
31 |
+
wp_enqueue_style( 'sis_css', SIS_URL . '/assets/css/sis-style' . $suffix . '.css', array(), SIS_VERSION );
|
32 |
+
}
|
33 |
+
|
34 |
+
|
35 |
+
/**
|
36 |
+
* Localize the var for javascript
|
37 |
+
*
|
38 |
+
* @access public
|
39 |
+
* @return array
|
40 |
+
* @author Nicolas Juen
|
41 |
+
*/
|
42 |
+
public static function localize_vars() {
|
43 |
+
return array(
|
44 |
+
'ajaxUrl' => admin_url( '/admin-ajax.php' ),
|
45 |
+
'reading' => __( 'Reading attachments...', 'simple-image-sizes' ),
|
46 |
+
'maximumWidth' => __( 'Maximum width', 'simple-image-sizes' ),
|
47 |
+
'maximumHeight' => __( 'Maximum height', 'simple-image-sizes' ),
|
48 |
+
'crop' => __( 'Crop', 'simple-image-sizes' ),
|
49 |
+
'tr' => __( 'yes', 'simple-image-sizes' ),
|
50 |
+
'fl' => __( 'no', 'simple-image-sizes' ),
|
51 |
+
'show' => __( 'Show in post insertion ?', 'simple-image-sizes' ),
|
52 |
+
'of' => __( ' of ', 'simple-image-sizes' ),
|
53 |
+
'or' => __( ' or ', 'simple-image-sizes' ),
|
54 |
+
'beforeEnd' => __( ' before the end.', 'simple-image-sizes' ),
|
55 |
+
'deleteImage' => __( 'Delete', 'simple-image-sizes' ),
|
56 |
+
'noMedia' => __( 'No media in your site to regenerate !', 'simple-image-sizes' ),
|
57 |
+
'regenerating' => __( 'Regenerating ', 'simple-image-sizes' ),
|
58 |
+
'regenerate' => __( 'Regenerate ', 'simple-image-sizes' ),
|
59 |
+
'validate' => __( 'Validate image size name', 'simple-image-sizes' ),
|
60 |
+
'done' => __( 'Done.', 'simple-image-sizes' ),
|
61 |
+
'size' => __( 'Size', 'simple-image-sizes' ),
|
62 |
+
'notOriginal' => __( 'Don\'t use the basic Wordpress thumbnail size name, use the form above to edit them', 'simple-image-sizes' ),
|
63 |
+
'alreadyPresent' => __( 'This size is already registered, edit it instead of recreating it.', 'simple-image-sizes' ),
|
64 |
+
'confirmDelete' => __( 'Do you really want to delete these size ?', 'simple-image-sizes' ),
|
65 |
+
'update' => __( 'Update', 'simple-image-sizes' ),
|
66 |
+
'ajaxErrorHandler' => __( 'Error requesting page', 'simple-image-sizes' ),
|
67 |
+
'messageRegenerated' => __( 'images have been regenerated !', 'simple-image-sizes' ),
|
68 |
+
'validateButton' => __( 'Validate', 'simple-image-sizes' ),
|
69 |
+
'startedAt' => __( ' started at', 'simple-image-sizes' ),
|
70 |
+
'customName' => __( 'Public name', 'simple-image-sizes' ),
|
71 |
+
'finishedAt' => __( ' finished at :', 'simple-image-sizes' ),
|
72 |
+
'phpError' => __( 'Error during the php treatment, be sure to not have php errors in your page', 'simple-image-sizes' ),
|
73 |
+
'notSaved' => __( 'All the sizes you have modifed are not saved, continue anyway ?', 'simple-image-sizes' ),
|
74 |
+
'soloRegenerated' => __( 'This image has been regenerated in %s seconds', 'simple-image-sizes' ),
|
75 |
+
'crop_positions' => self::get_available_crop(),
|
76 |
+
'regen_one' => wp_create_nonce( 'regen' )
|
77 |
+
);
|
78 |
+
}
|
79 |
+
|
80 |
+
/**
|
81 |
+
* Rebuild the given attribute with the given thumbnails
|
82 |
+
*
|
83 |
+
* @param $att_id
|
84 |
+
* @param $thumbnails
|
85 |
+
*
|
86 |
+
* @return array
|
87 |
+
* @author Nicolas Juen
|
88 |
+
*/
|
89 |
+
public static function thumbnail_rebuild( $att_id, $thumbnails = null ) {
|
90 |
+
// Time a the begining
|
91 |
+
timer_start();
|
92 |
+
|
93 |
+
// Check Id
|
94 |
+
if ( (int) $att_id <= 0 ) {
|
95 |
+
return array(
|
96 |
+
'time' => timer_stop( false, 4 ),
|
97 |
+
'error' => __( 'No id given in POST datas.', 'simple-image-sizes' )
|
98 |
+
);
|
99 |
+
}
|
100 |
+
|
101 |
+
// Get the path
|
102 |
+
$fullsizepath = get_attached_file( $att_id );
|
103 |
+
|
104 |
+
// Regen the attachment
|
105 |
+
if ( false !== $fullsizepath && file_exists( $fullsizepath ) ) {
|
106 |
+
if ( false == wp_update_attachment_metadata( $att_id, self::wp_generate_attachment_metadata_custom( $att_id, $fullsizepath, $thumbnails ) ) ) {
|
107 |
+
return array(
|
108 |
+
'src' => wp_get_attachment_thumb_url( $att_id ),
|
109 |
+
'time' => timer_stop( false, 4 ),
|
110 |
+
'message' => sprintf( __( 'This file already exists in this size and have not been regenerated :<br/><a target="_blank" href="%1$s" >%2$s</a>', 'simple-image-sizes' ), get_edit_post_link( $att_id ), get_the_title( $att_id ) )
|
111 |
+
);
|
112 |
+
}
|
113 |
+
} else {
|
114 |
+
return array(
|
115 |
+
'src' => wp_get_attachment_thumb_url( $att_id ),
|
116 |
+
'time' => timer_stop( false, 4 ),
|
117 |
+
'error' => sprintf( __( 'This file does not exists and have not been regenerated :<br/><a target="_blank" href="%1$s" >%2$s</a>', 'simple-image-sizes' ), get_edit_post_link( $att_id ), get_the_title( $att_id ) )
|
118 |
+
);
|
119 |
+
|
120 |
+
}
|
121 |
+
|
122 |
+
// Display the attachment url for feedback
|
123 |
+
return array(
|
124 |
+
'time' => timer_stop( false, 4 ),
|
125 |
+
'src' => wp_get_attachment_thumb_url( $att_id ),
|
126 |
+
'title' => get_the_title( $att_id )
|
127 |
+
);
|
128 |
+
}
|
129 |
+
|
130 |
+
/**
|
131 |
+
* Include the javascript template
|
132 |
+
*
|
133 |
+
* @param void
|
134 |
+
*
|
135 |
+
* @return bool
|
136 |
+
*/
|
137 |
+
public static function add_template() {
|
138 |
+
global $pagenow;
|
139 |
+
if ( 'options-media.php' !== $pagenow ) {
|
140 |
+
return false;
|
141 |
+
}
|
142 |
+
|
143 |
+
if ( is_file( SIS_DIR . '/templates/admin-js.html' ) ) {
|
144 |
+
include( SIS_DIR . '/templates/admin-js.html' );
|
145 |
+
}
|
146 |
+
|
147 |
+
return true;
|
148 |
+
}
|
149 |
+
|
150 |
+
/**
|
151 |
+
* Get all the available cropping
|
152 |
+
*
|
153 |
+
* @return array
|
154 |
+
*
|
155 |
+
* @param void
|
156 |
+
*
|
157 |
+
* @author Nicolas Juen
|
158 |
+
*/
|
159 |
+
public static function get_available_crop() {
|
160 |
+
global $wp_version;
|
161 |
+
|
162 |
+
// Return the only possible
|
163 |
+
if ( version_compare( $wp_version, '3.9', '<' ) ) {
|
164 |
+
return array();
|
165 |
+
}
|
166 |
+
|
167 |
+
$x = array(
|
168 |
+
'left' => __( 'Left', 'simple-image-sizes' ),
|
169 |
+
'center' => __( 'Center', 'simple-image-sizes' ),
|
170 |
+
'right' => __( 'Right', 'simple-image-sizes' ),
|
171 |
+
);
|
172 |
+
|
173 |
+
$y = array(
|
174 |
+
'top' => __( 'top', 'simple-image-sizes' ),
|
175 |
+
'center' => __( 'center', 'simple-image-sizes' ),
|
176 |
+
'bottom' => __( 'bottom', 'simple-image-sizes' ),
|
177 |
+
);
|
178 |
+
|
179 |
+
$crops = array();
|
180 |
+
foreach ( $x as $x_pos => $x_pos_label ) {
|
181 |
+
foreach ( $y as $y_pos => $y_pos_label ) {
|
182 |
+
$crops[ $x_pos . '_' . $y_pos ] = $x_pos_label . ' ' . $y_pos_label;
|
183 |
+
}
|
184 |
+
}
|
185 |
+
|
186 |
+
return $crops;
|
187 |
+
}
|
188 |
+
|
189 |
+
/**
|
190 |
+
* Check if the crop is available
|
191 |
+
*
|
192 |
+
* @param string $crop_position
|
193 |
+
*
|
194 |
+
* @return bool
|
195 |
+
* @author Nicolas Juen
|
196 |
+
*/
|
197 |
+
public static function is_crop_position( $crop_position ) {
|
198 |
+
$crops = self::get_available_crop();
|
199 |
+
|
200 |
+
return isset( $crops[ $crop_position ] );
|
201 |
+
}
|
202 |
+
|
203 |
+
/**
|
204 |
+
* Return the crop position label from the slug
|
205 |
+
*
|
206 |
+
*
|
207 |
+
* @param string $crop_position
|
208 |
+
*
|
209 |
+
* @return string
|
210 |
+
* @author Nicolas Juen
|
211 |
+
*/
|
212 |
+
public static function get_crop_position_label( $crop_position ) {
|
213 |
+
if ( ! self::is_crop_position( $crop_position ) ) {
|
214 |
+
return '';
|
215 |
+
}
|
216 |
+
$crops = self::get_available_crop();
|
217 |
+
|
218 |
+
return $crops[ $crop_position ];
|
219 |
+
}
|
220 |
+
|
221 |
+
|
222 |
+
/**
|
223 |
+
* Display a json encoded element with right headers
|
224 |
+
*
|
225 |
+
* @param $data (optional) : the element to display ( if needed )
|
226 |
+
*
|
227 |
+
* @return void
|
228 |
+
* @author Nicolas Juen
|
229 |
+
*/
|
230 |
+
public static function displayJson( $data = array() ) {
|
231 |
+
if ( function_exists( 'wp_send_json' ) ) {
|
232 |
+
wp_send_json( $data );
|
233 |
+
}
|
234 |
+
|
235 |
+
header( 'Cache-Control: no-cache, must-revalidate' );
|
236 |
+
header( 'Expires: Mon, 26 Jul 1997 05:00:00 GMT' );
|
237 |
+
header( 'Content-type: application/json' );
|
238 |
+
echo json_encode( $data );
|
239 |
+
die();
|
240 |
+
}
|
241 |
+
|
242 |
+
/**
|
243 |
+
* Generate post thumbnail attachment meta data.
|
244 |
+
*
|
245 |
+
* @since 2.1.0
|
246 |
+
*
|
247 |
+
* @param int $attachment_id Attachment Id to process.
|
248 |
+
* @param string $file Filepath of the Attached image.
|
249 |
+
*
|
250 |
+
* @return mixed Metadata for attachment.
|
251 |
+
*/
|
252 |
+
public static function wp_generate_attachment_metadata_custom( $attachment_id, $file, $thumbnails = null ) {
|
253 |
+
$attachment = get_post( $attachment_id );
|
254 |
+
|
255 |
+
$meta_datas = get_post_meta( $attachment_id, '_wp_attachment_metadata', true );
|
256 |
+
|
257 |
+
$metadata = array();
|
258 |
+
if ( preg_match( '!^image/!', get_post_mime_type( $attachment ) ) && file_is_displayable_image( $file ) ) {
|
259 |
+
$imagesize = getimagesize( $file );
|
260 |
+
$metadata['width'] = $imagesize[0];
|
261 |
+
$metadata['height'] = $imagesize[1];
|
262 |
+
list( $uwidth, $uheight ) = wp_constrain_dimensions( $metadata['width'], $metadata['height'], 128, 96 );
|
263 |
+
$metadata['hwstring_small'] = "height='$uheight' width='$uwidth'";
|
264 |
+
|
265 |
+
// Make the file path relative to the upload dir
|
266 |
+
$metadata['file'] = _wp_relative_upload_path( $file );
|
267 |
+
|
268 |
+
// make thumbnails and other intermediate sizes
|
269 |
+
global $_wp_additional_image_sizes;
|
270 |
+
|
271 |
+
foreach ( get_intermediate_image_sizes() as $s ) {
|
272 |
+
$sizes[ $s ] = array( 'width' => '', 'height' => '', 'crop' => false );
|
273 |
+
if ( isset( $_wp_additional_image_sizes[ $s ]['width'] ) ) {
|
274 |
+
$sizes[ $s ]['width'] = intval( $_wp_additional_image_sizes[ $s ]['width'] );
|
275 |
+
} // For theme-added sizes
|
276 |
+
else {
|
277 |
+
$sizes[ $s ]['width'] = get_option( "{$s}_size_w" );
|
278 |
+
} // For default sizes set in options
|
279 |
+
if ( isset( $_wp_additional_image_sizes[ $s ]['height'] ) ) {
|
280 |
+
$sizes[ $s ]['height'] = intval( $_wp_additional_image_sizes[ $s ]['height'] );
|
281 |
+
} // For theme-added sizes
|
282 |
+
else {
|
283 |
+
$sizes[ $s ]['height'] = get_option( "{$s}_size_h" );
|
284 |
+
} // For default sizes set in options
|
285 |
+
if ( isset( $_wp_additional_image_sizes[ $s ]['crop'] ) ) {
|
286 |
+
$sizes[ $s ]['crop'] = intval( $_wp_additional_image_sizes[ $s ]['crop'] );
|
287 |
+
} // For theme-added sizes
|
288 |
+
else {
|
289 |
+
$sizes[ $s ]['crop'] = get_option( "{$s}_crop" );
|
290 |
+
} // For default sizes set in options
|
291 |
+
}
|
292 |
+
|
293 |
+
$sizes = apply_filters( 'intermediate_image_sizes_advanced', $sizes );
|
294 |
+
|
295 |
+
// Only if not all sizes
|
296 |
+
if ( isset( $thumbnails ) && is_array( $thumbnails ) && isset( $meta_datas['sizes'] ) && ! empty( $meta_datas['sizes'] ) ) {
|
297 |
+
// Fill the array with the other sizes not have to be done
|
298 |
+
foreach ( $meta_datas['sizes'] as $name => $fsize ) {
|
299 |
+
$metadata['sizes'][ $name ] = $fsize;
|
300 |
+
}
|
301 |
+
}
|
302 |
+
|
303 |
+
foreach ( $sizes as $size => $size_data ) {
|
304 |
+
if ( isset( $thumbnails ) ) {
|
305 |
+
if ( ! in_array( $size, $thumbnails ) ) {
|
306 |
+
continue;
|
307 |
+
}
|
308 |
+
}
|
309 |
+
|
310 |
+
$resized = image_make_intermediate_size( $file, $size_data['width'], $size_data['height'], $size_data['crop'] );
|
311 |
+
|
312 |
+
if ( isset( $meta_datas['size'][ $size ] ) ) {
|
313 |
+
// Remove the size from the orignal sizes for after work
|
314 |
+
unset( $meta_datas['size'][ $size ] );
|
315 |
+
}
|
316 |
+
|
317 |
+
if ( $resized ) {
|
318 |
+
$metadata['sizes'][ $size ] = $resized;
|
319 |
+
}
|
320 |
+
}
|
321 |
+
|
322 |
+
// fetch additional metadata from exif/iptc
|
323 |
+
$image_meta = wp_read_image_metadata( $file );
|
324 |
+
if ( $image_meta ) {
|
325 |
+
$metadata['image_meta'] = $image_meta;
|
326 |
+
}
|
327 |
+
}
|
328 |
+
|
329 |
+
return apply_filters( 'wp_generate_attachment_metadata', $metadata, $attachment_id );
|
330 |
+
}
|
331 |
}
|
classes/admin/media.php
CHANGED
@@ -1,479 +1,525 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
add_action( '
|
12 |
-
|
13 |
-
|
14 |
-
//
|
15 |
-
|
16 |
-
add_action( 'wp_ajax_'.'
|
17 |
-
add_action( 'wp_ajax_'.'
|
18 |
-
add_action( 'wp_ajax_'.'
|
19 |
-
add_action( 'wp_ajax_'.'
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
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 a link to the setting option page
|
53 |
-
*
|
54 |
-
* @access public
|
55 |
-
|
56 |
-
* @param
|
57 |
-
* @
|
58 |
-
*
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
*
|
76 |
-
*
|
77 |
-
* @
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
</
|
178 |
-
<
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
*
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
if(
|
258 |
-
|
259 |
-
}
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
$
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
*
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
$
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
if(
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
Class SIS_Admin_Media {
|
4 |
+
|
5 |
+
// Original sizes
|
6 |
+
public static $original = array( 'thumbnail', 'medium', 'large' );
|
7 |
+
|
8 |
+
public function __construct() {
|
9 |
+
// Init
|
10 |
+
|
11 |
+
add_action( 'admin_menu', array( __CLASS__, 'init' ) );
|
12 |
+
add_action( 'admin_enqueue_scripts', array( __CLASS__, 'enqueue_assets' ), 11 );
|
13 |
+
|
14 |
+
// Add ajax action
|
15 |
+
// Option page
|
16 |
+
add_action( 'wp_ajax_' . 'sis_get_list', array( __CLASS__, 'a_get_list' ) );
|
17 |
+
add_action( 'wp_ajax_' . 'sis_rebuild_images', array( __CLASS__, 'a_thumbnails_rebuild' ) );
|
18 |
+
add_action( 'wp_ajax_' . 'sis_get_sizes', array( __CLASS__, 'a_get_sizes' ) );
|
19 |
+
add_action( 'wp_ajax_' . 'sis_add_size', array( __CLASS__, 'a_add_size' ) );
|
20 |
+
add_action( 'wp_ajax_' . 'sis_remove_size', array( __CLASS__, 'a_remove_size' ) );
|
21 |
+
|
22 |
+
// Add link in plugins list
|
23 |
+
add_filter( 'plugin_action_links', array( __CLASS__, 'add_settings_link' ), 10, 2 );
|
24 |
+
}
|
25 |
+
|
26 |
+
/**
|
27 |
+
* Register javascripts and css.
|
28 |
+
*
|
29 |
+
* @access public
|
30 |
+
* @return void
|
31 |
+
* @author Nicolas Juen
|
32 |
+
*/
|
33 |
+
public static function enqueue_assets( $hook_suffix = '' ) {
|
34 |
+
if ( ! isset( $hook_suffix ) || empty( $hook_suffix ) ) {
|
35 |
+
return false;
|
36 |
+
}
|
37 |
+
|
38 |
+
if ( 'options-media.php'!== $hook_suffix ) {
|
39 |
+
// Add javascript
|
40 |
+
wp_enqueue_script( 'sis_js' );
|
41 |
+
|
42 |
+
// Add CSS
|
43 |
+
wp_enqueue_style( 'sis_css' );
|
44 |
+
|
45 |
+
// Add underscore template
|
46 |
+
add_action( 'admin_footer', array( 'SIS_Admin_Main', 'add_template' ) );
|
47 |
+
}
|
48 |
+
}
|
49 |
+
|
50 |
+
|
51 |
+
/**
|
52 |
+
* Add a link to the setting option page
|
53 |
+
*
|
54 |
+
* @access public
|
55 |
+
*
|
56 |
+
* @param array $links
|
57 |
+
* @param string $file
|
58 |
+
*
|
59 |
+
* @return void
|
60 |
+
* @author Nicolas Juen
|
61 |
+
*/
|
62 |
+
public static function add_settings_link( $links, $file ) {
|
63 |
+
|
64 |
+
if ( 'simple-image-sizes/simple_image_sizes.php' !== $file ) {
|
65 |
+
return $links;
|
66 |
+
}
|
67 |
+
|
68 |
+
$settings_link = '<a href="' . admin_url( 'options-media.php' ) . '"> ' . __( 'Settings', 'simple-image-sizes' ) . ' </a>';
|
69 |
+
array_unshift( $links, $settings_link );
|
70 |
+
|
71 |
+
return $links;
|
72 |
+
}
|
73 |
+
|
74 |
+
/**
|
75 |
+
* Init for the option page
|
76 |
+
*
|
77 |
+
* @access public
|
78 |
+
* @return void
|
79 |
+
* @author Nicolas Juen
|
80 |
+
*/
|
81 |
+
public static function init() {
|
82 |
+
// Check if admin
|
83 |
+
if ( ! is_admin() ) {
|
84 |
+
return false;
|
85 |
+
}
|
86 |
+
|
87 |
+
// Get the image sizes
|
88 |
+
global $_wp_additional_image_sizes;
|
89 |
+
$options = get_option( SIS_OPTION );
|
90 |
+
|
91 |
+
// Get the sizes and add the settings
|
92 |
+
foreach ( get_intermediate_image_sizes() as $s ) {
|
93 |
+
// Don't make the original sizes or numeric sizes that appear
|
94 |
+
if ( in_array( $s, self::$original ) || is_integer( $s ) ) {
|
95 |
+
continue;
|
96 |
+
}
|
97 |
+
|
98 |
+
// Set width
|
99 |
+
$width = isset( $_wp_additional_image_sizes[ $s ]['width'] ) ? intval( $_wp_additional_image_sizes[ $s ]['width'] ) : get_option( "{$s}_size_w" );
|
100 |
+
|
101 |
+
// Set height
|
102 |
+
$height = isset( $_wp_additional_image_sizes[ $s ]['height'] ) ? intval( $_wp_additional_image_sizes[ $s ]['height'] ) : get_option( "{$s}_size_h" );
|
103 |
+
|
104 |
+
//Set crop
|
105 |
+
$crop = isset( $_wp_additional_image_sizes[ $s ]['crop'] ) ? intval( $_wp_additional_image_sizes[ $s ]['crop'] ) : get_option( "{$s}_crop" );
|
106 |
+
|
107 |
+
// Add the setting field for this size
|
108 |
+
add_settings_field( 'image_size_' . $s, sprintf( __( '%s size', 'simple-image-sizes' ), $s ), array(
|
109 |
+
__CLASS__,
|
110 |
+
'image_sizes'
|
111 |
+
), 'media', 'default', array( 'name' => $s, 'width' => $width, 'height' => $height, 'c' => $crop ) );
|
112 |
+
}
|
113 |
+
|
114 |
+
// Register the setting for media option page
|
115 |
+
register_setting( 'media', SIS_OPTION );
|
116 |
+
|
117 |
+
// Add the button
|
118 |
+
add_settings_field( 'add_size_button', __( 'Add a new size', 'simple-image-sizes' ), array(
|
119 |
+
__CLASS__,
|
120 |
+
'addSizeButton'
|
121 |
+
), 'media' );
|
122 |
+
|
123 |
+
// Add php button
|
124 |
+
add_settings_field( 'get_php_button', __( 'Get php for theme', 'simple-image-sizes' ), array(
|
125 |
+
__CLASS__,
|
126 |
+
'getPhpButton'
|
127 |
+
), 'media' );
|
128 |
+
|
129 |
+
// Add section for the thumbnail regeneration
|
130 |
+
add_settings_section( 'thumbnail_regenerate', __( 'Thumbnail regeneration', 'simple-image-sizes' ), array(
|
131 |
+
__CLASS__,
|
132 |
+
'thumbnailRegenerate'
|
133 |
+
), 'media' );
|
134 |
+
}
|
135 |
+
|
136 |
+
/**
|
137 |
+
* Display the row of the image size
|
138 |
+
*
|
139 |
+
* @access public
|
140 |
+
*
|
141 |
+
* @param mixed $args
|
142 |
+
*
|
143 |
+
* @return void
|
144 |
+
* @author Nicolas Juen
|
145 |
+
*/
|
146 |
+
public static function image_sizes( $args ) {
|
147 |
+
|
148 |
+
if ( is_integer( $args['name'] ) ) {
|
149 |
+
return;
|
150 |
+
}
|
151 |
+
|
152 |
+
// Get the options
|
153 |
+
$sizes = (array) get_option( SIS_OPTION, array() );
|
154 |
+
|
155 |
+
// Get the vars
|
156 |
+
$height = isset( $sizes[ $args['name'] ]['h'] ) ? $sizes[ $args['name'] ]['h'] : $args['height'];
|
157 |
+
$width = isset( $sizes[ $args['name'] ]['w'] ) ? $sizes[ $args['name'] ]['w'] : $args['width'];
|
158 |
+
$crop = isset( $sizes[ $args['name'] ]['c'] ) && ! empty( $sizes[ $args['name'] ]['c'] ) ? $sizes[ $args['name'] ]['c'] : $args['c'];
|
159 |
+
$show = isset( $sizes[ $args['name'] ]['s'] ) && ! empty( $sizes[ $args['name'] ]['s'] ) ? '1' : '0';
|
160 |
+
$custom = isset( $sizes[ $args['name'] ]['custom'] ) && ! empty( $sizes[ $args['name'] ]['custom'] ) ? '1' : '0';
|
161 |
+
$name = isset( $sizes[ $args['name'] ]['n'] ) && ! empty( $sizes[ $args['name'] ]['n'] ) ? esc_html( $sizes[ $args['name'] ]['n'] ) : esc_html( $args['name'] );
|
162 |
+
?>
|
163 |
+
<input type="hidden" value="<?php echo esc_attr( $args['name'] ); ?>" name="image_name"/>
|
164 |
+
<?php if ( $custom ): ?>
|
165 |
+
<input name="<?php echo esc_attr( 'custom_image_sizes[' . $args['name'] . '][custom]' ); ?>" type="hidden"
|
166 |
+
id="<?php echo esc_attr( 'custom_image_sizes[' . $args['name'] . '][custom]' ); ?>" value="1"/>
|
167 |
+
<?php else: ?>
|
168 |
+
<input name="<?php echo esc_attr( 'custom_image_sizes[' . $args['name'] . '][theme]' ); ?>" type="hidden"
|
169 |
+
id="<?php echo esc_attr( 'custom_image_sizes[' . $args['name'] . '][theme]' ); ?>" value="1"/>
|
170 |
+
<?php endif; ?>
|
171 |
+
<label class="sis-label" for="<?php echo esc_attr( 'custom_image_sizes[' . $args['name'] . '][w]' ); ?>">
|
172 |
+
<?php _e( 'Maximum width', 'simple-image-sizes' ); ?>
|
173 |
+
<input name="<?php esc_attr_e( 'custom_image_sizes[' . $args['name'] . '][w]' ); ?>" class='w small-text'
|
174 |
+
type="number" step='1' min='0'
|
175 |
+
id="<?php echo esc_attr( 'custom_image_sizes[' . $args['name'] . '][w]' ); ?>"
|
176 |
+
base_w='<?php echo esc_attr( $width ); ?>' value="<?php echo esc_attr( $width ); ?>"/>
|
177 |
+
</label>
|
178 |
+
<label class="sis-label" for="<?php esc_attr_e( 'custom_image_sizes[' . $args['name'] . '][h]' ); ?>">
|
179 |
+
<?php _e( 'Maximum height', 'simple-image-sizes' ); ?>
|
180 |
+
<input name="<?php esc_attr_e( 'custom_image_sizes[' . $args['name'] . '][h]' ); ?>" class='h small-text'
|
181 |
+
type="number" step='1' min='0'
|
182 |
+
id="<?php echo esc_attr( 'custom_image_sizes[' . $args['name'] . '][h]' ); ?>"
|
183 |
+
base_h='<?php echo esc_attr( $height ); ?>' value="<?php echo esc_attr( $height ); ?>"/>
|
184 |
+
</label>
|
185 |
+
<label class="sis-label" for="<?php echo esc_attr( 'custom_image_sizes[' . $args['name'] . '][n]' ); ?>">
|
186 |
+
<?php _e( 'Public name', 'simple-image-sizes' ); ?>
|
187 |
+
<input name="<?php echo esc_attr( 'custom_image_sizes[' . $args['name'] . '][n]' ); ?>" class='n'
|
188 |
+
type="text" id="<?php echo esc_attr( 'custom_image_sizes[' . $args['name'] . '][n]' ); ?>"
|
189 |
+
base_n='<?php echo $name; ?>' value="<?php echo $name ?>"/>
|
190 |
+
</label>
|
191 |
+
<span class="size_options">
|
192 |
+
<label class="c"
|
193 |
+
for="<?php echo esc_attr( 'custom_image_sizes[' . $args['name'] . '][c]' ); ?>"><?php _e( 'Cropping', 'simple-image-sizes' ); ?></label>
|
194 |
+
<select id="<?php echo esc_attr( 'custom_image_sizes[' . $args['name'] . '][c]' ); ?>" class="c crop"
|
195 |
+
base_c='<?php echo esc_attr( $crop ); ?>'
|
196 |
+
name="<?php echo esc_attr( 'custom_image_sizes[' . $args['name'] . '][c]' ); ?>">
|
197 |
+
<option
|
198 |
+
value="0" <?php selected( 0, $crop ); ?>><?php esc_html_e( 'No', 'simple-image-sizes' ); ?></option>
|
199 |
+
<option
|
200 |
+
value="1" <?php selected( 1, $crop ); ?>><?php esc_html_e( 'Yes', 'simple-image-sizes' ); ?></option>
|
201 |
+
<?php foreach ( SIS_Admin_Main::get_available_crop() as $crop_position => $label ): ?>
|
202 |
+
<option <?php selected( $crop_position, $crop ); ?>
|
203 |
+
value="<?php echo esc_attr( $crop_position ) ?>"><?php echo esc_html( $label ); ?></option>
|
204 |
+
<?php endforeach; ?>
|
205 |
+
</select>
|
206 |
+
|
207 |
+
<input type='checkbox'
|
208 |
+
id="<?php echo esc_attr( 'custom_image_sizes[' . $args['name'] . '][s]' ); ?>" <?php checked( $show, 1 ) ?>
|
209 |
+
class="s show" base_s='<?php echo esc_attr( $show ); ?>'
|
210 |
+
name="<?php echo esc_attr( 'custom_image_sizes[' . $args['name'] . '][s]' ); ?>" value="1"/>
|
211 |
+
<label class="s"
|
212 |
+
for="<?php echo esc_attr( 'custom_image_sizes[' . $args['name'] . '][s]' ); ?>"><?php _e( 'Show in post insertion ?', 'simple-image-sizes' ); ?></label>
|
213 |
+
</span>
|
214 |
+
<span class="delete_size button-secondary"><?php _e( 'Delete', 'simple-image-sizes' ); ?></span>
|
215 |
+
<span class="add_size validate_size button-primary"><?php _e( 'Update', 'simple-image-sizes' ); ?></span>
|
216 |
+
|
217 |
+
<input type="hidden" class="deleteSize button-primary"
|
218 |
+
value='<?php echo wp_create_nonce( 'delete_' . $args['name'] ); ?>'/>
|
219 |
+
<?php }
|
220 |
+
|
221 |
+
/**
|
222 |
+
* Add the button to add a size
|
223 |
+
*
|
224 |
+
* @access public
|
225 |
+
* @return void
|
226 |
+
* @author Nicolas Juen
|
227 |
+
*/
|
228 |
+
public static function addSizeButton() { ?>
|
229 |
+
<input type="button" class="button-secondary action" id="add_size"
|
230 |
+
value="<?php esc_attr_e( 'Add a new size of thumbnail', 'simple-image-sizes' ); ?>"/>
|
231 |
+
<?php
|
232 |
+
}
|
233 |
+
|
234 |
+
/**
|
235 |
+
* Add the button to get the php for th sizes
|
236 |
+
*
|
237 |
+
* @access public
|
238 |
+
* @return void
|
239 |
+
* @author Nicolas Juen
|
240 |
+
*/
|
241 |
+
public static function getPhpButton() { ?>
|
242 |
+
<input type="button" class="button-secondary action" id="get_php"
|
243 |
+
value="<?php esc_attr_e( 'Get the PHP for the theme', 'simple-image-sizes' ); ?>"/>
|
244 |
+
<p> <?php _e( 'Copy and paste the code below into your Wordpress theme function file if you wanted to save them and deactivate the plugin.', 'simple-image-sizes' ); ?> </p>
|
245 |
+
<code></code>
|
246 |
+
<?php
|
247 |
+
}
|
248 |
+
|
249 |
+
/**
|
250 |
+
* Display the Table of sizes and post types for regenerating
|
251 |
+
*
|
252 |
+
* @access public
|
253 |
+
* @return void
|
254 |
+
* @author Nicolas Juen
|
255 |
+
*/
|
256 |
+
public static function thumbnailRegenerate() {
|
257 |
+
if ( is_file( SIS_DIR . '/templates/options-media.php' ) ) {
|
258 |
+
include( SIS_DIR . '/templates/options-media.php' );
|
259 |
+
} else {
|
260 |
+
esc_html_e( 'Admin option-media template missing', 'simple-image-sizes' );
|
261 |
+
}
|
262 |
+
}
|
263 |
+
|
264 |
+
/**
|
265 |
+
* Add a size by Ajax
|
266 |
+
*
|
267 |
+
* @access public
|
268 |
+
* @return void
|
269 |
+
* @author Nicolas Juen
|
270 |
+
*/
|
271 |
+
public static function a_add_size() {
|
272 |
+
|
273 |
+
// Get the nonce
|
274 |
+
$nonce = isset( $_POST['nonce'] ) ? $_POST['nonce'] : '';
|
275 |
+
|
276 |
+
// Get old options
|
277 |
+
$sizes = (array) get_option( SIS_OPTION, array() );
|
278 |
+
$croppings = SIS_Admin_Main::get_available_crop();
|
279 |
+
$croppings[ true ] = '';
|
280 |
+
$croppings[ false ] = '';
|
281 |
+
|
282 |
+
// Check entries
|
283 |
+
$name = isset( $_POST['name'] ) ? sanitize_title( $_POST['name'] ) : '';
|
284 |
+
$height = ! isset( $_POST['height'] ) ? 0 : absint( $_POST['height'] );
|
285 |
+
$width = ! isset( $_POST['width'] ) ? 0 : absint( $_POST['width'] );
|
286 |
+
$crop = isset( $_POST['crop'] ) && isset( $croppings[ $_POST['crop'] ] ) ? $_POST['crop'] : false;
|
287 |
+
$show = isset( $_POST['show'] ) && $_POST['show'] == 'false' ? false : true;
|
288 |
+
$cn = isset( $_POST['customName'] ) && ! empty( $_POST['customName'] ) ? sanitize_text_field( $_POST['customName'] ) : $name;
|
289 |
+
|
290 |
+
// Check the nonce
|
291 |
+
if ( ! wp_verify_nonce( $nonce, 'add_size' ) ) {
|
292 |
+
die( 0 );
|
293 |
+
}
|
294 |
+
|
295 |
+
// If no name given do not save
|
296 |
+
if ( empty( $name ) ) {
|
297 |
+
die( 0 );
|
298 |
+
}
|
299 |
+
|
300 |
+
// Make values
|
301 |
+
$values = array( 'custom' => 1, 'w' => $width, 'h' => $height, 'c' => $crop, 's' => $show, 'n' => $cn );
|
302 |
+
|
303 |
+
// If the size have not changed return 2
|
304 |
+
if ( isset( $sizes[ $name ] ) && $sizes[ $name ] === $values ) {
|
305 |
+
die( 2 );
|
306 |
+
}
|
307 |
+
|
308 |
+
// Put the new values
|
309 |
+
$sizes[ $name ] = $values;
|
310 |
+
|
311 |
+
// display update result
|
312 |
+
echo (int) update_option( 'custom_image_sizes', $sizes );
|
313 |
+
die();
|
314 |
+
}
|
315 |
+
|
316 |
+
/**
|
317 |
+
* Remove a size by Ajax
|
318 |
+
*
|
319 |
+
* @access public
|
320 |
+
* @return void
|
321 |
+
* @author Nicolas Juen
|
322 |
+
*/
|
323 |
+
public static function a_remove_size() {
|
324 |
+
|
325 |
+
// Get old options
|
326 |
+
$sizes = (array) get_option( SIS_OPTION, array() );
|
327 |
+
|
328 |
+
// Get the nonce and name
|
329 |
+
$nonce = isset( $_POST['nonce'] ) ? $_POST['nonce'] : '';
|
330 |
+
$name = isset( $_POST['name'] ) ? sanitize_title( $_POST['name'] ) : '';
|
331 |
+
|
332 |
+
// Check the nonce
|
333 |
+
if ( ! wp_verify_nonce( $nonce, 'delete_' . $name ) ) {
|
334 |
+
die( 0 );
|
335 |
+
}
|
336 |
+
|
337 |
+
// Remove the size
|
338 |
+
unset( $sizes[ sanitize_title( $name ) ] );
|
339 |
+
unset( $sizes[0] );
|
340 |
+
|
341 |
+
// Display the results
|
342 |
+
echo (int) update_option( SIS_OPTION, $sizes );
|
343 |
+
die();
|
344 |
+
}
|
345 |
+
|
346 |
+
/**
|
347 |
+
* Display the add_image_size for the registered sizes
|
348 |
+
*
|
349 |
+
* @access public
|
350 |
+
* @return void
|
351 |
+
*/
|
352 |
+
public static function a_get_sizes() {
|
353 |
+
global $_wp_additional_image_sizes, $wp_version;
|
354 |
+
|
355 |
+
foreach ( get_intermediate_image_sizes() as $s ) {
|
356 |
+
// Don't make the original sizes
|
357 |
+
if ( in_array( $s, self::$original ) ) {
|
358 |
+
continue;
|
359 |
+
}
|
360 |
+
|
361 |
+
// Set width
|
362 |
+
$width = isset( $_wp_additional_image_sizes[ $s ]['width'] ) ? intval( $_wp_additional_image_sizes[ $s ]['width'] ) : get_option( "{$s}_size_w" );
|
363 |
+
|
364 |
+
// Set height
|
365 |
+
$height = isset( $_wp_additional_image_sizes[ $s ]['height'] ) ? intval( $_wp_additional_image_sizes[ $s ]['height'] ) : get_option( "{$s}_size_h" );
|
366 |
+
|
367 |
+
//Set crop
|
368 |
+
$crop = isset( $_wp_additional_image_sizes[ $s ]['crop'] ) ? $_wp_additional_image_sizes[ $s ]['crop'] : get_option( "{$s}_crop" );
|
369 |
+
|
370 |
+
if ( is_bool( $crop ) || is_numeric( $crop ) || version_compare( $wp_version, '3.9', '<' ) ) {
|
371 |
+
$crop = ( absint( $crop ) == 0 ) ? 'false' : 'true';
|
372 |
+
} else {
|
373 |
+
if ( ! Sis_Admin_Main::is_crop_position( implode( '_', $crop ) ) ) {
|
374 |
+
$crop = "false";
|
375 |
+
} else {
|
376 |
+
$crop = 'array( "' . $crop[0] . '", "' . $crop[1] . '")';
|
377 |
+
}
|
378 |
+
}
|
379 |
+
?>
|
380 |
+
add_image_size( '<?php echo $s; ?>', '<?php echo $width; ?>', '<?php echo $height; ?>', <?php echo $crop; ?> );
|
381 |
+
<br/>
|
382 |
+
<?php
|
383 |
+
}
|
384 |
+
|
385 |
+
die();
|
386 |
+
}
|
387 |
+
|
388 |
+
/**
|
389 |
+
*
|
390 |
+
* Get the media list to regenerate
|
391 |
+
*
|
392 |
+
* @param : void
|
393 |
+
*
|
394 |
+
* @return void
|
395 |
+
*/
|
396 |
+
public static function a_get_list() {
|
397 |
+
/**
|
398 |
+
* @var $wpdb wpdb
|
399 |
+
*/
|
400 |
+
global $wpdb;
|
401 |
+
|
402 |
+
// Basic vars
|
403 |
+
$res = array();
|
404 |
+
$nonce = isset( $_POST['nonce'] ) ? $_POST['nonce'] : '';
|
405 |
+
|
406 |
+
// Check the nonce
|
407 |
+
if ( ! wp_verify_nonce( $nonce, 'getList' ) ) {
|
408 |
+
SIS_Admin_Main::displayJson();
|
409 |
+
}
|
410 |
+
|
411 |
+
if ( isset( $_POST['post_types'] ) && ! empty( $_POST['post_types'] ) ) {
|
412 |
+
|
413 |
+
foreach ( $_POST['post_types'] as $key => $type ) {
|
414 |
+
if ( ! post_type_exists( $type ) ) {
|
415 |
+
unset( $_POST['post_types'][ $key ] );
|
416 |
+
}
|
417 |
+
}
|
418 |
+
|
419 |
+
if ( empty( $_POST['post_types'][ $key ] ) ) {
|
420 |
+
SIS_Admin_Main::displayJson();
|
421 |
+
}
|
422 |
+
|
423 |
+
// Get image medias
|
424 |
+
$whichmimetype = wp_post_mime_type_where( 'image', $wpdb->posts );
|
425 |
+
|
426 |
+
// Get all parent from post type
|
427 |
+
$attachments = $wpdb->get_var( "SELECT COUNT( ID )
|
428 |
+
FROM $wpdb->posts
|
429 |
+
WHERE 1 = 1
|
430 |
+
AND post_type = 'attachment'
|
431 |
+
$whichmimetype
|
432 |
+
AND post_parent IN (
|
433 |
+
SELECT DISTINCT ID
|
434 |
+
FROM $wpdb->posts
|
435 |
+
WHERE post_type IN ('" . implode( "', '", $_POST['post_types'] ) . "')
|
436 |
+
)" );
|
437 |
+
// Return the Id's and Title of medias
|
438 |
+
SIS_Admin_Main::displayJson( array( 'total' => $attachments ) );
|
439 |
+
|
440 |
+
} else {
|
441 |
+
$attachments = get_children( array(
|
442 |
+
'post_type' => 'attachment',
|
443 |
+
'post_mime_type' => 'image',
|
444 |
+
'numberposts' => - 1,
|
445 |
+
'post_status' => null,
|
446 |
+
'post_parent' => null, // any parent
|
447 |
+
'output' => 'ids',
|
448 |
+
) );
|
449 |
+
// Return the Id's and Title of medias
|
450 |
+
SIS_Admin_Main::displayJson( array( 'total' => count( $attachments ) ) );
|
451 |
+
}
|
452 |
+
|
453 |
+
}
|
454 |
+
|
455 |
+
/**
|
456 |
+
* Regenerate the thumbnails ajax action
|
457 |
+
*
|
458 |
+
* @return array
|
459 |
+
*
|
460 |
+
* @param void
|
461 |
+
*
|
462 |
+
* @author Nicolas Juen
|
463 |
+
*/
|
464 |
+
public static function a_thumbnails_rebuild() {
|
465 |
+
// Get the nonce
|
466 |
+
$nonce = isset( $_POST['nonce'] ) ? $_POST['nonce'] : '';
|
467 |
+
$offset = isset( $_POST['offset'] ) ? absint( $_POST['offset'] ) : 0;
|
468 |
+
$post_types = isset( $_POST['post_types'] ) ? $_POST['post_types'] : 'any';
|
469 |
+
$thumbnails = isset( $_POST['thumbnails'] ) ? $_POST['thumbnails'] : null;
|
470 |
+
|
471 |
+
// Check the nonce
|
472 |
+
if ( ! wp_verify_nonce( $nonce, 'regen' ) ) {
|
473 |
+
SIS_Admin_Main::displayJson( array( 'error' => __( 'Trying to cheat ?', 'simple-image-sizes' ) ) );
|
474 |
+
}
|
475 |
+
|
476 |
+
if ('any' !== $post_types ) {
|
477 |
+
|
478 |
+
foreach ( $_POST['post_types'] as $key => $type ) {
|
479 |
+
if ( ! post_type_exists( $type ) ) {
|
480 |
+
unset( $_POST['post_types'][ $key ] );
|
481 |
+
}
|
482 |
+
}
|
483 |
+
|
484 |
+
if ( empty( $_POST['post_types'] ) ) {
|
485 |
+
SIS_Admin_Main::displayJson();
|
486 |
+
}
|
487 |
+
|
488 |
+
// Get image medias
|
489 |
+
$whichmimetype = wp_post_mime_type_where( 'image', $wpdb->posts );
|
490 |
+
|
491 |
+
// Get all parent from post type
|
492 |
+
$attachment = $wpdb->get_var( $wpdb->prepare( "SELECT ID
|
493 |
+
FROM $wpdb->posts
|
494 |
+
WHERE 1 = 1
|
495 |
+
AND post_type = 'attachment'
|
496 |
+
$whichmimetype
|
497 |
+
AND post_parent IN (
|
498 |
+
SELECT DISTINCT ID
|
499 |
+
FROM $wpdb->posts
|
500 |
+
WHERE post_type IN ('" . implode( "', '", $_POST['post_types'] ) . "')
|
501 |
+
)
|
502 |
+
LIMIT %d,1
|
503 |
+
", $offset ) );
|
504 |
+
|
505 |
+
} else {
|
506 |
+
$attachment = get_posts( array(
|
507 |
+
'post_type' => 'attachment',
|
508 |
+
'post_mime_type' => 'image',
|
509 |
+
'numberposts' => 1,
|
510 |
+
'post_status' => 'any',
|
511 |
+
'output' => 'object',
|
512 |
+
'offset' => $offset,
|
513 |
+
) );
|
514 |
+
|
515 |
+
$attachment = ! empty( $attachment ) ? $attachment[0]->ID : 0;
|
516 |
+
}
|
517 |
+
|
518 |
+
if ( empty( $attachment ) ) {
|
519 |
+
return array(
|
520 |
+
'message' => __( 'Regeneration ended', 'simple-image-sizes' )
|
521 |
+
);
|
522 |
+
}
|
523 |
+
SIS_Admin_Main::displayJson( SIS_Admin_Main::thumbnail_rebuild( $attachment, $thumbnails ) );
|
524 |
+
}
|
525 |
+
}
|
classes/admin/post.php
CHANGED
@@ -1,252 +1,266 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
if
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
*
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
if
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
*
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
*
|
77 |
-
|
78 |
-
* @
|
79 |
-
*
|
80 |
-
* @
|
81 |
-
* @
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
$
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
$
|
106 |
-
|
107 |
-
//
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
*
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
252 |
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
Class SIS_Admin_Post {
|
4 |
+
public function __construct() {
|
5 |
+
// Add image sizes in the form, check if 3.3 is installed or not
|
6 |
+
if ( ! function_exists( 'is_main_query' ) ) {
|
7 |
+
add_filter( 'attachment_fields_to_edit', array(
|
8 |
+
__CLASS__,
|
9 |
+
'sizes_in_form'
|
10 |
+
), 11, 2 ); // Add our sizes to media forms
|
11 |
+
} else {
|
12 |
+
add_filter( 'image_size_names_choose', array( __CLASS__, 'add_thumbnail_name' ) );
|
13 |
+
}
|
14 |
+
|
15 |
+
add_action( 'admin_enqueue_scripts', array( __CLASS__, 'enqueue_assets' ), 11 );
|
16 |
+
|
17 |
+
// Rebuilt the image
|
18 |
+
add_action( 'wp_ajax_' . 'sis_rebuild_image', array( __CLASS__, 'a_thumbnail_rebuild' ) );
|
19 |
+
|
20 |
+
// Add action in media row quick actions
|
21 |
+
add_filter( 'media_row_actions', array( __CLASS__, 'add_actions_list' ), 10, 2 );
|
22 |
+
|
23 |
+
// Add filter for the Media single
|
24 |
+
add_filter( 'attachment_fields_to_edit', array( __CLASS__, 'add_field_regenerate' ), 9, 2 );
|
25 |
+
}
|
26 |
+
|
27 |
+
/**
|
28 |
+
* Register javascripts and css.
|
29 |
+
*
|
30 |
+
* @access public
|
31 |
+
* @return void
|
32 |
+
* @author Nicolas Juen
|
33 |
+
*/
|
34 |
+
public static function enqueue_assets( $hook_suffix = '' ) {
|
35 |
+
if ( ! isset( $hook_suffix ) || empty( $hook_suffix ) ) {
|
36 |
+
return false;
|
37 |
+
}
|
38 |
+
|
39 |
+
if ( 'upload.php' !== $hook_suffix || ( 'post.php' !== $hook_suffix && isset( $_GET['post'] ) && isset( $_GET['action'] ) && 'edit' == $_GET['action'] ) ) {
|
40 |
+
// Add javascript
|
41 |
+
wp_enqueue_script( 'sis_js_attachments' );
|
42 |
+
|
43 |
+
// Add underscore template
|
44 |
+
add_action( 'admin_footer', array( 'SIS_Admin_Main', 'add_template' ) );
|
45 |
+
}
|
46 |
+
}
|
47 |
+
|
48 |
+
/**
|
49 |
+
* Rebuild the image
|
50 |
+
*
|
51 |
+
* @access public
|
52 |
+
* @return void
|
53 |
+
* @author Nicolas Juen
|
54 |
+
*/
|
55 |
+
public static function a_thumbnail_rebuild() {
|
56 |
+
// Get the nonce
|
57 |
+
$nonce = isset( $_POST['nonce'] ) ? $_POST['nonce'] : '';
|
58 |
+
|
59 |
+
// Time a the begining
|
60 |
+
timer_start();
|
61 |
+
|
62 |
+
// Get the thumbnails
|
63 |
+
$thumbnails = isset( $_POST['thumbnails'] ) ? $_POST['thumbnails'] : null;
|
64 |
+
|
65 |
+
// Check the nonce
|
66 |
+
if ( ! wp_verify_nonce( $nonce, 'regen' ) ) {
|
67 |
+
SIS_Admin_Main::displayJson( array( 'error' => _e( 'Trying to cheat ?', 'simple-image-sizes' ) ) );
|
68 |
+
}
|
69 |
+
|
70 |
+
// Get the id
|
71 |
+
$id = isset( $_POST['id'] ) ? $_POST['id'] : 0;
|
72 |
+
SIS_Admin_Main::displayJson( SIS_Admin_Main::thumbnail_rebuild( $id, $thumbnails ) );
|
73 |
+
}
|
74 |
+
|
75 |
+
/**
|
76 |
+
* Add the custom sizes to the image sizes in article edition
|
77 |
+
*
|
78 |
+
* @access public
|
79 |
+
*
|
80 |
+
* @param array $form_fields
|
81 |
+
* @param object $post
|
82 |
+
*
|
83 |
+
* @return string
|
84 |
+
* @author Nicolas Juen
|
85 |
+
* @author Additional Image Sizes (zui)
|
86 |
+
*/
|
87 |
+
public static function sizes_in_form( $form_fields, $post ) {
|
88 |
+
// Protect from being view in Media editor where there are no sizes
|
89 |
+
if ( ! isset( $form_fields['image-size'] ) ) {
|
90 |
+
return $form_fields;
|
91 |
+
}
|
92 |
+
|
93 |
+
$out = null;
|
94 |
+
$size_names = array();
|
95 |
+
$sizes_custom = get_option( SIS_OPTION, array() );
|
96 |
+
|
97 |
+
if ( is_array( $sizes_custom ) ) {
|
98 |
+
foreach ( $sizes_custom as $key => $value ) {
|
99 |
+
if ( isset( $value['s'] ) && $value['s'] == 1 ) {
|
100 |
+
$size_names[ $key ] = self::_get_thumbnail_name( $key );;
|
101 |
+
}
|
102 |
+
}
|
103 |
+
}
|
104 |
+
foreach ( $size_names as $size => $label ) {
|
105 |
+
$downsize = image_downsize( $post->ID, $size );
|
106 |
+
|
107 |
+
// is this size selectable?
|
108 |
+
$enabled = ( $downsize[3] || 'full' == $size );
|
109 |
+
$css_id = "image-size-{$size}-{$post->ID}";
|
110 |
+
|
111 |
+
// We must do a clumsy search of the existing html to determine is something has been checked yet
|
112 |
+
if ( false === strpos( 'checked="checked"', $form_fields['image-size']['html'] ) ) {
|
113 |
+
if ( empty( $check ) ) {
|
114 |
+
$check = get_user_setting( 'imgsize' );
|
115 |
+
} // See if they checked a custom size last time
|
116 |
+
|
117 |
+
$checked = '';
|
118 |
+
|
119 |
+
// if this size is the default but that's not available, don't select it
|
120 |
+
if ( $size == $check || str_replace( " ", "", $size ) == $check ) {
|
121 |
+
if ( $enabled ) {
|
122 |
+
$checked = " checked='checked'";
|
123 |
+
} else {
|
124 |
+
$check = '';
|
125 |
+
}
|
126 |
+
} elseif ( ! $check && $enabled && 'thumbnail' != $size ) {
|
127 |
+
// if $check is not enabled, default to the first available size that's bigger than a thumbnail
|
128 |
+
$check = $size;
|
129 |
+
$checked = " checked='checked'";
|
130 |
+
}
|
131 |
+
}
|
132 |
+
$html = "<div class='image-size-item' style='min-height: 50px; margin-top: 18px;'><input type='radio' " . disabled( $enabled, false, false ) . "name='attachments[$post->ID][image-size]' id='{$css_id}' value='{$size}'$checked />";
|
133 |
+
|
134 |
+
$html .= "<label for='{$css_id}'>$label</label>";
|
135 |
+
// only show the dimensions if that choice is available
|
136 |
+
if ( $enabled ) {
|
137 |
+
$html .= " <label for='{$css_id}' class='help'>" . sprintf( "(%d × %d)", $downsize[1], $downsize[2] ) . "</label>";
|
138 |
+
}
|
139 |
+
|
140 |
+
$html .= '</div>';
|
141 |
+
|
142 |
+
$out .= $html;
|
143 |
+
}
|
144 |
+
$form_fields['image-size']['html'] .= $out;
|
145 |
+
|
146 |
+
return $form_fields;
|
147 |
+
}
|
148 |
+
|
149 |
+
/**
|
150 |
+
* Add the thumbnail name in the post insertion, based on new WP filter
|
151 |
+
*
|
152 |
+
* @access public
|
153 |
+
*
|
154 |
+
* @param array $sizes
|
155 |
+
*
|
156 |
+
* @return array
|
157 |
+
* @since 2.3
|
158 |
+
* @author Nicolas Juen
|
159 |
+
* @author radeno based on this post : http://www.wpmayor.com/wordpress-hacks/how-to-add-custom-image-sizes-to-wordpress-uploader/
|
160 |
+
*/
|
161 |
+
public static function add_thumbnail_name( $sizes ) {
|
162 |
+
// Get options
|
163 |
+
$sizes_custom = get_option( SIS_OPTION, array() );
|
164 |
+
// init size array
|
165 |
+
$addsizes = array();
|
166 |
+
|
167 |
+
// check there is custom sizes
|
168 |
+
if ( is_array( $sizes_custom ) && ! empty( $sizes_custom ) ) {
|
169 |
+
foreach ( $sizes_custom as $key => $value ) {
|
170 |
+
// If we show this size in the admin
|
171 |
+
if ( isset( $value['s'] ) && 1 == $value['s'] ) {
|
172 |
+
$addsizes[ $key ] = self::_get_thumbnail_name( $key );
|
173 |
+
}
|
174 |
+
}
|
175 |
+
}
|
176 |
+
|
177 |
+
// Merge the two array
|
178 |
+
$newsizes = array_merge( $sizes, $addsizes );
|
179 |
+
|
180 |
+
// Add new size
|
181 |
+
return $newsizes;
|
182 |
+
}
|
183 |
+
|
184 |
+
/**
|
185 |
+
* Get a thumbnail name from its slug
|
186 |
+
*
|
187 |
+
* @access private
|
188 |
+
*
|
189 |
+
* @param string $thumbnailSlug : the slug of the thumbnail
|
190 |
+
*
|
191 |
+
* @return array
|
192 |
+
* @since 2.3
|
193 |
+
* @author Nicolas Juen
|
194 |
+
*/
|
195 |
+
private static function _get_thumbnail_name( $thumbnailSlug = '' ) {
|
196 |
+
|
197 |
+
// get the options
|
198 |
+
$sizes_custom = get_option( SIS_OPTION );
|
199 |
+
|
200 |
+
if ( ! isset( $sizes_custom[ $thumbnailSlug ] ) ) {
|
201 |
+
// return slug if not found
|
202 |
+
return $thumbnailSlug;
|
203 |
+
}
|
204 |
+
|
205 |
+
// If the name exists return it, slug by default
|
206 |
+
if ( isset( $sizes_custom[ $thumbnailSlug ]['n'] ) && ! empty( $sizes_custom[ $thumbnailSlug ]['n'] ) ) {
|
207 |
+
return $sizes_custom[ $thumbnailSlug ]['n'];
|
208 |
+
}
|
209 |
+
|
210 |
+
return $thumbnailSlug;
|
211 |
+
}
|
212 |
+
|
213 |
+
|
214 |
+
/**
|
215 |
+
* Add action in media row
|
216 |
+
*
|
217 |
+
* @since 2.2
|
218 |
+
* @access public
|
219 |
+
* @return $actions : array of actions and content to display
|
220 |
+
* @author Nicolas Juen
|
221 |
+
*/
|
222 |
+
public static function add_actions_list( $actions, $object ) {
|
223 |
+
if ( ! wp_attachment_is_image( $object->ID ) ) {
|
224 |
+
return $actions;
|
225 |
+
}
|
226 |
+
// Add action for regeneration
|
227 |
+
$actions['sis-regenerate'] = "<a href='#' data-id='" . $object->ID . "' class='sis-regenerate-one'>" . __( 'Regenerate thumbnails', 'simple-image-sizes' ) . "</a>";
|
228 |
+
|
229 |
+
// Return actions
|
230 |
+
return $actions;
|
231 |
+
}
|
232 |
+
|
233 |
+
|
234 |
+
/**
|
235 |
+
* Get a thumbnail name from its slug
|
236 |
+
*
|
237 |
+
* @access public
|
238 |
+
*
|
239 |
+
* @param array $fields : the fields of the media
|
240 |
+
* @param object $post : the post object
|
241 |
+
*
|
242 |
+
* @return array
|
243 |
+
* @since 2.3.1
|
244 |
+
* @author Nicolas Juen
|
245 |
+
*/
|
246 |
+
public static function add_field_regenerate( $fields, $post ) {
|
247 |
+
// Check this is an image
|
248 |
+
if ( false === strpos( $post->post_mime_type, 'image' ) ) {
|
249 |
+
return $fields;
|
250 |
+
}
|
251 |
+
|
252 |
+
$fields['sis-regenerate'] = array(
|
253 |
+
'label' => __( 'Regenerate Thumbnails', 'simple-image-sizes' ),
|
254 |
+
'input' => 'html',
|
255 |
+
'html' => '
|
256 |
+
<input type="button" data-id="' . $post->ID . '" class="button title sis-regenerate-one" value="' . __( 'Regenerate Thumbnails', 'simple-image-sizes' ) . '" />
|
257 |
+
<span class="spinner"></span>
|
258 |
+
<span class="title"><em></em></span>
|
259 |
+
<input type="hidden" class="regen" value="' . wp_create_nonce( 'regen' ) . '" />',
|
260 |
+
'show_in_edit' => true,
|
261 |
+
'show_in_modal' => false,
|
262 |
+
);
|
263 |
+
|
264 |
+
return $fields;
|
265 |
+
}
|
266 |
}
|
classes/main.php
CHANGED
@@ -1,52 +1,61 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
*
|
19 |
-
*
|
20 |
-
* @
|
21 |
-
* @
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
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 |
}
|
1 |
+
<?php
|
2 |
+
|
3 |
+
Class SIS_Client {
|
4 |
+
|
5 |
+
// Set the original
|
6 |
+
var $original = array( 'thumbnail', 'medium', 'large' );
|
7 |
+
|
8 |
+
function __construct() {
|
9 |
+
|
10 |
+
// Make new image sizes
|
11 |
+
add_action( 'init', array( __CLASS__, 'init' ), 1 );
|
12 |
+
|
13 |
+
// Add translation
|
14 |
+
add_action( 'init', array( __CLASS__, 'init_translation' ), 2 );
|
15 |
+
}
|
16 |
+
|
17 |
+
/**
|
18 |
+
* Override the images by the plugin images
|
19 |
+
*
|
20 |
+
* @access public
|
21 |
+
* @return void
|
22 |
+
* @author Nicolas Juen
|
23 |
+
*/
|
24 |
+
public static function init() {
|
25 |
+
// Get inital options
|
26 |
+
$sizes = get_option( SIS_OPTION, array() );
|
27 |
+
|
28 |
+
// Return false if empty
|
29 |
+
if ( empty( $sizes ) || ! is_array( $sizes ) ) {
|
30 |
+
return;
|
31 |
+
}
|
32 |
+
|
33 |
+
// Set the new sizes
|
34 |
+
foreach ( $sizes as $name => $size ) {
|
35 |
+
if ( empty( $size ) || ! isset( $size['w'] ) || ! isset( $size['h'] ) ) {
|
36 |
+
continue;
|
37 |
+
}
|
38 |
+
|
39 |
+
$crop = ( isset( $size['c'] ) && ! empty( $size['c'] ) ) ? $size['c'] : false;
|
40 |
+
|
41 |
+
if ( is_string( $crop ) ) {
|
42 |
+
$crop = explode( '_', $crop );
|
43 |
+
}
|
44 |
+
|
45 |
+
// Add the images sizes
|
46 |
+
add_image_size( $name, $size['w'], $size['h'], $crop );
|
47 |
+
}
|
48 |
+
}
|
49 |
+
|
50 |
+
/**
|
51 |
+
* Load the plugin text domain
|
52 |
+
*
|
53 |
+
* @param void
|
54 |
+
*
|
55 |
+
* @return void
|
56 |
+
* @author Nicolas Juen
|
57 |
+
*/
|
58 |
+
public static function init_translation() {
|
59 |
+
load_plugin_textdomain( 'simple-image-sizes', false, basename( rtrim( SIS_DIR, '/' ) ) . '/languages' );
|
60 |
+
}
|
61 |
}
|
readme.txt
CHANGED
@@ -1,178 +1,180 @@
|
|
1 |
-
=== Simple Image Sizes ===
|
2 |
-
Contributors: Rahe
|
3 |
-
Donate link: http://www.beapi.fr/donate/
|
4 |
-
Tags: images, image, custom sizes, custom images, thumbnail regenerate, thumbnail, regenerate
|
5 |
-
Requires at least: 3.5
|
6 |
-
Tested up to: 4.1
|
7 |
-
Stable tag: 3.0.
|
8 |
-
License: GPLv2 or later
|
9 |
-
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
-
|
11 |
-
== Description ==
|
12 |
-
|
13 |
-
This plugin allow create custom image sizes for your site. Override your theme sizes directly on the media option page.
|
14 |
-
You can regenerate all the sizes you have just created and choose which one you wanted to regenerate.
|
15 |
-
You can now get all the code to copy and paste to your function theme file.
|
16 |
-
Now you can use the generated sizes directly into your posts and insert images at the right size !
|
17 |
-
Now you choose if you want display the size in the post insert image.
|
18 |
-
Now you can regenerate the images one by one in the 'Medias' general pane.
|
19 |
-
Now you can regenerate the images by bulk action in the 'Medias' general pane.
|
20 |
-
Now you can regenerate the image sizes on single attachment edit page.
|
21 |
-
|
22 |
-
I have added a timer so when you regeneration your thumbnails, you can know approximately when the regeneration will be ended.
|
23 |
-
I have improved the php and javascript, you can know if the image have been regenerated or not or if there is an error and which one.
|
24 |
-
|
25 |
-
Contribute on https://github.com/Rahe/Simple-image-sizes
|
26 |
-
|
27 |
-
== Installation ==
|
28 |
-
**PHP5 Required.**
|
29 |
-
|
30 |
-
1. Download, unzip and upload to your WordPress plugins directory
|
31 |
-
2. Activate the plugin within you WordPress Administration Backend
|
32 |
-
3. Go to Settings > Medias
|
33 |
-
4. Configure your new image sizes and regenerate the thumbnails !
|
34 |
-
|
35 |
-
== Frequently Asked Questions ==
|
36 |
-
|
37 |
-
= Where can I add image sizes ? =
|
38 |
-
Go to Settings -> Media then you can add a image size. You have to add a unique custom name without any spaces or special chars.
|
39 |
-
The best is to use something like my-custom-size.
|
40 |
-
Then you have several fields for configuring the image size, the widht, the height, cropping.
|
41 |
-
And then you can choose if the image is displayed on the media insertion or not ( this will be displayed on the dropdown list ).
|
42 |
-
|
43 |
-
|
44 |
-
== Screenshots ==
|
45 |
-
|
46 |
-
1. Settings page
|
47 |
-
2. Get PHP for the theme
|
48 |
-
3. Choose the sizes to regenerate and regenerate them
|
49 |
-
|
50 |
-
== Changelog ==
|
51 |
-
* 3.0.
|
52 |
-
*
|
53 |
-
* 3.0.
|
54 |
-
*
|
55 |
-
* 3.0.
|
56 |
-
*
|
57 |
-
|
58 |
-
*
|
59 |
-
*
|
60 |
-
*
|
61 |
-
*
|
62 |
-
|
63 |
-
*
|
64 |
-
*
|
65 |
-
*
|
66 |
-
*
|
67 |
-
*
|
68 |
-
|
69 |
-
*
|
70 |
-
*
|
71 |
-
* 2.4.
|
72 |
-
*
|
73 |
-
* 2.4
|
74 |
-
*
|
75 |
-
|
76 |
-
*
|
77 |
-
*
|
78 |
-
*
|
79 |
-
*
|
80 |
-
*
|
81 |
-
*
|
82 |
-
|
83 |
-
*
|
84 |
-
* Add
|
85 |
-
|
86 |
-
*
|
87 |
-
*
|
88 |
-
|
89 |
-
*
|
90 |
-
*
|
91 |
-
*
|
92 |
-
|
93 |
-
* Add
|
94 |
-
*
|
95 |
-
*
|
96 |
-
*
|
97 |
-
*
|
98 |
-
*
|
99 |
-
* 2.2.
|
100 |
-
*
|
101 |
-
|
102 |
-
*
|
103 |
-
*
|
104 |
-
|
105 |
-
*
|
106 |
-
*
|
107 |
-
*
|
108 |
-
*
|
109 |
-
|
110 |
-
*
|
111 |
-
*
|
112 |
-
*
|
113 |
-
*
|
114 |
-
*
|
115 |
-
*
|
116 |
-
*
|
117 |
-
*
|
118 |
-
|
119 |
-
*
|
120 |
-
*
|
121 |
-
*
|
122 |
-
*
|
123 |
-
* Remove
|
124 |
-
*
|
125 |
-
*
|
126 |
-
*
|
127 |
-
* 2.0.
|
128 |
-
*
|
129 |
-
|
130 |
-
*
|
131 |
-
* Resolve
|
132 |
-
|
133 |
-
*
|
134 |
-
*
|
135 |
-
|
136 |
-
*
|
137 |
-
|
138 |
-
|
139 |
-
*
|
140 |
-
|
141 |
-
|
142 |
-
*
|
143 |
-
*
|
144 |
-
* Handle
|
145 |
-
*
|
146 |
-
*
|
147 |
-
*
|
148 |
-
*
|
149 |
-
*
|
150 |
-
*
|
151 |
-
*
|
152 |
-
|
153 |
-
*
|
154 |
-
*
|
155 |
-
*
|
156 |
-
|
157 |
-
*
|
158 |
-
*
|
159 |
-
*
|
160 |
-
*
|
161 |
-
* 1.0.
|
162 |
-
* Fix the
|
163 |
-
|
164 |
-
*
|
165 |
-
* Add
|
166 |
-
*
|
167 |
-
*
|
168 |
-
* Add
|
169 |
-
*
|
170 |
-
*
|
171 |
-
*
|
172 |
-
* 1.0.
|
173 |
-
*
|
174 |
-
|
175 |
-
*
|
176 |
-
*
|
177 |
-
|
|
|
|
|
178 |
* Image size generation
|
1 |
+
=== Simple Image Sizes ===
|
2 |
+
Contributors: Rahe
|
3 |
+
Donate link: http://www.beapi.fr/donate/
|
4 |
+
Tags: images, image, custom sizes, custom images, thumbnail regenerate, thumbnail, regenerate
|
5 |
+
Requires at least: 3.5
|
6 |
+
Tested up to: 4.2.1
|
7 |
+
Stable tag: 3.0.4
|
8 |
+
License: GPLv2 or later
|
9 |
+
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
+
|
11 |
+
== Description ==
|
12 |
+
|
13 |
+
This plugin allow create custom image sizes for your site. Override your theme sizes directly on the media option page.
|
14 |
+
You can regenerate all the sizes you have just created and choose which one you wanted to regenerate.
|
15 |
+
You can now get all the code to copy and paste to your function theme file.
|
16 |
+
Now you can use the generated sizes directly into your posts and insert images at the right size !
|
17 |
+
Now you choose if you want display the size in the post insert image.
|
18 |
+
Now you can regenerate the images one by one in the 'Medias' general pane.
|
19 |
+
Now you can regenerate the images by bulk action in the 'Medias' general pane.
|
20 |
+
Now you can regenerate the image sizes on single attachment edit page.
|
21 |
+
|
22 |
+
I have added a timer so when you regeneration your thumbnails, you can know approximately when the regeneration will be ended.
|
23 |
+
I have improved the php and javascript, you can know if the image have been regenerated or not or if there is an error and which one.
|
24 |
+
|
25 |
+
Contribute on https://github.com/Rahe/Simple-image-sizes
|
26 |
+
|
27 |
+
== Installation ==
|
28 |
+
**PHP5 Required.**
|
29 |
+
|
30 |
+
1. Download, unzip and upload to your WordPress plugins directory
|
31 |
+
2. Activate the plugin within you WordPress Administration Backend
|
32 |
+
3. Go to Settings > Medias
|
33 |
+
4. Configure your new image sizes and regenerate the thumbnails !
|
34 |
+
|
35 |
+
== Frequently Asked Questions ==
|
36 |
+
|
37 |
+
= Where can I add image sizes ? =
|
38 |
+
Go to Settings -> Media then you can add a image size. You have to add a unique custom name without any spaces or special chars.
|
39 |
+
The best is to use something like my-custom-size.
|
40 |
+
Then you have several fields for configuring the image size, the widht, the height, cropping.
|
41 |
+
And then you can choose if the image is displayed on the media insertion or not ( this will be displayed on the dropdown list ).
|
42 |
+
|
43 |
+
|
44 |
+
== Screenshots ==
|
45 |
+
|
46 |
+
1. Settings page
|
47 |
+
2. Get PHP for the theme
|
48 |
+
3. Choose the sizes to regenerate and regenerate them
|
49 |
+
|
50 |
+
== Changelog ==
|
51 |
+
* 3.0.4
|
52 |
+
* Fix global add_image_size
|
53 |
+
* 3.0.3
|
54 |
+
* Add Hebrew translations thanks to Atar4U
|
55 |
+
* 3.0.2
|
56 |
+
* Fix version check for the image crop positions
|
57 |
+
* 3.0.1
|
58 |
+
* Change the template render method for non apache webservers : https://wordpress.org/support/topic/fatal-error-1190?replies=6
|
59 |
+
* Remove ambigious ids for the css bugging WooCommerce : https://wordpress.org/support/topic/bad-css-style-administration and
|
60 |
+
* Right code for counting the elements on backoffice : https://github.com/Rahe/Simple-image-sizes/issues/20
|
61 |
+
* Fix bug on regenation and _e instead of __ : https://plugins.trac.wordpress.org/ticket/2259
|
62 |
+
* 3.0
|
63 |
+
* Revamping all the code, change classes and structure
|
64 |
+
* Use grunt for compiling files
|
65 |
+
* Handle the 3.9 new cropping position
|
66 |
+
* Remove aristo css
|
67 |
+
* Use UI from WordPress
|
68 |
+
* 2.4.3
|
69 |
+
* Remove some php notices
|
70 |
+
* Remove notice when wrong image size
|
71 |
+
* 2.4.2
|
72 |
+
* Selective regeneration fix by g100g on http://wordpress.org/support/topic/regenerating-fix
|
73 |
+
* 2.4.1
|
74 |
+
* Remove function not working on admin file
|
75 |
+
* 2.4
|
76 |
+
* Made for 3.5 and up
|
77 |
+
* Refactoring PHP/Javascript code
|
78 |
+
* Javascript improvements
|
79 |
+
* Remove useless UI
|
80 |
+
* UI improvements
|
81 |
+
* Global PHP performance improvements
|
82 |
+
* 2.3.1
|
83 |
+
* Add Ajax bulk actions on medias list
|
84 |
+
* Add ajax thumbnail rebuild on single media
|
85 |
+
* 2.3
|
86 |
+
* Add the custom size name in the attachment insertion
|
87 |
+
* Exclude post_type wich do not support the post-thumbnail feature
|
88 |
+
* 2.2.5
|
89 |
+
* Debug the regeneration buggy !
|
90 |
+
* Complete the french translation
|
91 |
+
* Security update for single regeneration, include the nonce this time :)
|
92 |
+
* 2.2.4
|
93 |
+
* Add security nonces for every actions
|
94 |
+
* Put the messages at the begining of the log
|
95 |
+
* Add a select all checkbox Thank to cocola
|
96 |
+
* Add the german translation thanks to glueckpress
|
97 |
+
* Remove notice tnahks to christianwach
|
98 |
+
* Remove useless and buggy for my scripting pointers
|
99 |
+
* 2.2.3
|
100 |
+
* Do not force network usage
|
101 |
+
* 2.2.2
|
102 |
+
* Debug js for the buttons
|
103 |
+
* Remove console.log calls
|
104 |
+
* 2.2.1
|
105 |
+
* Use buttonset for the checkboxes
|
106 |
+
* Add Pointer for WordPress 3.3
|
107 |
+
* Fix translation in French
|
108 |
+
* Some medias queries for small windows ( change size of buttons and alignment )
|
109 |
+
* 2.2
|
110 |
+
* Add new version of css aristo
|
111 |
+
* Add some icons
|
112 |
+
* Display button for saving changes only when changes detected
|
113 |
+
* Display message when a size is modified but not saved and wanted to regenerate
|
114 |
+
* Debug functionnality when regenerating only some sizes, metas not crushed
|
115 |
+
* Add solo regenerating
|
116 |
+
* Remove displaying for theme/not theme sizes
|
117 |
+
* Use WordPress class for small inputs
|
118 |
+
* 2.1
|
119 |
+
* Add javascript timer
|
120 |
+
* Improve javascript and more IE friendly
|
121 |
+
* You can now choose if you want to display the image sizes in image insertion or not
|
122 |
+
* Handle errors and messages
|
123 |
+
* Remove some css useless rules
|
124 |
+
* Fix bad translation for french
|
125 |
+
* Remove accents in image sizes
|
126 |
+
* Do not update size properties if there is an ajax query for an another size name
|
127 |
+
* 2.0.3
|
128 |
+
* Resolve issue with theme sizes witch by default are displayed as not cropped. Thanks to momo360modena for the bug signalment.
|
129 |
+
* 2.0.2
|
130 |
+
* Remove debug on php for javascript
|
131 |
+
* Resolve issue with the different versions on jquery ( like in WP3.2 ) with attr return for checked components
|
132 |
+
* 2.0.1
|
133 |
+
* Resolve javascript issue when clicking on delete button
|
134 |
+
* Resolve issue of never unchecking crop button
|
135 |
+
* 2.0
|
136 |
+
* Code refactoring
|
137 |
+
* Update translations
|
138 |
+
* Ajaxification of the process
|
139 |
+
* Deleting by Ajax
|
140 |
+
* Updating by Ajax
|
141 |
+
* Adding by Ajax
|
142 |
+
* Change UI
|
143 |
+
* Change theme
|
144 |
+
* Handle ajax errors
|
145 |
+
* Handle not modified sizes, cropped
|
146 |
+
* Handle same names
|
147 |
+
* Sanitize the names
|
148 |
+
* Customize jQuery ui
|
149 |
+
* Customize jQuery ui theme
|
150 |
+
* HTML5 Elements
|
151 |
+
* CSS3 Animations
|
152 |
+
* 1.0.6
|
153 |
+
* Minify javascript names
|
154 |
+
* Change progressbar style
|
155 |
+
* Add animations on progressbar
|
156 |
+
* 1.0.5
|
157 |
+
* Only add css and js script in the media page to avoid any javascript error in other pages
|
158 |
+
* Rectify css
|
159 |
+
* Add function to get the code for the function.php file of the theme
|
160 |
+
* Don't redefine the Wordpress basic size names
|
161 |
+
* 1.0.4
|
162 |
+
* Fix the add_image_size issue ( height and width reversed )
|
163 |
+
* 1.0.3
|
164 |
+
* Fix the plugin language
|
165 |
+
* Add some translations
|
166 |
+
* Externalise some css
|
167 |
+
* Add sizes in the image adding to an article
|
168 |
+
* Add setting link in the plugins list
|
169 |
+
* Use admin_url instead of home_url
|
170 |
+
* Add legend for colors
|
171 |
+
* Some code refactoring
|
172 |
+
* 1.0.2
|
173 |
+
* Fix the plugin license
|
174 |
+
* 1.0.1
|
175 |
+
* Add POT file
|
176 |
+
* Add french translation
|
177 |
+
* 1.0
|
178 |
+
* First release
|
179 |
+
* Thumbnail regenerate
|
180 |
* Image size generation
|
simple_image_sizes.php
CHANGED
@@ -1,60 +1,62 @@
|
|
1 |
-
<?php
|
2 |
-
/*
|
3 |
-
Plugin Name: Simple Image Sizes
|
4 |
-
Plugin URI: https://github.com/Rahe/
|
5 |
-
Description: Add options in media setting page for images sizes
|
6 |
-
Version: 3.0.
|
7 |
-
Author: Rahe
|
8 |
-
Author URI: http://nicolas-juen.fr
|
9 |
-
Text Domain: 'simple-image-sizes'
|
10 |
-
Domain Path: /languages
|
11 |
-
License: GPLv2 or later
|
12 |
-
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
13 |
-
|
14 |
-
Copyright 2011 Nicolas JUEN (njuen@beapi.fr) - Be-API
|
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 2 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, write to the Free Software
|
28 |
-
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
29 |
-
*/
|
30 |
-
|
31 |
-
define( 'SIS_URL', plugin_dir_url
|
32 |
-
define( 'SIS_DIR', plugin_dir_path( __FILE__ ) );
|
33 |
-
define( 'SIS_VERSION', '3.0.
|
34 |
-
define( 'SIS_OPTION', 'custom_image_sizes' );
|
35 |
-
|
36 |
-
// Function for easy load files
|
37 |
-
function _sis_load_files($dir, $files, $prefix = '') {
|
38 |
-
foreach ( $files as $file ) {
|
39 |
-
if ( is_file( $dir . $prefix . $file .
|
40 |
-
require_once( $dir . $prefix . $file .
|
41 |
-
}
|
42 |
-
}
|
43 |
-
}
|
44 |
-
|
45 |
-
// Plugin client classes
|
46 |
-
_sis_load_files( SIS_DIR . 'classes/', array( 'main' ) );
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
new
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Plugin Name: Simple Image Sizes
|
4 |
+
Plugin URI: https://github.com/Rahe/simple-image-sizes
|
5 |
+
Description: Add options in media setting page for images sizes
|
6 |
+
Version: 3.0.4
|
7 |
+
Author: Rahe
|
8 |
+
Author URI: http://nicolas-juen.fr
|
9 |
+
Text Domain: 'simple-image-sizes'
|
10 |
+
Domain Path: /languages
|
11 |
+
License: GPLv2 or later
|
12 |
+
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
13 |
+
|
14 |
+
Copyright 2011 Nicolas JUEN (njuen@beapi.fr) - Be-API
|
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 2 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, write to the Free Software
|
28 |
+
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
29 |
+
*/
|
30 |
+
|
31 |
+
define( 'SIS_URL', plugin_dir_url( __FILE__ ) );
|
32 |
+
define( 'SIS_DIR', plugin_dir_path( __FILE__ ) );
|
33 |
+
define( 'SIS_VERSION', '3.0.4' );
|
34 |
+
define( 'SIS_OPTION', 'custom_image_sizes' );
|
35 |
+
|
36 |
+
// Function for easy load files
|
37 |
+
function _sis_load_files( $dir, $files, $prefix = '' ) {
|
38 |
+
foreach ( $files as $file ) {
|
39 |
+
if ( is_file( $dir . $prefix . $file . '.php' ) ) {
|
40 |
+
require_once( $dir . $prefix . $file . '.php' );
|
41 |
+
}
|
42 |
+
}
|
43 |
+
}
|
44 |
+
|
45 |
+
// Plugin client classes
|
46 |
+
_sis_load_files( SIS_DIR . 'classes/', array( 'main' ) );
|
47 |
+
|
48 |
+
if ( is_admin() ) {
|
49 |
+
// Admins classes
|
50 |
+
_sis_load_files( SIS_DIR . 'classes/admin/', array( 'main', 'post', 'media' ) );
|
51 |
+
}
|
52 |
+
|
53 |
+
add_action( 'plugins_loaded', 'init_sis' );
|
54 |
+
function init_sis() {
|
55 |
+
if ( is_admin() ) {
|
56 |
+
new SIS_Admin_Main();
|
57 |
+
new SIS_Admin_Post();
|
58 |
+
new SIS_Admin_Media();
|
59 |
+
}
|
60 |
+
|
61 |
+
new SIS_Client();
|
62 |
+
}
|