I noticed a while ago when I upgraded all the blogs I manage to WordPress 3.1 that there is a small problem with using the Disqus plugin in that it causes a horrible error when viewing posts page in the Admin interface.
Instead of showing the post count it instead shows:
Warning: number_format() expects parameter 1 to be double, string given in/home/dan/public_html/wp-includes/functions.php on line155
What’s going wrong?
The problem is fairly simple, because of the way the disqus plugin works it injects itself into the comment system. This means when class-wp-list-table.php calls the get_comments_number() function and passes it into the internal number_formati18n() function it causes an error because unlike vanilla WordPress comments, disqus is injecting HTML code. Making the output a string and not a decimal as expected.
How to Fix It?
Being a lazy coder I naturally Googled it and discovered Evan Wondrasek’s post on the problem, where he offers a “fix”… However, I wasn’t satisfied with the output as this means that while it fixes the problem in the WordPress backend, it still means that the front end is returned a boring number and not the nice text I like.
So, after a – surprisingly very brief – think the answer seemed obvious.
Instead of completely re-writing the disqus plugin function(s) I instead made a small alteration which solved the problem beautifully.
1. Open the file /wp-content/plugins/disqus-comment-system/disqus.php
2. Jump to the code on line 692:
function dsq_comments_number($count) {
global $post;
if ( dsq_can_replace()) {
return ''.$count.'';
} else {
return $count;
}
}
3. Insert && !is_admin()
into the if statement
function dsq_comments_number($count) {
global $post;
if ( dsq_can_replace() && !is_admin()) {
return ''.$count.'';
} else {
return $count;
}
}
This means it will check if the code is running withing the WordPress admin panel (eg, when you are viewing posts) if it is, it will return the raw count – if not it will return as normal.
That’s it! Code should function perfectly in both Admin and Front-end!
If this helps or if you have any problems please drop a comment below!
Really great work you have done by discovering WordPress 3.1 with Disqus Plugin Errors. Awesome work and information. I enjoyed reading your article. I would like to thanks for the effort you have done for crafting this great article. Thanks again!
Really great work you have done by discovering WordPress 3.1 with Disqus Plugin Errors. Awesome work and information. I enjoyed reading your article. I would like to thanks for the effort you have done for crafting this great article. Thanks again!
The problem to solve, just add: &&! is_admin()…Now the display in the management comments is perfect before…There was all of square people who are very good at her job…XD…Graciassss…Dan…Saludos.
I am new to wordpress. Your site is really nice to read the information. I am also using disqus comment system in blogger and thinking to use the wordpress for blogging.
netfirms coupon
This is really my very first time here Great job, wonderful blog… Thanks
You have explained well, what is going wrong with it and how to solve the above problem. Thanks for sharing such a great post.
The fix is to edit disqus.php and have the function dsq_comments_number($count) simply return $count. you may need to just delete extra HTML.