Changeset 2448747
- Timestamp:
- 01/01/2021 07:07:47 AM (5 years ago)
- Location:
- wp-image-sizes
- Files:
-
- 14 added
- 3 edited
-
tags/1.0.4 (added)
-
tags/1.0.4/assets (added)
-
tags/1.0.4/assets/css (added)
-
tags/1.0.4/assets/css/wpis-style.css (added)
-
tags/1.0.4/assets/js (added)
-
tags/1.0.4/assets/js/api-request.min.js (added)
-
tags/1.0.4/assets/js/wpis.js (added)
-
tags/1.0.4/includes (added)
-
tags/1.0.4/includes/tab-templates (added)
-
tags/1.0.4/includes/tab-templates/image-sizes.php (added)
-
tags/1.0.4/includes/wpis-settings.php (added)
-
tags/1.0.4/readme.txt (added)
-
tags/1.0.4/wp-image-sizes.php (added)
-
tags/1.0.4/wpis-init.php (added)
-
trunk/readme.txt (modified) (4 diffs)
-
trunk/wp-image-sizes.php (modified) (1 diff)
-
trunk/wpis-init.php (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-image-sizes/trunk/readme.txt
r2446637 r2448747 4 4 Requires at least: 4.7 5 5 Requires PHP: 5.2.4 6 Stable tag: 1.0. 36 Stable tag: 1.0.4 7 7 Tested up to: 5.6 8 8 License: GPLv2 or later … … 13 13 == Description == 14 14 15 Whenever an image is uploaded, wordpress creates all registered image sizes which leads to disk storage consumption for unnecessary images. 16 Aiwatech introduces WP Image Sizes which gives you the option to select only required image sizes for every post type and whenever an image is uplaoded for post type, it will only create selected sizes and avoid creation of unnecessary images. 17 This drastically saves server space by preventing unnecessary image sizes. 15 In modern web designs, designers create different sizes of images on the web pages for attractive layout. If a web page is built using wordpress, a developer has to register every image size in theme to make sure, if client uploads an image of different size, it does not break the layout. 16 17 With a new WordPress installation, by default it creates three sizes e.g. thumbnail (150 x 150), medium (300×300), large (1024×1024) which means whenever a new image will be uploaded, WordPress will keep at least four copies of images on the server, one original image and 3 cropped image copies based on image sizes. 18 19 When developer/designer needs different size of image, they will register more image sizes e.g. hero, product thumbnail, product large image, team member image etc depending on design of the page. 20 21 Now lets say we have 3 default and 3 custom image sizes defined in theme, and now whenever a new image will be uploaded, WordPress will create 6 image copies and 1 original image even we need to use only 1 for a specific area on the website, remaining copies will remain on the server and will occupy space. Imagine when we have lots of posts, pages having different images, how many unnecessary images WordPress creates on the server which are useless and just eat server space. In case of Woo-Commerce website if you need to upload a new slider image for home page or a hero image for about page, it will create a lots of copies including different sizes of products image sizes which woo-commerce registers itself. 22 23 Ultimately website speed gets effected and server space as well. 24 25 To solve this issue, we built a plugin WP Image Sizes this plugin allows user to decide which image sizes should be created for every image being uploaded through WordPress. 26 27 After installing WP Image Sizes, it will create a setting page from where user can assign image sizes to each CPT. e.g. user can assign one size for hero/slider CPT, one size for team member, testimonials. After assigning image sizes to each CPT when user will upload a new image, WP Image Sizes will only allow WordPress to create copies of image sizes which were assigned to the CPT. 28 29 In case user tries to upload an image from a Media, it will show options in media uploader to select which image size user wants and WP Image Sizes will only create that image size. 30 31 WP Image Sizes plugin saves a lot of space on the server and plays a role to make WordPress website a bit fast. 18 32 19 33 … … 42 56 43 57 == PRO == 44 WP Image Sizes plugin is also available in a professional version which includes more features [See here](https://aiwatech.com/ wp-image-sizes)58 WP Image Sizes plugin is also available in a professional version which includes more features [See here](https://aiwatech.com/product/wp-image-sizes-pro/) 45 59 46 60 … … 52 66 53 67 == Changelog == 68 = 1.0.4 = 69 * Media upload image sizes bug fix 70 54 71 = 1.0.3 = 55 72 * Session storage changed to fix register_globals conflict -
wp-image-sizes/trunk/wp-image-sizes.php
r2446637 r2448747 4 4 * Plugin URI: https://aiwatech.com/wp-image-sizes 5 5 * Description: Save server space by creating selected image sizes for every post type. It allows to select registered image sizes in media uploader and helps to avoid creation of unneccessary images. 6 * Version: 1.0. 36 * Version: 1.0.4 7 7 * Requires at least: 4.7 8 8 * Tested up to: 5.6 -
wp-image-sizes/trunk/wpis-init.php
r2446637 r2448747 24 24 25 25 //==== Add Plugin Menu Page ===// 26 if(!function_exists( 'wpis_menu_pages')):26 if(!function_exists("wpis_menu_pages")): 27 27 add_action("admin_menu", "wpis_menu_pages", 80 ); 28 28 function wpis_menu_pages(){ … … 41 41 endif; 42 42 43 if(!function_exists( 'wpis_get_attachment_image_src')):43 if(!function_exists("wpis_get_attachment_image_src")): 44 44 //=== Create Images on Runtime ===// 45 45 add_filter( "wp_get_attachment_image_src", "wpis_get_attachment_image_src", 10, 4 ); … … 130 130 endif; 131 131 132 if(!function_exists( 'wpis_image_sizes_advanced')):132 if(!function_exists("wpis_image_sizes_advanced")): 133 133 //==== Filter Image Sizes ===// 134 134 add_filter("intermediate_image_sizes_advanced", "wpis_image_sizes_advanced", 10, 3); … … 136 136 global $wpis_image_sizes; 137 137 138 $wpis_session = get_option( "wpis_session" );138 $wpis_session = get_option( "wpis_session" ); 139 139 140 140 $post_type = get_post_type( intval($_REQUEST["post_id"]) ); 141 141 142 if( !$post_type && get_current_screen() && get_current_screen()->base == "async-upload" ){ 143 $post_type = "attachment"; 142 if( !$post_type && get_current_screen() ){ 143 if( get_current_screen()->base != "attachment" ){ 144 $post_type = "attachment"; 145 } 144 146 } 145 147 … … 154 156 } 155 157 156 //=== Remove sizes from session157 unset($wpis_session["wpis_image_sizes"][$post_type]);158 update_option( "wpis_session", $wpis_session );159 160 158 return $sizes; 161 159 } 162 160 endif; 163 161 164 if(!function_exists( 'save_wpis_image_sizes')):162 if(!function_exists("save_wpis_image_sizes")): 165 163 add_action("wp_ajax_save_wpis_image_sizes", "save_wpis_image_sizes"); 166 164 function save_wpis_image_sizes(){ … … 182 180 183 181 $wpis_session["wpis_image_sizes"][$post_type] = $wpis_image_sizes; 182 184 183 update_option( "wpis_session", $wpis_session ); 185 184 … … 188 187 endif; 189 188 190 if(!function_exists('wpis_media_uploader_ui')): 189 if(!function_exists("wpis_session_reset")): 190 //==== Reset WPIS Session ===// 191 add_action("wp_ajax_wpis_session_reset", "wpis_session_reset"); 192 function wpis_session_reset(){ 193 $res["success"] = 0; 194 $res["message"] = __("Session has been reset", "wpis"); 195 196 update_option( "wpis_session", [] ); 197 198 die(json_encode($res)); 199 } 200 endif; 201 202 if(!function_exists("wpis_media_uploader_ui")): 191 203 //==== Show Image Sizes on Media Uploader ===// 192 204 add_action( "post-upload-ui", "wpis_media_uploader_ui" ); 193 205 function wpis_media_uploader_ui(){ 206 global $wpis_image_sizes; 194 207 195 208 $wpis_session = get_option( "wpis_session" ); 196 209 197 210 $intermediate_image_sizes = get_intermediate_image_sizes(); 198 $wp_additional_image_sizes = wp_get_additional_image_sizes();?> 211 $wp_additional_image_sizes = wp_get_additional_image_sizes(); 212 213 $post_type = get_post_type( intval($_REQUEST["post"]) ); 214 215 if( !$post_type && get_current_screen() ){ 216 if( get_current_screen()->base != "attachment" ){ 217 $post_type = "attachment"; 218 } 219 } 220 221 ?> 199 222 200 223 <div class="wpis-image-sizes"> … … 203 226 <div class="wpis-image-size-boxes"> 204 227 <?php 205 global $wpis_image_sizes;206 207 $post_type = get_post_type( intval($_REQUEST["post"]) );208 209 if( !$post_type && get_current_screen() && get_current_screen()->base == "upload" ){210 $post_type = "attachment";211 }212 213 228 $wpis_image_sizes[$post_type] = isset($wpis_session["wpis_image_sizes"][$post_type]) ? array_map("sanitize_text_field",$wpis_session["wpis_image_sizes"][$post_type]) : array_map("sanitize_text_field", (array)$wpis_image_sizes[$post_type]); 214 229 215 230 foreach( $intermediate_image_sizes as $image_size ){ 216 231 … … 236 251 ) 237 252 ); 238 239 }?> 253 } 254 255 ?> 240 256 </div> 241 257 </div> … … 243 259 244 260 jQuery(document).ready(function($) { 245 $(".image-size-checkbox > input").change(function(e){ 261 262 if( wp.media ){ 263 264 var ajaxed = false; 265 266 wp.media.frame.on("close", function(e){ 267 if( !ajaxed ){ 268 ajaxed = true; 269 270 $.ajax({ 271 url: "<?=admin_url("admin-ajax.php")?>", 272 type: "POST", 273 data: { 274 action: "wpis_session_reset", 275 }, 276 success: function(res){ 277 ajaxed = false; 278 } 279 }); 280 } 281 }); 282 283 } 284 $(".image-size-checkbox > input, .disable-size-checkbox > input").change(function(e){ 246 285 e.stopImmediatePropagation(); 247 286 assign_image_sizes(); … … 253 292 254 293 wpis_image_sizes = []; 255 294 wpis_disable_sizes = $(".disable-size-checkbox > .wpis-checkbox").is(":checked"); 295 256 296 $(".image-size-checkbox").each(function(){ 257 297 var checkbox = $(this).find("input:checkbox"); … … 265 305 } 266 306 }); 267 307 268 308 $.ajax({ 269 309 url: "<?=admin_url("admin-ajax.php")?>", … … 272 312 action: "save_wpis_image_sizes", 273 313 post_type:"<?=$post_type?>", 274 wpis_image_sizes: wpis_image_sizes 314 wpis_image_sizes: wpis_image_sizes, 275 315 } 276 316 }); … … 282 322 283 323 //=== Hooked update wpis settings 284 add_action( "update_option_wpis", "wpis_update_option", 10, 3 ); 285 function wpis_update_option( $old_option, $new_option, $option ){ 286 update_option( "wpis_session", [] ); 287 } 324 add_filter( "pre_update_option", "wpis_update_option", 10, 3 ); 325 function wpis_update_option( $value, $option, $old_value ){ 326 327 if( $option == "wpis" ){ 328 update_option( "wpis_session", [] ); 329 } 330 331 return $value; 332 }
Note: See TracChangeset
for help on using the changeset viewer.