Plugin Directory

Changeset 2448747


Ignore:
Timestamp:
01/01/2021 07:07:47 AM (5 years ago)
Author:
aiwatech
Message:

v-1.0.4 - Media uploader image sizes fixed.

Location:
wp-image-sizes
Files:
14 added
3 edited

Legend:

Unmodified
Added
Removed
  • wp-image-sizes/trunk/readme.txt

    r2446637 r2448747  
    44Requires at least: 4.7
    55Requires PHP: 5.2.4
    6 Stable tag: 1.0.3
     6Stable tag: 1.0.4
    77Tested up to: 5.6
    88License: GPLv2 or later
     
    1313== Description ==
    1414
    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.
     15In 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
     17With 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
     19When 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
     21Now 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
     23Ultimately website speed gets effected and server space as well.
     24
     25To 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
     27After 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
     29In 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
     31WP Image Sizes plugin saves a lot of space on the server and plays a role to make WordPress website a bit fast.
    1832
    1933
     
    4256
    4357== 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)
     58WP Image Sizes plugin is also available in a professional version which includes more features [See here](https://aiwatech.com/product/wp-image-sizes-pro/)
    4559
    4660
     
    5266
    5367== Changelog ==
     68= 1.0.4 =
     69* Media upload image sizes bug fix
     70
    5471= 1.0.3 =
    5572* Session storage changed to fix register_globals conflict
  • wp-image-sizes/trunk/wp-image-sizes.php

    r2446637 r2448747  
    44 * Plugin URI: https://aiwatech.com/wp-image-sizes
    55 * 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.3
     6 * Version: 1.0.4
    77 * Requires at least: 4.7
    88 * Tested up to: 5.6
  • wp-image-sizes/trunk/wpis-init.php

    r2446637 r2448747  
    2424
    2525//==== Add Plugin Menu Page ===//
    26 if(!function_exists('wpis_menu_pages')):
     26if(!function_exists("wpis_menu_pages")):
    2727    add_action("admin_menu", "wpis_menu_pages", 80 );
    2828    function wpis_menu_pages(){
     
    4141endif;
    4242
    43 if(!function_exists('wpis_get_attachment_image_src')):
     43if(!function_exists("wpis_get_attachment_image_src")):
    4444//=== Create Images on Runtime ===//
    4545add_filter( "wp_get_attachment_image_src", "wpis_get_attachment_image_src", 10, 4 );
     
    130130endif;
    131131
    132 if(!function_exists('wpis_image_sizes_advanced')):
     132if(!function_exists("wpis_image_sizes_advanced")):
    133133//==== Filter Image Sizes ===//
    134134add_filter("intermediate_image_sizes_advanced", "wpis_image_sizes_advanced", 10, 3);
     
    136136    global $wpis_image_sizes;
    137137   
    138     $wpis_session = get_option( "wpis_session" );
     138    $wpis_session   = get_option( "wpis_session" );
    139139   
    140140    $post_type = get_post_type( intval($_REQUEST["post_id"]) );
    141141   
    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        }
    144146    }
    145147   
     
    154156    }
    155157   
    156     //=== Remove sizes from session
    157     unset($wpis_session["wpis_image_sizes"][$post_type]);
    158     update_option( "wpis_session", $wpis_session );
    159    
    160158    return $sizes;
    161159}
    162160endif;
    163161
    164 if(!function_exists('save_wpis_image_sizes')):
     162if(!function_exists("save_wpis_image_sizes")):
    165163add_action("wp_ajax_save_wpis_image_sizes", "save_wpis_image_sizes");
    166164function save_wpis_image_sizes(){
     
    182180   
    183181    $wpis_session["wpis_image_sizes"][$post_type] = $wpis_image_sizes;
     182   
    184183    update_option( "wpis_session", $wpis_session );
    185184   
     
    188187endif;
    189188
    190 if(!function_exists('wpis_media_uploader_ui')):
     189if(!function_exists("wpis_session_reset")):
     190//==== Reset WPIS Session ===//
     191add_action("wp_ajax_wpis_session_reset", "wpis_session_reset");
     192function 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}
     200endif;
     201
     202if(!function_exists("wpis_media_uploader_ui")):
    191203//==== Show Image Sizes on Media Uploader ===//
    192204add_action( "post-upload-ui", "wpis_media_uploader_ui" );
    193205function wpis_media_uploader_ui(){
     206    global $wpis_image_sizes;
    194207   
    195208    $wpis_session = get_option( "wpis_session" );
    196209   
    197210    $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    ?>
    199222   
    200223    <div class="wpis-image-sizes">
     
    203226        <div class="wpis-image-size-boxes">
    204227        <?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        
    213228        $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
    215230        foreach( $intermediate_image_sizes as $image_size ){
    216231           
     
    236251                )
    237252            );
    238                
    239         }?>
     253        }
     254       
     255        ?>
    240256        </div>
    241257    </div>
     
    243259       
    244260        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){
    246285                e.stopImmediatePropagation();
    247286                assign_image_sizes();
     
    253292           
    254293            wpis_image_sizes = [];
    255            
     294            wpis_disable_sizes = $(".disable-size-checkbox > .wpis-checkbox").is(":checked");
     295
    256296            $(".image-size-checkbox").each(function(){
    257297                var checkbox = $(this).find("input:checkbox");
     
    265305                }
    266306            });
    267            
     307
    268308            $.ajax({
    269309                url: "<?=admin_url("admin-ajax.php")?>",
     
    272312                    action: "save_wpis_image_sizes",
    273313                    post_type:"<?=$post_type?>",
    274                     wpis_image_sizes: wpis_image_sizes
     314                    wpis_image_sizes: wpis_image_sizes,
    275315                }
    276316            });
     
    282322
    283323//=== 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 }
     324add_filter( "pre_update_option", "wpis_update_option", 10, 3 );
     325function 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.