I'm able to view Disqus comments on content types I've selected when logged into Drupal as an Authenticated user, but when I visit the same content as Anonymous, Disqus comments are not loaded and this noscript block of code gets written out:

<div id="disqus_thread">
<noscript><p><a href="[url]">View the discussion thread.</a></p></noscript>
</div>

I confirmed that all Permissions are set correctly for Anon to be able to view disqus comments and I turned off all caching and JS aggregation.

I found this comment in disqus.module line 779: "Prepares the noscript tag which is used when JavaScript is not available.", where function theme_disqus_noscript returns this noscript tag.

I confirmed that while I'm Authenticated, sites/all/modules/contrib/disqus/disqus.js gets loaded, but when I'm Anonymous this file does not get loaded. Even though doing a var_dump($element) in function disqus_element_post_render shows that the disqus.js is getting stored in $element['#attached']['js'][] for BOTH Authenticated and Anonymous with all caches cleared.

I'm not sure what is stopping disqus.js from loading for Anonymous users and how else can I get it to load?

Comments

slashrsm’s picture

Category: bug » support

Have you tried to clear caches? Does it happen with JS aggregation enabled or disabled?

wesleymusgrove’s picture

Yes I have cleared all caches and disabled all block and page caching. Turning off/on JS aggregation doesn't change anything.

I turned off all caching and JS aggregation.

This was happening on the 7.x-1.9 branch as well as the 7.x-1.x-dev. I duplicated the issue on two separate installs.

wesleymusgrove’s picture

Status: Active » Closed (works as designed)

This issue has been resolved. I had a hook implementation in template.php that I forgot about which removes javascript for anonymous users, as I have a custom implementation that loads javascript dependencies after the DOM finishes loading.

function hook_js_alter(&$javascript) {
	$logged_in_user = user_uid_optional_load();
	if(!in_array("authenticated user", $logged_in_user->roles)) {
		foreach($javascript as $key => $value) {
			unset($javascript[$key]);
		}
	}
}

I temporarily removed this function and confirmed that disqus.js loads for anonymous users. However it is not loaded after the page loads, which wasn't satisfactory for my project. My final solution was to abandon use of the module and incorporate Disqus' universal embed code into my postloaded javascript solution.