May 22nd

How to fix disqus plugin for WordPress 3.2 beta

2011, 16:49 UTC | By | In wordpress
Leave a comment | Trackback  | 10570 views

Disqus plugin breaks admin area of WordPress 3.2 beta

After installing the disqus plugin in WordPress 3.2 beta1, I began to notice severe problems in the WordPress admin area. Basically, all JavaScript related things stopped working - the sliding menus on the left did no longer respond and many other things were broken as well.

Using Opera Dragonfly, I quickly found a JavaScript error:

Uncaught exception: Syntax error, unrecognized expression: [href=edit-comments.php?page=disqus]

This is caused by a change in jQuery which was upgraded to version 1.5.2 in WordPress  3.2. Unquoted selectors are no longer allowed in jQuery 1.5.2, so this is a fairly easy fix.

 Searching wp-content/plugins/disqus-comment-system/disqus.php for the phrase, I found it in or around line 761.

mc.find('a.wp-has-submenu').attr('href', 'edit-comments.php?page=disqus').end().find('.wp-submenu  li:has('a[href=edit-comments.php?page=disqus]')')

To fix the problem, you must quote the selector for li:has(). Just add single quotes like seen in the code above.

I'm pretty certain disqus will release an updated version of their plugin soon, because it's popular and widely in use, but until then, the fix above should work and restore full admin area functionality.

HTML5 validation fix

Also, if you care about valid HTML5, there is another small problem in the disqus plugin. It is using rel attributes in <span> tags (which is not allowed in HTML5) to mark these tags for the JavaScript code that later replaces them with the  x comments and y reactions link.

Instead of rel attributes, a HTML5 conformal data-*  attribute can be used. To fix this, do the following:

  • Search disqus.php for <span class="dsq-postid"  rel="[...]. There should be 2 occurrences around line 700 in the functions dsq_comments_number and dsq_comments_text.
  • replace the rel tag with a data-* tag of your choice, for example data-id.
  • Around line 1060 there are 2 functions, dsq_output_loop_comment_js and dsq_output_footer_comment_js. Within the loops inside these 2 functions, you will find a nodes[i].getAttribute('rel') expression. Replace the rel with the name of the data-* tag you have assigned in step 2.

This will make HTML5 validators happy without affecting the functionality of the plugin.

Note: tested in most modern browsers (Internet Explorer 8 and up), Chrome, Firefox 4, Opera 10+11.  I cannot guarantee that some older browsers may react strangely on data-* attributes. In theory, they shouldn't, but you never know...

Last update: June 1, 2011

2 Likes Like
 

14 responses to: How to fix disqus plugin for WordPress 3.2 beta

  1. eschapp, May 24th, 2011 at 16:10
    Reply | Quote | #2

    Thanks for sharing this fix!

  2. James Koole, May 25th, 2011 at 23:28
    Reply | Quote | #3

    Thank you thank you. I pointed this out to Disqus and they didn't care because I was running WordPress 3.2b. Unimpressed by that, but happy to see a solution!

  3. Michael Aulia @Cravi, May 26th, 2011 at 01:36
    Reply | Quote | #5

    Many thanks for this!! I've been searching for it on Google and didn't know it's because of the DISQUS plug-in

  4. rainer, Jun 26th, 2011 at 18:09
    Reply | Quote | #7

    to be honest, this error is some reason i dont use disqus at my blog. but since you point out the error, looks like i have to evaluate this again.. thx

  5. Guest, Jun 29th, 2011 at 09:41
    Reply | Quote | #8

    hi, i m new in wordpress, i am using disqus comment system plugin in my website, when i login through admin panel in discus menu i logged in but showing 
    You are not allowed to access this page.
    Please make sure you're logged into the correct account.
    i can not understand what happened
    can anyone please help me
    thanks

    • Alex, Jun 30th, 2011 at 13:07
      Reply | Quote | #9

      Looks like you are not authenticated with disqus - you need to login separately before you can fully access the disqus admin section in your WordPress admin back end.

      If you ARE logged into disqus, maybe you didn't setup the plugin properly? 

      In you WP admin panel go to discuss setup (it's in the comments node). In the top right corner of that page, you'll find a Advanced Options link. Click it and configure the page that opens. For a minimum, you need to provide your disqus short name and your API keys.

      If it still doesn't work, maybe you should ask disqus support.

  6. Generic Viagra, Jul 5th, 2011 at 07:50

    Thank you for this! I searched on Google and did not know is because Disqus plug-in

  7. code should be  by  Khalid, Aug 1st, 2011 at 19:31

    I think the code should be
    with double quote then its working fine
    .find(".wp-submenu li:has('a[href=edit-comments.php?page=disqus]')")

  8. Solai Luke, Dec 1st, 2011 at 00:54

    This is the interesting post! Thank you for the idea! With all the best Luke aka couchgool.

Subject

  (this is optional)

Comment text

Allowed HTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>