Skip to content

Instantly share code, notes, and snippets.

@hjanuschka
Created February 12, 2026 07:55
Show Gist options
  • Select an option

  • Save hjanuschka/4f3b692f2043af4e2917572048e5fc96 to your computer and use it in GitHub Desktop.

Select an option

Save hjanuschka/4f3b692f2043af4e2917572048e5fc96 to your computer and use it in GitHub Desktop.
Fix Joomla 3.x compatibility for captcha.eu plugin - adds fallback for getWebAssetManager()
diff --git a/captcha_eu.php b/captcha_eu.php
index e73a26a..72e549d 100644
--- a/captcha_eu.php
+++ b/captcha_eu.php
@@ -88,10 +88,16 @@ class PlgCaptchacaptcha_eu extends CMSPlugin
$sdkSrc = 'https://www.captcha.eu/sdk.js';
- // Load assets, the callback should be first
- $this->app->getDocument()->getWebAssetManager()
- ->registerAndUseScript('plg_captcha_eu_sdk_src', $sdkSrc, [], ['defer' => true]);
-
+ // Load assets - use WebAssetManager for Joomla 4+, fallback to addScript for Joomla 3.x
+ $document = $this->app->getDocument();
+ if (method_exists($document, 'getWebAssetManager')) {
+ // Joomla 4.x+
+ $document->getWebAssetManager()
+ ->registerAndUseScript('plg_captcha_eu_sdk_src', $sdkSrc, [], ['defer' => true]);
+ } else {
+ // Joomla 3.x
+ $document->addScript($sdkSrc, ['version' => 'auto'], ['defer' => true]);
+ }
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment