Skip to content

Implement Manage Versions feature in media library#1815

Draft
shreyasikhar wants to merge 4 commits intodevelopfrom
feat/media-versions
Draft

Implement Manage Versions feature in media library#1815
shreyasikhar wants to merge 4 commits intodevelopfrom
feat/media-versions

Conversation

@shreyasikhar
Copy link
Copy Markdown
Member

@shreyasikhar shreyasikhar commented Apr 23, 2026

Summary

Adds a Manage Versions feature to the WordPress Media Library attachment details panel, enabling users to:

  • View all available versions for a media item
  • Set any version as the active version
  • Add a new version by selecting/uploading a file from the Media Library
  • Delete non-default versions

This includes the UI (modal + styles), client-side interactions (AJAX + polling), and server-side AJAX handlers to integrate with GoDAM’s versions APIs and update URLs/metadata across the site when a version changes.


What’s included

UI / UX

  • Adds a “Manage Versions” action button in attachment details (works for all media types).
  • Introduces a custom modal (template printed in admin_footer) with:
    • Versions list with Default/Active chips
    • “Set Active” action per version
    • Delete action for non-default versions
    • “Add New Version” button with max-version guard
  • Snackbar improvements:
    • Adds success and error variants
    • Prevents overlapping timeouts (clears previous timeout before showing a new message)

Client-side (Media Library)

  • Fetch versions via AJAX (godam_get_media_versions) and render modal using WP templates.
  • Add-version flow:
    • Opens WP media frame filtered to same attachment type
    • Calls replace endpoint to start version creation
    • Polls for new version (up to 24 attempts, 5s interval)
    • Finalizes pending replace and refreshes current attachment UI (URL field + download link + reselect current attachment)
  • Set-active flow:
    • Optimistic UI update while switching active version
    • Refreshes versions + attachment data on success

Server-side (AJAX + GoDAM API integration)

Adds AJAX endpoints:

  • godam_get_media_versions
  • godam_switch_active_version
  • godam_delete_version
  • godam_replace_media_version
  • godam_finalize_media_version_replace

Also adds:

  • Callback hook rtgodam_handle_callback_finished to finalize URL replacements when GoDAM finishes processing.
  • URL replacement across site content + attachment guid updates, plus post cache cleanup.
  • Updates relevant attachment meta (e.g., transcoded URLs, thumbnail, HLS/transcript where applicable) and refreshes rtgodam_image_sizes from selected source attachment when needed.

Files changed

  • assets/src/js/media-library/views/attachment-detail-two-column.js
  • assets/src/css/media-library.scss
  • inc/classes/class-assets.php
  • inc/classes/class-media-library-ajax.php

Testing notes

  1. Open WP Admin → Media Library → select an attachment.
  2. In attachment details, click Manage Versions.
  3. Verify:
    • Versions list loads and shows Default/Active states
    • Set Active updates the active version and refreshes the attachment URL + download link
    • Add New Version opens media frame, starts upload/replace, then updates the modal after processing
    • Delete works for versions >= 2 and updates the list
  4. Confirm snackbar messages show correct success/error styles.

Notes / Caveats

  • Polling is used to wait for GoDAM to register the newly created version before finalizing URL replacement.
  • Delete is restricted to non-default versions (Version 1 cannot be deleted).

- Introduced a new modal for managing media versions, including actions to set a version as active and delete versions.
- Implemented AJAX handlers for fetching media versions, switching active versions, and deleting versions.
- Enhanced the snackbar notification system to provide feedback on actions related to media versions.
- Updated the media library JavaScript to integrate the new Manage Versions feature and handle user interactions.
- Added a template for the Manage Versions modal in the admin footer.
@shreyasikhar shreyasikhar self-assigned this Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant