Explicitly globalize $DISQUSVERSION variable #139
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Explicitly assigns
DISQUSVERSION
to$GLOBALS
rather than relying on the plugin file being loaded in global scope.Motivation and Context
By default, WordPress core loads active plugins in global scope. However, at our agency, we typically load plugins in code, which allows for more consistency across environments and less risk of accidental deactivation by users. See our plugin loader library and also the recommendation from WordPress VIP for sites on their platform.
In these scenarios, plugins are typically not loaded within global scope, and so variables defined in the plugin entry file are not automatically globalized.
Although workarounds exist to globalize variables manually after including the plugin entry file, the Disqus plugin poses a challenge because it relies on the
DISQUSVERSION
variable, as aglobal
, later in the same entry file, here:disqus-wordpress-plugin/disqus/disqus.php
Lines 62 to 78 in 9c20fe3
When the plugin is loaded in code, that variable does not exist yet as a global when
run_disqus()
runs.The fix proposed here is to just assign
DISQUSVERSION
directly to$GLOBALS
, rather than the current approach of assuming that the plugin is being loaded in such a way that the variable will end up in$GLOBALS
. This change should ensure the variable is available torun_disqus()
even when the Disqus plugin is loaded in code.How Has This Been Tested?
Use the Plugin Loader library to attempt to load the Disqus plugin:
Observe that the Disqus settings page fails to load because the version number is missing from the enqueued JavaScript.
Apply the change, and observe that the version number is present again.
Types of changes
Checklist: