JavaScript global namespace pollution
-
This plugin interferes with WP PDF Embedder in the Gutenberg editor and causes that plugin to show “Your site doesn’t include support for the PDF Embedder block”.
I identified the cause to be a JavaScript variable defined on the first line of
assets/js/block-notice.js
, while the other plugin also definesvar __ = wp.i18n.__
. Since both plugins define this variable only for internal use, putting the definition at JS file level causes a global namespace pollution.One possible solution is to wrap the whole script inside a self-executing function, or better yet, since it’s only used once, remove the variable definition and use the full namespaced path (i.e.
wp.i18n.__(...)
).I have already contacted the developers of the other plugin, but it would certainly be nice if this can be fixed on both sides. Namespace pollution is known as a bad practice and makes plugins susceptible to conflicts.
- The topic ‘JavaScript global namespace pollution’ is closed to new replies.