Skip to content

Implement Manage Versions feature in media library#1815

Draft
shreyasikhar wants to merge 10 commits into
developfrom
feat/media-versions
Draft

Implement Manage Versions feature in media library#1815
shreyasikhar wants to merge 10 commits into
developfrom
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
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 15, 2026

🔍 WordPress Plugin Check Report

⚠️ Status: Passed with warnings

📊 Report

🎯 Total Issues ❌ Errors ⚠️ Warnings
14 0 14

⚠️ Warnings (14)

📁 composer.json (1 warning)
📍 Line 🔖 Check 💬 Message
0 missing_composer_json_file The "/vendor" directory using composer exists, but "composer.json" file is missing.
📁 readme.txt (2 warnings)
📍 Line 🔖 Check 💬 Message
0 mismatched_plugin_name Plugin name "GoDAM - Organize WordPress Media Library & File Manager with Unlimited Folders for Images, Videos & more" is different from the name declared in plugin header "GoDAM".
0 trademarked_term The plugin name includes a restricted term. Your chosen plugin name - "GoDAM - Organize WordPress Media Library & File Manager with Unlimited Folders for Images, Videos & more" - contains the restricted term "wordpress" which cannot be used at all in your plugin name.
📁 assets/build/css/main.css (1 warning)
📍 Line 🔖 Check 💬 Message
0 EnqueuedStylesScope This style is being loaded in all contexts.
📁 assets/src/libs/analytics.min.js (5 warnings)
📍 Line 🔖 Check 💬 Message
0 EnqueuedScriptsScope This script is being loaded in all frontend contexts.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880 (with handle analytics-library) is loaded in the footer. Consider a defer or async script loading strategy instead.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880/2026/05/20/hello-world/ (with handle analytics-library) is loaded in the footer. Consider a defer or async script loading strategy instead.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880/sample-page/ (with handle analytics-library) is loaded in the footer. Consider a defer or async script loading strategy instead.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880/demo-attachment-post/ (with handle analytics-library) is loaded in the footer. Consider a defer or async script loading strategy instead.
📁 assets/build/js/main.min.js (5 warnings)
📍 Line 🔖 Check 💬 Message
0 EnqueuedScriptsScope This script is being loaded in all frontend contexts.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880 (with handle rtgodam-script) is loaded in the footer. Consider a defer or async script loading strategy instead.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880/2026/05/20/hello-world/ (with handle rtgodam-script) is loaded in the footer. Consider a defer or async script loading strategy instead.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880/sample-page/ (with handle rtgodam-script) is loaded in the footer. Consider a defer or async script loading strategy instead.
0 NonBlockingScripts.NoStrategy This script on http://localhost:8880/demo-attachment-post/ (with handle rtgodam-script) is loaded in the footer. Consider a defer or async script loading strategy instead.

🤖 Generated by WordPress Plugin Check Action • Learn more about Plugin Check

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