lesterchan / wp-sweep

WP-Sweep allows you to clean up unused, orphaned and duplicated data in your WordPress. It also optimizes your database tables.
https://wordpress.org/plugins/wp-sweep/
153 stars 22 forks source link

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

Closed barisunver closed 9 years ago

barisunver commented 9 years ago

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 ) . '%';

}

?>
barisunver commented 9 years ago

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

senlin commented 9 years ago

+1 on the sweep all button!

lesterchan commented 9 years ago

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.

siamkreative commented 9 years ago

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