WordPress 3.1 with Disqus Plugin Errors for Comment Count in Admin
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!
Related Posts:
-
http://joomla-web-developer.com/joomla-developers.html Joomla Developers
-
http://www.joomla-web-developer.com/joomla-developers.html Joomla Developers
-
http://infosantana.es/ Lorenzo Juanos
-
Anonymous
-
http://www.register-web-domain.in Domain register
-
http://www.joomla-web-developers.net/ Joomla Web Developers




