CrabOptimize is built to be highly extensible. Below is a comprehensive list of available actions and filters you can use to customize the plugin's behavior, integrate it with other tools, or modify its core functionality.
Fires when the CrabOptimize plugin has fully loaded and initialized its classes.
add_action( 'dm_crab_optimize_loaded', function() {
// Your custom code here
} );Fires after the plugin's admin assets (scripts and styles) have been enqueued.
$hook(string): The current admin page hook suffix.
Fires after optimization metadata is saved for an attachment. Useful for triggering third-party cache clearing or logging.
$post_id(int): The attachment ID.$mime_type(string): The mime type of the attachment.
Fires when an unoptimized image is successfully linked to its new optimized counterpart during migration.
$original_id(int): The original attachment ID.$optimized_id(int): The optimized attachment ID.$format(string): The optimization format (e.g., 'avif', 'webp').
Fires after all CrabOptimize settings have been registered with WordPress.
Fires at the bottom of the settings form table, allowing you to inject custom settings rows.
add_action( 'dm_crab_optimize_settings_form_bottom', function() {
echo '<tr valign="top"><th scope="row">Custom Setting</th><td>...</td></tr>';
} );Filters the localized settings array passed to the frontend JavaScript (window.dmCrabSettingsMain).
$settings(array): The settings array.
Filters the title of the "Crab Optimized" column in the Media Library.
$title(string): The column title.
Filters the metadata exposed to the WordPress JS Media models.
$response(array): Array of prepared attachment data.$attachment(WP_Post): The attachment object.
Filters the image sizes to be generated for an attachment. By default, CrabOptimize disables thumbnail generation for AVIF/WebP if configured to do so.
$sizes(array): Array of image sizes that would be generated.$metadata(array): Attachment metadata array.$attachment_id(int): Attachment post ID.
Filters the WP_Query arguments used to discover unoptimized images during the bulk migration process.
$query_args(array): The query arguments.
Filters the WP_Query arguments used to find posts for content replacement during migration.
$query_args(array): The query arguments.
Filters the allowed image formats for optimization in the settings.
$allowed_formats(array): Array of allowed formats (default:['avif', 'webp']).
Filters the post types that are scanned and updated during the content replacement phase of migration.
$post_types(array): Array of post types (default:['post', 'page']).
Filters the regex rules used for replacing old image IDs and URLs with optimized ones in post content.
$rules(array): Array of replacement rules containingpatternandcallback.$optimization_map(array): Associative array mapping old attachment IDs to new optimized attachment IDs.