Try for free

Cloud Storage Filters and Actions

Filters

media-cloud/storage/after-upload

This filter allows for filtering of an attachment’s metadata after it has been uploaded to cloud storage.

add_filter('media-cloud/storage/after-upload', function($attachmentMeta, $attachmentId) {
    // do something here
    return $attachmentMeta;
}, 1000, 2);

media-cloud/storage/can-calculate-srcset

Determines if Media Cloud should calculate the srcset for an image.

add_filter('media-cloud/storage/can-calculate-srcset', function($canCalculateSrcSet) {
    return $canCalculateSrcSet;
});

media-cloud/storage/can-filter-content

Controls if Media Cloud should filter a post’s content.

add_filter('media-cloud/storage/can-filter-content', function($canFilterContent) {
    return $canFilterContent;
});

media-cloud/storage/ignore-metadata-update

This filter can be used to temporarily suspend Media Cloud’s processing of attachment metadata.

add_filter('media-cloud/storage/ignore-metadata-update', function($shouldIgnore, $attachmentId) {
    return $shouldIgnore;
}, 1000, 2);

media-cloud/storage/ignore-existing-s3-data

Forces Media Cloud to ignore an attachment’s existing cloud storage metadata when processing an attachment.

add_filter('media-cloud/storage/ignore-existing-s3-data', function($shouldIgnore, $attachmentId) {
    return $shouldIgnore;
}, 1000, 2);

media-cloud/storage/ignore-optimizers

Forces Media Cloud to ignore the fact that image optimizer plugins are installed and activated.

add_filter('media-cloud/storage/ignore-optimizers', function($shouldIgnore, $attachmentId) {
    return $shouldIgnore;
}, 1000, 2);

media-cloud/storage/process-file-name

Filters a given filename, removing any storage related parts from the path, eg the bucket name.

$filename = apply_filters('media-cloud/storage/process-file-name', $filename);

media-cloud/storage/should-handle-upload

Controls if Media Cloud should process a WordPress upload.

add_filter('media-cloud/storage/should-handle-upload', function($shouldHandle, $uploadData) {
    return $shouldHandle;
}, 1000, 2);

media-cloud/storage/should-override-attached-file

Media Cloud will typically intercept get_attached_file() and return the storage URL if that file is no longer present on the local filesystem. If the file is on the local filesystem, get_attached_file() will return the file path to it. This filter allows you to override this behavior.

add_filter('media-cloud/storage/should-override-attached-file', function($shouldOverride, $attachment_id) {
    return $shouldOverride;
}, 1000, 2);

media-cloud/storage/should-use-custom-prefix

Allows the use of custom prefixes on uploads to be overridden from whatever the setting currently is.

add_filter('media-cloud/storage/should-use-custom-prefix', function($shouldUseCustomPrefix) {
    return $shouldUseCustomPrefix;
});

media-cloud/storage/upload-master

Controls if the master/main image is uploaded to cloud storage.

add_filter('media-cloud/storage/upload-master', function($shouldUpload) {
    return $shouldUpload;
});

Actions

media-cloud/storage/register-drivers

Registers any additional or custom cloud storage drivers.

add_action('media-cloud/storage/register-drivers', function() {
    StorageManager::registerDriver('my-storage-driver-key', 'My Storage Driver', MyNamespace\MyStorageDriver::class, [], []);
});

media-cloud/storage/uploaded-attachment

This is fired once an upload has been added.

add_action('media-cloud/storage/uploaded-attachment', function($attachmentId, $fileName, $uploadData) {
    // Do something
}, 1000, 3);

media-cloud/storage/migration/complete

This is fired once a migration to the cloud has completed.

add_action('media-cloud/storage/migration/complete', function() {
    // Do something
});

media-cloud/storage/import/complete

This is fired once a import from the cloud has completed.

add_action('media-cloud/storage/import/complete', function() {
    // Do something
});