Filter Hooks

This document lists all available filter hooks in Advanced Media Offloader. Filter hooks allow you to modify data or control plugin behavior.

Offload Control Filters

advmo_should_offload_attachment

Filter to determine whether an attachment should be offloaded to cloud storage.

Parameters:

  • $should_offload (bool) – Default true
  • $attachment_id (int) – The attachment ID
  • $metadata (array, optional) – Attachment metadata (only passed during updates)

Return: (bool) Return false to skip offloading this attachment

Example:

// Skip offloading files larger than 5MB
add_filter('advmo_should_offload_attachment', function($should_offload, $attachment_id, $metadata = null) {
    $file = get_attached_file($attachment_id);
    if ($file && filesize($file) > 5 * 1024 * 1024) {
        return false;
    }
    return $should_offload;
}, 10, 3);

Example:

// Skip offloading specific post types
add_filter('advmo_should_offload_attachment', function($should_offload, $attachment_id) {
    $post = get_post($attachment_id);
    if ($post && $post->post_parent) {
        $parent_post_type = get_post_type($post->post_parent);
        if ($parent_post_type === 'product') {
            return false; // Don't offload product images
        }
    }
    return $should_offload;
}, 10, 2);

advmo_should_upload_original_image

Filter to determine whether the original image should be uploaded to cloud storage.

Parameters:

  • $should_upload_original_image (bool) – Default true
  • $attachment_id (int) – The attachment ID
  • $metadata (array) – Attachment metadata

Return: (bool) Return false to skip uploading the original image

Example:

// Only upload original images for specific image sizes
add_filter('advmo_should_upload_original_image', function($should_upload, $attachment_id, $metadata) {
    // Only upload original if image is larger than 2000px
    if (isset($metadata['width']) && $metadata['width'] < 2000) {
        return false;
    }
    return $should_upload;
}, 10, 3);

File Handling Filters

advmo_temp_fetch_mime_types

Filter the supported MIME types for temporary file fetching when local files are missing.

Parameters:

  • $supported_mime_types (array) – Array of supported MIME types (default: ['image/svg+xml'])
  • $attachment_id (int) – The attachment ID

Return: (array) Array of supported MIME types

Example:

// Add PDF files to temporary fetch list
add_filter('advmo_temp_fetch_mime_types', function($types, $attachment_id) {
    $types[] = 'application/pdf';
    return $types;
}, 10, 2);

Cloud Provider Filters

advmo_cloud_providers

Filter the list of available cloud providers.

Parameters:

  • $cloud_providers (array) – Array of cloud provider configurations

Return: (array) Filtered array of cloud providers

Example:

// Add custom cloud provider
add_filter('advmo_cloud_providers', function($providers) {
    $providers['custom_provider'] = [
        'name' => 'Custom Provider',
        'class' => 'Custom_Provider_Class',
    ];
    return $providers;
});

Domain Filters

advmo_aws_domain

Filter the custom domain URL for Amazon S3.

Parameters:

  • $domain (string) – The domain URL

Return: (string) The filtered domain URL

Example:

// Force HTTPS for AWS domain
add_filter('advmo_aws_domain', function($domain) {
    return str_replace('http://', 'https://', $domain);
});

advmo_cloudflare_r2_domain

Filter the custom domain URL for Cloudflare R2.

Parameters:

  • $domain (string) – The domain URL

Return: (string) The filtered domain URL

Example:

add_filter('advmo_cloudflare_r2_domain', function($domain) {
    // Modify domain as needed
    return $domain;
});

advmo_backblaze_b2_domain

Filter the custom domain URL for Backblaze B2.

Parameters:

  • $domain (string) – The domain URL

Return: (string) The filtered domain URL

Example:

add_filter('advmo_backblaze_b2_domain', function($domain) {
    // Modify domain as needed
    return $domain;
});

advmo_dos_domain

Filter the custom domain URL for DigitalOcean Spaces.

Parameters:

  • $domain (string) – The domain URL

Return: (string) The filtered domain URL

Example:

add_filter('advmo_dos_domain', function($domain) {
    // Modify domain as needed
    return $domain;
});

advmo_minio_domain

Filter the custom domain URL for MinIO.

Parameters:

  • $domain (string) – The domain URL

Return: (string) The filtered domain URL

Example:

add_filter('advmo_minio_domain', function($domain) {
    // Modify domain as needed
    return $domain;
});

advmo_wasabi_domain

Filter the custom domain URL for Wasabi.

Parameters:

  • $domain (string) – The domain URL

Return: (string) The filtered domain URL

Example:

add_filter('advmo_wasabi_domain', function($domain) {
    // Modify domain as needed
    return $domain;
});

Need More Help?

Can't find what you're looking for? We're here to help!

Contact Support