Skip to content

Fix: Video Block Preview in WP Bakery - #2130

Merged
rudrakshi-gupta merged 2 commits into
developfrom
fix/video-block-preview
Sep 21, 2026
Merged

rudrakshi-gupta merged 2 commits into
developfrom
fix/video-block-preview

Conversation

@rudrakshi-gupta

Copy link
Copy Markdown
Member

Issue

Fixes #1590

Root Cause

The godam_video shortcode renders a static poster placeholder plus a hidden video that video.js turns into the real player once godam-player-frontend-script runs. WPBakery's inline editor injects a freshly-added element via AJAX but never injects the newly-enqueued script into the running preview — so on a page that had no player before, the script was absent and the video stayed frozen on its poster (or the loading placeholder with no poster). A full reload re-rendered the shortcode in content with the script present, which is why the live player only appeared after refresh.

Fix

Added preload_wpbakery_editor_assets() to class-godam-player.php, hooked on wp_enqueue_scripts (priority 20) and guarded by vc_is_inline(). It enqueues the player script, styles, and active skin up front in the inline editor. The JS side already watches for builder-injected markup (isBuilderPreview() + MutationObserver → initializePendingVideos()), so now a just-added video initializes right away. This mirrors the existing GoDAM Image element's fix for the same WPBakery quirk. Editor-only — the published front end is untouched.

Demo

Before

Screen.Recording.2026-09-17.at.11.46.00.AM.mov

After

after.mov

@rudrakshi-gupta rudrakshi-gupta self-assigned this Sep 17, 2026
Copilot AI balanced review requested due to automatic review settings September 17, 2026 06:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Resolve the analytics tracking concern and clarify or implement the audio autoplay scope.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Fixes WPBakery inline-editor video previews by preloading GoDAM player assets.

Changes:

  • Adds an inline-editor asset preload hook.
  • Enqueues player scripts, styles, and the selected skin.
File summaries
File Summary Findings
inc/classes/shortcodes/class-godam-player.php Adds WPBakery editor asset preloading. Moderate: Avoid preloading analytics in builder previews or add an opt-out. Nit: Address the linked issue’s audio autoplay requirement or narrow the issue scope.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 2
  • Review effort level: Lite (auto)

Note

Copilot is running an experiment and ran this review at Lite.


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@github-actions

github-actions Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

🔍 WordPress Plugin Check Report

⚠️ Status: Passed with warnings

📊 Report

🎯 Total Issues ❌ Errors ⚠️ Warnings
16 0 16

⚠️ Warnings (16)

📁 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/blocks/godam-gallery-v2/render.php (2 warnings)
📍 Line 🔖 Check 💬 Message
15 WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound Global variables defined by a theme/plugin should start with the theme/plugin prefix. Found: "$inner_block_video_ids".
23 WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound Global variables defined by a theme/plugin should start with the theme/plugin prefix. Found: "$inner_block_video_ids".
📁 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/09/17/demo-post-post/ (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-page-post/ (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/09/17/demo-post-post/ (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-page-post/ (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

@KMchaudhary

Copy link
Copy Markdown
Collaborator

Code review — correctness + cleanup (medium effort)

Editor-only, additive change; mechanism is sound. Two things worth addressing before merge.


1. godam-player-analytics-script should not be preloaded in the editor — inc/classes/shortcodes/class-godam-player.php:321 · data integrity

preload_wpbakery_editor_assets() enqueues the analytics script in the inline editor. Once frontend.js initializes the just-added player, the analytics plugin attaches and starts tracking. The only guard, shouldSkipAnalytics(), gates on:

  • isAdminPage → is_admin(), which is false on the WPBakery frontend inline-editor page, and
  • ?godam_page=video-preview, which isn't set here.

So analytics is not skipped, and every preview play/scrub in the editor sends real view/engagement events to the SaaS endpoint — corrupting the video's stats. Before this PR the player never initialized in the editor, so nothing fired; the fix reintroduces the player and wires up tracking with it.

Note the GoDAM Image element's preload_wpbakery_editor_assets() deliberately loads only its layers script + styles, not any tracking script. Suggest dropping godam-player-analytics-script from the preload (or, if editor analytics is genuinely wanted, having shouldSkipAnalytics() also return true under vc_is_inline()).


2. Skin lookup is copy-pasted from render() — inc/classes/shortcodes/class-godam-player.php:326-334 · reuse

The settings read + $skins map + isset() enqueue is duplicated verbatim from render() (lines 451-462). The skin list now lives in two places — add/rename/remove a skin and you must edit both, or the editor preview silently diverges from the front end. Worth extracting a small private helper (e.g. enqueue_active_skin_style()) and calling it from both.


🤖 Generated with Claude Code

@rudrakshi-gupta
rudrakshi-gupta merged commit f769066 into develop Sep 21, 2026
6 checks passed
@rudrakshi-gupta
rudrakshi-gupta deleted the fix/video-block-preview branch September 21, 2026 07:17
OpuRockey pushed a commit to OpuRockey/godam that referenced this pull request Nov 1, 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.

3 participants