WordPress image optimisation plugin — compression, next-gen formats (WebP / AVIF), and multi-context management.
Version 2.2.8 · PHP 7.3+ · WordPress 5.3+Source code organisation, service loading, and plugin lifecycle.
The plugin starts from imagify.php. It defines global constants, includes the Composer autoloader, then hooks the imagify_init() function on plugins_loaded.
IMAGIFY_VERSION — plugin versionIMAGIFY_PATH / IMAGIFY_URLIMAGIFY_MAX_BYTES — 5 MB limit per imageIMAGIFY_APP_API_URL — remote API URLIMAGIFY_API_KEY — override via PHP constantvendor/autoload.php)config/providers.phpImagify\Plugindo_action('imagify_loaded')// 1. plugins_loaded imagify_init() └── include vendor/autoload.php └── new Imagify\Plugin() └── load config/providers.php // register services └── boot Options, Data, Auth └── boot Auto-Optimization └── (admin only) boot Settings, Views, Imagifybeat └── do_action('imagify_loaded')
On-the-fly or bulk compression, quality levels, backup management, and resizing.
| Level | Name | Description |
|---|---|---|
0 | Normal | Light compression, maximum quality preserved. |
1 | Aggressive | Stronger compression, good quality/size trade-off. |
2 | Ultra (default) | Maximum compression — recommended for most use cases. |
Imagify\Optimization\File class, which communicates with the remote Imagify API.
When the auto_optimize option is enabled, the Imagify_Auto_Optimization class hooks into wp_generate_attachment_metadata. Each uploaded image is optimised immediately, along with all its thumbnails.
backup option.imagify_backup_directory.resize_larger: when enabled, images exceeding resize_larger_w pixels wide are resized.big_image_size_threshold).All sizes registered in WordPress are optimised. Sizes can be excluded via the disallowed-sizes blacklist in the settings.
// Attachment post meta _imagify_status // 'success' | 'already_optimized' | 'error' | 'pending' _imagify_data // JSON — full optimisation results _imagify_level // Level used (0, 1, 2) _imagify_next_gen_done // Boolean — next-gen versions generated
Generation and delivery of modern formats to reduce image weight on the browser side.
After optimisation, Imagify can generate WebP and/or AVIF versions of each image. The optimization_format option controls this behaviour:
| Value | Behaviour |
|---|---|
'off' | No next-gen format. |
'webp' | Generates WebP only. |
'avif' | Generates WebP + AVIF (AVIF takes priority if supported). |
Class: Imagify\Picture\Display. The plugin starts an output buffer on template_redirect, scans the generated HTML, and replaces each <img> with a <picture> block containing <source> elements pointing to the WebP/AVIF files.
<!-- Before --> <img src="photo.jpg" alt="..."> <!-- After transformation --> <picture> <source srcset="photo.avif" type="image/avif"> <source srcset="photo.webp" type="image/webp"> <img src="photo.jpg" alt="..."> </picture>
Class: Imagify\Webp\Display. Rather than altering the HTML, rules are written directly into .htaccess (Apache) or web.config (IIS). The server automatically serves WebP if the browser accepts it (Accept: image/webp).
The data-lazy-src, data-src, data-srcset, data-lazy-srcset attributes are detected and propagated into the generated <source> and <img> tags.
An image with the CSS class imagify-no-webp is ignored by the <picture> transformation.
All options stored in imagify_settings (wp_options / wp_sitemeta on multisite).
| Key | Type | Default | Description |
|---|---|---|---|
api_key | string | '' | Imagify API key (or the IMAGIFY_API_KEY constant). |
optimization_level | int | 2 | Compression level (0, 1, 2). |
lossless | bool | 0 | Lossless compression. |
auto_optimize | bool | 1 | Automatic optimisation on upload. |
backup | bool | 1 | Back up the original before compression. |
resize_larger | bool | 0 | Resize images that are too large. |
resize_larger_w | int | 0 | Maximum width in pixels. |
optimization_format | string | 'webp' | 'off', 'webp', or 'avif'. |
display_nextgen_method | string | 'picture' | 'picture' or 'rewrite'. |
cdn_url | string | '' | CDN URL for serving media. |
disallowed-sizes | array | [] | Thumbnail sizes excluded from optimisation. |
admin_bar_menu | bool | 1 | Show Imagify in the admin bar. |
Imagify_Settings class handles option registration (register_setting()) and validation. It is network-aware: on multisite, network options are stored in wp_sitemeta.
Batch processing of all existing images, with an asynchronous queue.
The Imagify\Bulk\Bulk class orchestrates bulk optimisation. It relies on ActionScheduler (bundled library) to create asynchronous jobs processed in the background.
Class: Imagify\Bulk\WP
Optimises all attachments in the WordPress media library that have not yet been optimised.
Class: Imagify\Bulk\CustomFolders
Optimises files indexed in the custom folders.
Class: Imagify\Bulk\NGG
Optimises images from NextGEN Gallery galleries.
// Trigger (UI or CLI) imagify_bulk_optimize (AJAX) // or wp imagify bulk-optimize └── Imagify\Bulk\Bulk::run() └── ActionScheduler::enqueue(imagify_optimize_media) └── Imagify\Job\MediaOptimization::execute() └── Imagify\Optimization\File::optimize() └── Remote Imagify API
The AJAX action imagify_missing_nextgen_generation and the ActionScheduler hook imagify_convert_next_gen allow generating WebP/AVIF versions for all already-optimised images whose next-gen files are missing.
Columns, actions, and buttons directly within the WordPress media interface.
?imagify-status=....admin_bar_menu option.
Optimisation of image files located outside the WordPress media library.
Custom folders allow optimising images located anywhere on the server (themes, plugins, custom directories). They are indexed in two dedicated MySQL tables.
imagify_foldersimagify_files// Database access Imagify_Files_DB // CRUD on wp_imagify_files Imagify_Folders_DB // CRUD on wp_imagify_folders Imagify_Files_Scan // Filesystem scan // Context Imagify\Context\CustomFolders
All server entry points used by the administration interface.
wp_ajax_* (authenticated) or admin_post_*. A custom "Imagifybeat" system handles real-time updates.
wp_ajax_*)imagify_signupimagify_check_api_key_validityimagify_get_user_dataimagify_delete_user_data_cacheimagify_get_pricesimagify_check_couponimagify_bulk_optimizeimagify_missing_nextgen_generationimagify_bulk_get_statsimagify_get_folder_type_dataimagify_bulk_info_seenimagify_get_images_countsimagify_check_backup_dir_is_writableimagify_get_files_treeimagify_update_estimate_sizesimagify_reset_internal_stateimagify_rpc (Imagifybeat)admin_post_*)imagify_manual_optimizeimagify_manual_reoptimizeimagify_optimize_missing_sizesimagify_generate_nextgen_versionsimagify_delete_nextgen_versionsimagify_restoreimagify_optimize_fileimagify_reoptimize_fileimagify_restore_fileimagify_refresh_file_modifiedimagify_scan_custom_foldersReal-time update system (analogous to WordPress Heartbeat). Hook: wp_ajax_imagifybeat. Interface data (nonces, statuses) is refreshed periodically via AJAX polling, configurable by filter.
Command-line interface for automating optimisation operations.
wp imagify bulk-optimizeLaunches bulk optimisation for one or more contexts (wp, custom-folders).
--optimization-levelwp imagify restoreRestores original images for the specified contexts (library, custom-folders).
wp imagify generate-missing-nextgenGenerates missing WebP/AVIF versions for all already-optimised images.
Full support for the NextGEN Gallery (NGG) plugin.
The plugin automatically detects NextGEN Gallery and activates a dedicated context (Imagify\Context\NGG).
imagify_ngg_has_pope_storage())Compatibility with other plugins and WordPress hosts.
On variable product pages, WooCommerce dynamically replaces the main image. Imagify fixes the wp-post-image class on generated <picture> tags to maintain compatibility with WooCommerce's image-switching mechanism.
Recurring jobs for maintenance and statistics.
| Task | WP Cron hook | Frequency | Role |
|---|---|---|---|
Imagify_Cron_Rating |
imagify_rating_event |
Daily (3:00 PM) | Triggers the plugin rating request. |
Imagify_Cron_Library_Size |
— | Periodic | Recalculates media library statistics. |
Imagify_Cron_Sync_Files |
— | Periodic | Synchronises files in custom folders. |
The ActionScheduler library is bundled in /inc/Dependencies/ActionScheduler/. It manages asynchronous optimisation jobs:
imagify_optimize_media — Processes a single optimisation job.imagify_convert_next_gen — Generates next-gen versions.All jobs are cleaned up when the plugin is deactivated.
Extension points for customising the plugin's behaviour.
| Hook | When |
|---|---|
imagify_loaded | Plugin fully loaded and ready. |
imagify_activation | On plugin activation. |
imagify_deactivation | On plugin deactivation. |
imagify_optimize_media | ActionScheduler optimisation job. |
imagify_convert_next_gen | Next-gen generation job. |
imagify_delete_media | Deletion of a media item. |
imagify_settings_on_save | After settings are saved. |
imagify_not_over_quota_anymore | Quota dropped back below 100%. |
| Filter | Usage |
|---|---|
imagify_backup_directory | Change the backup folder. |
imagify_register_context | Register a custom optimisation context. |
imagify_picture_attributes | Modify attributes of the <picture> tag. |
imagify_picture_source_attributes | Modify attributes of <source> tags. |
imagify_picture_img_attributes | Modify attributes of the inner <img>. |
imagify_allow_picture_tags_for_nextgen | Disable the <picture> transformation. |
imagify_buffer | Filter the final HTML page buffer. |
imagify_cdn_source_url | Override the CDN URL. |
imagify_event_recurrence | Change the frequency of Imagify cron jobs. |
imagify_event_time | Change the trigger time for cron jobs. |
imagify_bulk_stats | Modify bulk statistics data. |
imagify_unoptimized_attachment_limit | Limit query results. |
Subscription plans, quota consumption, and user data cache.
plan_id = 1
Limited monthly quota. Blocked at 100% consumption (is_over_quota()).
plan_id = 16 / 18
Larger monthly quota, additional byte packs available.
plan_id = 15 / 17
Unlimited quota — no quota blocking.
Imagify\User\Userquota // Total monthly quota (MB) consumed_current_month_quota // Quota consumed this month (MB) extra_quota // Imagify byte pack (MB) extra_quota_consumed // Pack consumed (MB) next_date_update // Quota reset date is_active // Account active
User data is cached in a WordPress transient (imagify_user_cache) for 5 minutes. The cache can be manually cleared via the AJAX action imagify_delete_user_data_cache.
WordPress capabilities required for each Imagify action.
| Action | Required WP capability | Context |
|---|---|---|
manage — Access settings | manage_options | All |
optimize — Optimize a media item | upload_files | All |
bulk-optimize — Launch a bulk run | manage_options | All |
Imagify\Context\AbstractContext::get_capacity() and can be overridden via the standard WordPress filter option_page_capability_imagify.
Built-in tools to resolve common issues without technical intervention.
AJAX action: imagify_reset_internal_state (requires the manage capability). This one-click tool unblocks the bulk optimiser when it gets stuck in an inconsistent state.
imagify_custom-folders_optimize_runningimagify_wp_optimize_runningimagify_bulk_optimization_completeimagify_bulk_optimization_resultimagify_missing_next_gen_totalimagify_bulk_optimization_infos_transient_%imagify-auto-optimize-%)_transient_%imagify_rpc_%)_transient_imagify_%_process_locked)imagify_optimize_mediaimagify_convert_next_genImagify\Tools\InternalStateList class is the single source of truth for all these items — it is also used by uninstall.php for a full cleanup on uninstallation.