Skip to content

Instantly share code, notes, and snippets.

@tangrufus
Last active August 8, 2019 10:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tangrufus/904cbfc6c9766d64b06a71dbad02856b to your computer and use it in GitHub Desktop.
Save tangrufus/904cbfc6c9766d64b06a71dbad02856b to your computer and use it in GitHub Desktop.
wp offload media + download monitor s3
<?php
     
function is_download_monitor_attachment(int $id): bool
{
    $parentPostId = wp_get_post_parent_id($id);

    return is_int($parentPostId) && 'dlm_download' === get_post_type($parentPostId);
}

add_filter('as3cf_pre_upload_attachment', function (bool $pre, int $postId): bool {
    if (is_download_monitor_attachment($postId)) {
        $message = __('Refuse to offload Download Monitor files', 'disallow-offloading-download-monitor-files');
        throw new RuntimeException($message);
    }

    return $pre;
}, -1000, 3);

add_filter('as3cf_upload_acl', function (string $acl, array $data, int $postId): string {
    return is_download_monitor_attachment($postId) ? 'private' : $acl;
}, 10, 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment