lesterchan/wp-sweep

"Division by zero" in comments tables if there are really no comments

barisunver opened this issue · 4 comments

Warning: Division by zero in /home/***/public_html/wp-content/plugins/wp-sweep/admin.php on line 184

I use Disqus in my blog, so I don't keep comments in my database. Naturally, when WP-Sweep uses the code below:

<?php echo round( ( $deleted_comments/$total_comments ) * 100, 2 ); ?>

It returns a warning of "division by zero". This is of course, one of the five lines of code that checks the comments table.

The code below works better:

<?php echo ( $total_comments > 0 ? round( ( $deleted_comments / $total_comments ) * 100, 2 ) : 0 ); ?>%

But I suggest you use a simple function that you can use anywhere to make the code cleaner:

<?php

function check_percentage( $check, $total ) {

    return ( $total > 0 ? round( ( $check / $total ) * 100, 2 ) : 0 ) . '%';

}

?>

BTW, any plans on putting a "Sweep All" button?

+1 on the sweep all button!

Thanks @barisunver, I will fix it on monday! yea it was a copy and paste coding to get the job done. Only after that I will refactor :p

I have plans on Sweep All and cron job. My concern for sweep off is that I afraid it might timeout because the process is quite heavy unless I switched it to AJAX based.

I was about to open a new issue regarding this matter. Please update the latest version on WordPress.org :)