• Resolved aparmar115

    (@aparmar115)


    REQUEST: Can you add an option under “General settings” > “Retention policy” ?

    HIGH LEVEL DESCRIPTION : I will appreciate an option for “Full cloud migration with Cron Job”. This is to allow for a delayed offloading to cloud instead of immediate.

    DETAILS OF REQUEST

    • I have a use case and custom plugin where users upload files into a form to create a post
    • After installing AMO this plugin is not working any more due to the fact the AMO changes the URL of the file in media library
    • However, if you allow the option to offload file at a specific time of day then this issue will not happen

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Plugin Author Masoud Golchin

    (@masoudin)

    Hi @aparmar115

    You can use advmo_should_offload_attachment filter to apply a delay to offloading your media files to cloud storage. For example the following code prevents offloading media files that are uploaded less than 5 minutes ago: (It means do not offload newly uploaded files)

    /**
    * Prevent offloading of newly uploaded attachments (younger than 5 minutes).
    * @param bool $should_offload Current decision.
    * @param int $attachment_id Attachment ID.
    * @param array|null $metadata Attachment metadata when available.
    * @return bool False to skip offloading.
    */
    function wpfitter_prevent_recent_offload($should_offload, $attachment_id, $metadata = null)
    {
    try {
    $post = get_post($attachment_id);
    if (!$post) {
    return $should_offload;
    }

    // Compare upload time (GMT) against now (GMT)
    $created_gmt = get_post_time('U', true, $post);
    $now_gmt = current_time('timestamp', true);

    if (is_numeric($created_gmt) && ($now_gmt - (int) $created_gmt) < (5 * MINUTE_IN_SECONDS)) {
    return false; // Skip offloading if younger than 5 minutes
    }

    return $should_offload;
    } catch (\Throwable $e) {
    // Fail open to avoid interrupting uploads/offload flow
    return $should_offload;
    }
    }

    add_filter('advmo_should_offload_attachment', 'wpfitter_prevent_recent_offload', 10, 3);

    And then you can add the following command to your server cronjob to run every 30 minutes and offload the non-offloaded files:

    */30 * * * * cd /path/to/public_html && wp advmo offload

    I hope this solution works for you.

Viewing 1 replies (of 1 total)

You must be logged in to reply to this topic.