Skip to content

Dan’s Tech Blog

Domains Guru, Geek, Coder, Lover of Terry’s Chocolate oranges & Pluviophile

Menu
  • Home
  • About Dan
  • Review / Advertise
Menu

WordPress 3.1 with Disqus Plugin Errors for Comment Count in Admin

Posted on April 5, 2011 by 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!

 

 

Facebook Comments

Share this:

  • Click to share on Twitter (Opens in new window)
  • Click to share on Facebook (Opens in new window)

Related

7 thoughts on “WordPress 3.1 with Disqus Plugin Errors for Comment Count in Admin”

  1. Joomla Developers says:
    April 9, 2011 at 8:51 am

    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!

    Reply
  2. Joomla Developers says:
    April 9, 2011 at 8:51 am

    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!

    Reply
  3. Lorenzo Juanos says:
    April 18, 2011 at 8:43 pm

    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.

    Reply
  4. Anonymous says:
    August 8, 2011 at 7:30 pm

    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

    Reply
  5. Domain register says:
    December 22, 2011 at 1:35 pm

    This is really my very first time here  Great job, wonderful blog… Thanks

    Reply
  6. Joomla Web Developers says:
    February 22, 2012 at 9:24 am

    You have explained well, what is going wrong with it and how to solve the above problem. Thanks for sharing such a great post.

    Reply
  7. Magento Development says:
    May 16, 2013 at 6:10 am

    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.

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • Can technology help predict outcomes?
  • Review: UnoDNS from UnoTelly.com
  • HungryHouse goes Mobile!
  • CAD Helps US Army with Star Trek-Style Replicators
  • Online Reputation Management: An Increasingly Needed Industry

Recent Comments

  • umeh on How to: Install FireSheep
  • ali on How to: Install FireSheep
  • Dan on HungryHouse goes Mobile!
  • Oliver on HungryHouse goes Mobile!
  • ForsterDJ on HungryHouse goes Mobile!

Categories

  • Cool Sites
  • Cool Tech
  • General stuff
  • Google
  • How Tos & Tutorials
  • Humor and funny crap!
  • Infographics
  • Microsoft
  • Ponderings
  • Projects
  • Ranting
  • Reviews
  • Scripts
  • Sponsored Posts
  • Student Partner
  • Tech Events
  • Technological Ponderings
  • Top Ten…
  • Tv/Video/Music Talk
  • Twitter
  • Uncategorized
  • University
  • vLogs
  • Web Hosting
  • Windows Phone
  • Windows Stuff
  • XBOX 360
  • YouTube

Archives

  • April 2015
  • October 2014
  • October 2013
  • February 2013
  • December 2012
  • November 2012
  • October 2012
  • August 2012
  • June 2012
  • May 2012
  • April 2012
  • March 2012
  • February 2012
  • January 2012
  • December 2011
  • November 2011
  • October 2011
  • September 2011
  • August 2011
  • July 2011
  • June 2011
  • May 2011
  • April 2011
  • March 2011
  • February 2011
  • January 2011
  • December 2010
  • November 2010
  • October 2010
  • September 2010
  • August 2010
  • July 2010
  • March 2010
  • February 2010
  • December 2009
  • November 2009
  • October 2009
  • September 2009
  • July 2009
  • June 2009
  • May 2009
  • April 2009
  • March 2009
  • February 2009
  • January 2009
  • December 2008
  • November 2008
  • September 2008
  • August 2008
  • July 2008
  • June 2008
  • May 2008
  • April 2008
  • March 2008
  • February 2008
  • January 2008
  • December 2007
  • November 2007
  • October 2007
  • September 2007

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
Proudly Hosted by allthe.domains
©2021 Dan’s Tech Blog | Built using WordPress and Responsive Blogily theme by Superb