From 1ce9f8121b19ca35000bbd4a24d7c3632b680110 Mon Sep 17 00:00:00 2001 From: s4luorth Date: Mon, 8 Jun 2026 12:58:28 +0200 Subject: [PATCH] fix: leerer elementor-video-platzhalter wenn URL nicht auslesbar (v1.4.1) Wenn ein Elementor-video per JS gebaut wird und im DOM weder URL noch Thumbnail steht (nur {"video_type":"youtube"}), konnte mein handler keinen platzhalter bauen -> Elementor baut nichts (API blockiert) -> leere box. Fallback: dienst ueber den video_type erkennen und trotzdem einen einwilligungs-platzhalter zeigen. Da keine embed-URL bekannt ist, gibt dessen button die einwilligung und laedt die seite neu - danach rendert Elementor das video normal (scripts sind dann freigegeben). "Einmal laden" entfaellt dort. + version 1.4.1 (assets cache-busting fuer die JS-aenderung). Co-Authored-By: Claude Opus 4.8 --- gdpr-content-blocker/assets/frontend.js | 38 ++++++++++++++++--- gdpr-content-blocker/gdpr-content-blocker.php | 4 +- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/gdpr-content-blocker/assets/frontend.js b/gdpr-content-blocker/assets/frontend.js index adfec5d..9d33272 100644 --- a/gdpr-content-blocker/assets/frontend.js +++ b/gdpr-content-blocker/assets/frontend.js @@ -93,6 +93,15 @@ const wrapper = btn.closest( '.cb-blocker' ); + // Placeholder without its own embed URL (e.g. an Elementor widget we + // couldn't read the URL from): persist consent and reload so the + // original embed renders normally. + if ( wrapper && wrapper.getAttribute( 'data-cb-reload' ) === '1' ) { + grantConsent( serviceId ); + window.location.reload(); + return; + } + // "Remember" checkbox (default checked): persist consent only when // ticked; otherwise load this embed once without storing consent. const remember = wrapper @@ -315,19 +324,38 @@ // catching a rendered iframe) → leave it. if ( container.querySelector( '.cb-blocker' ) ) return; - const raw = videoUrlForWidget( widget ); - if ( ! raw ) return; + const raw = videoUrlForWidget( widget ); + const embed = raw ? toEmbedUrl( raw ) : ''; + let svc = raw ? ( findService( raw ) || findService( embed ) ) : null; - const embed = toEmbedUrl( raw ); - const svc = findService( raw ) || findService( embed ); + // Fallback: no URL in the DOM (Elementor only kept {"video_type":"…"}). + // Identify the service by the video type so we can still show consent. + if ( ! svc ) { + const vt = ( widget.getAttribute( 'data-settings' ) || '' ) + .match( /"video_type"\s*:\s*"(youtube|vimeo|dailymotion)"/i ); + if ( vt ) { + svc = findService( vt[ 1 ] + '.com' ); + } + } if ( ! svc ) return; if ( hasConsent( svc.id ) ) return; // consented → let Elementor build it // Neutralise Elementor so it won't build the player / load the overlay. widget.removeAttribute( 'data-settings' ); + const placeholder = buildPlaceholder( svc, embed, {} ); + + // No embed URL → we can't build the iframe ourselves. Make the button + // grant consent and reload; Elementor then renders the video normally + // (scripts are released after consent). Drop the "load once" option. + if ( ! embed ) { + placeholder.setAttribute( 'data-cb-reload', '1' ); + const remember = placeholder.querySelector( '.cb-blocker__remember' ); + if ( remember ) remember.remove(); + } + container.innerHTML = ''; - container.appendChild( buildPlaceholder( svc, embed, {} ) ); + container.appendChild( placeholder ); } ); } diff --git a/gdpr-content-blocker/gdpr-content-blocker.php b/gdpr-content-blocker/gdpr-content-blocker.php index bd3277d..b96b392 100644 --- a/gdpr-content-blocker/gdpr-content-blocker.php +++ b/gdpr-content-blocker/gdpr-content-blocker.php @@ -3,7 +3,7 @@ * Plugin Name: GDPR Content Blocker * Plugin URI: https://lucas-orth.de * Description: DSGVO-konformer Consent-Blocker für externe iframes. Lädt Drittinhalte erst nach aktiver Einwilligung. - * Version: 1.4.0 + * Version: 1.4.1 * Author: Lucas Orth * Author URI: https://lucas-orth.de * Text Domain: gdpr-content-blocker @@ -15,7 +15,7 @@ defined( 'ABSPATH' ) || exit; -define( 'CB_VERSION', '1.4.0' ); +define( 'CB_VERSION', '1.4.1' ); define( 'CB_FILE', __FILE__ ); define( 'CB_DIR', plugin_dir_path( __FILE__ ) ); define( 'CB_URL', plugin_dir_url( __FILE__ ) );