Image Regenerate & Select Crop 4.3
Starting with version 4.3, the Image Regenerate & Select Crop plugin has some new features, please see below more details.
Summary for Version 4.3
- MOD Available Settings Overview
- NEW Advanced Custom Rules
- NEW Custom Rules Filter
- MOD Image Details & Options Lightbox
- MOD NEW WP-CLI New Commands & Flags
- Other updates
Settings Overview
Image Regenerate & Select Crop Settings
Please make sure you visit and update your settings whenever you activate a new theme or plugin so that the new image size is registered, adjusted, or removed to be reflected also here, and in this way to assure the optimal behavior for the features of this plugin.
Option to Enable Placeholders
This option allows you to display placeholders for the front-side images called programmatically (the images that are not embedded in the content with their src but exposed using WordPress native functions). If there is no placeholder set, then the WordPress default behavior would be to display the full-size image instead of the missing image size, hence your pages might load slower, and when using grids, the items would not look even.
If you activate the “force global” option, all the images on the front-side that are related to posts will be replaced with the placeholders that mention the image size required. This is useful for debugging, to quickly identify the image sizes used for each layout, and perhaps to help you regenerate the mission ones or decide what to keep or what to remove.
If you activate the “only missing images” option, all the programmatically called images on the front-side that are related to posts and do not have the requested image size generated will be replaced with the placeholders that mention the image size required. This is useful for showing smaller images instead of full-size images (as WordPress does by default), hence speeding up the page loading.
Option to Exclude Image Sizes
The plugin provides the option to select image sizes that will be excluded from the generation of the new images. By default, all image sizes defined in the system will be allowed (these are programmatically registered by the themes and plugins you activate on your site, without you even knowing about these). You can set up a global configuration, or a more specific configuration for all images attached to a particular post type. If no particular settings are made for a post type, then the default general settings will be used. The options for which you made some settings are marked with * in the dropdown.
Global Ignore
This option allows you to exclude globally from the application some of the image sizes that are registered through various plugins and themes options, that you perhaps do not need at all in your application (these are just stored in your folders and database but not actually used/visible on the front-end). By excluding these, the unnecessary image sizes will not be generated at all.
Image Size Quality
The quality option is allowing you to control the quality of the images that are generated for each of the image sizes, starting from the quality of the image you upload. This can be useful for performance. However, please be careful not to change the quality of the full image or the quality of the image size that you set as the forced original. Setting a lower quality is recommended for smaller image sizes, that are generated from the full/original file.
Hide Preview
This option allows you to hide from the “Image Regenerate & Select Crop Settings” lightbox the details and options for the selected image sizes (when you or other admins are checking the image details, the hidden image sizes will not be shown).
This is useful when you want to restrict from other users the functionality of crop or resize for particular image sizes, or to just hide the image sizes you added to global ignore.
Force Original
This option means that when uploading an image, the original image will be replaced completely by the image size you select (the image generated, scaled, or cropped to a specific width and height will become the full size for that image going further). This can be very useful if you do not use the original image in any of the layouts at the full size, and this might save some storage space.
Leave “nothing selected” to keep the full/original image as the file you upload (default WordPress behavior).
Default Crop
This option allows you to set a default crop position for the images generated for a particular image size. This option will be applied when you chose to regenerate an individual image or all of these, and also when a new image is uploaded
Cleanup
This option allows you to clean up all the images generated for a particular image size you already have in the application, and that you do not use or do not want to use anymore on the front-end.
Please be careful, once you click to remove the images for the selected image size, the action is irreversible, the images generated up this point will be deleted from your folders and database records. You can regenerate these later if you click the Regenerate button.
Regenerate
This option allows you to regenerate the images for the selected image size.
Please be careful, once you click the button to regenerate the selected image size, the action is irreversible, and the images already generated will be overwritten.
Advanced Custom Rules
NEW This new feature allows you to configure rules based on the post where the image will be uploaded. This becomes very useful when you have mixed content on your website, and for each type of content, you would need only some specific image sizes generated, as only these might be exposed on the front-end, hence, other image sizes generated for these would probably never get used.
The advanced custom rules you configure below are global and will override all the other settings you set above. Please be aware that the custom rules will apply only if you actually set up the post to use one of the rules below, and only then upload images to that post.
Very important: the order in which the rules are checked and have priority is: post ID, post type, post format, post parent, post tags, post categories, and other taxonomies. Any of the rules that match first in this order will apply to the images that are generated when you upload images to that post (and the rest of the rules will be ignored). You can suppress at any time any of the rules and then enable these back as it suits you.
The interface for custom rules setup will highlight the rules that are valid, as the rules for which you provided enough details in order for the upload script to use and perform the necessary adjustments to the final images.
In my example, I configured the upload to generate only thumbnails for my posts that have photos galleries (the first two rules, some of my posts are categorized and others have only the specified tags), as for that type of content I would only display the thumbnail and the original file, and no need to generate other image sizes.
With the third rule (which is targeting the posts I use to describe my plugins), I intend to generate the thumbnail, medium, and the hero-image, and at the same time override the file I initially upload with the hero-image that is generated from that (as the hero-image size would be smaller, and also, I would not display another image size for it in my theme).
Custom Rules Filter
NEW If you need rules even more customized than what the interface is providing, you can use the new filter sirsc_custom_upload_rule that allows developers to create programmatically more complex rules. The hook can be used in the theme or in a plugin.
// This is the Image Regenerate & Select Crop hook. Use with caution.
add_filter( 'sirsc_custom_upload_rule', 'my_custom_upload_rule', 99, 5 );
if ( ! function_exists( 'my_custom_upload_rule' ) ) {
/**
* Add here your custom rules and return the new settings.
* This hook is executed when you perform an upload.
*
* @param array $settings The plugin settings.
* @param integer $id The attachment ID.
* @param string $type The attachment post type.
* @param integer $parent_id The attachment parent ID.
* @param string $parent_type The attachment parent post type.
* @return array
*/
function my_custom_upload_rule( $settings, $id, $type, $parent_id = 0, $parent_type = '' ) {
// Add here your custom code, and then do not forget to return the settings.
return $settings;
}
}
Image Details & Options Lightbox
The details have been improved and include NEW the original filename and the link to the original file, and also NEW links for each of the image sizes generated.
The image sizes have been better defined with this version so these stand out more and the grouping of information is more intuitive.
WP-CLI New Commands & Flags
MOD When using the WP-CLI commands of the plugin you will see only the progress while the commands are running. If you need to see all the information, the images that are updated while running the commands, you can use the NEW –show-info flag (the flag can be used with all the currently available commands).
The command to regenerate all the thumbnails on site 1 and the result:
wp sirsc regenerate 1 all thumbnail
******* SIRSC EXECUTE OPERATION ON SITE 1 *******
------- EXECUTE REGENERATE FOR ALL IMAGES ASSOCIATED TO ALL TYPES -------
------- REGENERATE thumbnail 15 % [=============> ] 0:06 / 1:32
The command to regenerate all the thumbnails on site 1 + showing the info while executing
wp sirsc regenerate 1 all thumbnail --show-info
******* SIRSC EXECUTE OPERATION ON SITE 1 *******
------- EXECUTE REGENERATE FOR ALL IMAGES ASSOCIATED TO ALL TYPES -------
Success: https://site.demo/uploads/2015/10/banner-772x250-263x170.png
------- REGENERATE thumbnail 0 % [> ] 0:00 / 0:00
Success: https://site.demo/uploads/2015/11/banner-772x250-263x170.png
------- REGENERATE thumbnail 1 % [=> ] 0:01 / 1:01
Success: https://site.demo/uploads/2015/12/banner-772x250-263x170.png
------- REGENERATE thumbnail 2 % [==> ] 0:01 / 1:07
The cleanup command has a NEW flag called –force. This is useful when the image size you want to remove from the database and folders is no longer registered in your application (it was registered with a theme or plugin no longer used, or the image sizes names changed in your application over time).
In this case, the command like wp sirsc cleanup 1 all old-size would not remove anything, since the old-size must be a registered image size. To force the cleanup you would use the command
wp sirsc cleanup 1 all old-size --force
NEW With this version, a new command has been implemented that allows to delete all the images and keep only the original file. This is very useful when you start over, with another design or a new theme, and you need to remove and regenerate everything according to the most recent changes made to the images sizes. This new command is wp sirsc rawcleanup. Please use this command wisely, it is irreversible and the files are actually deleted from your folders.
The command to remove all and keep only the original file for site 1:
wp sirsc rawcleanup 1 all --show-info
More details about the commands and arguments are available here.
Other Features
- The plugin has been tested up to 4.9.8
- MOD The button for details has been renamed to
Image Details
so that both buttons fit in one line for most of the views. - MOD The general settings are saved when you change something (without the need to click the save button)
- MOD Styling updates for the settings page, the buttons, the image details lightbox, and the spinners
- NEW Plugin translations added
If you would like to support my work, consider making a donation, buy me a coffee, leave a 5 stars rating, or share this on your feed.
A huge thanks in advance!
You can download the free plugin from the WordPress repository.