studiohyperset/wordpress-pagination-plugin

PHP Warning: Division by zero in …/scrolling-pagination-functions.php

Closed this issue · 1 comments

From the WordPress plugin's support forum, about 6 months ago:

https://wordpress.org/support/topic/php-warning-division-by-zero-in-scrolling-pagination-functions-php/

I'm reposting it here because this is an extremely easy way to fix the above error, but if you prefer a PR, let me know (I'm lazy!).

Hi,

I’m getting this warning on my logs:

PHP Warning: Division by zero in /[full path to my WP installation]/wp-content/plugins/page-links-single-page-option/addons/scrolling-pagination/scrolling-pagination-functions.php on line 47

The affected function is generate_scrolling_pagination() and on line 47 we have:

$scrolls = $pages / $pages_per_scroll;

For some obscure reason, in my setup, sometimes $pages_per_scroll is zero, and so the division naturally fails.

A very quick & dirty fix is to simply change the above line to:

$scrolls = $pages / ($pages_per_scroll ?: 1);

but I guess there might be ‘cleaner’ ways to check why $pages_per_scroll is zero in some cases. I have to admit that your code is very clean and simple to read, but it would require me a lot of time to fully debug it.

In the meantime, if readers of this forum see the above message on their web server logs, as said, the quick & dirty fix will at least get rid of the message and do something sensible.

As a reference, my setup runs on Ubuntu 20.04.1 LTS, nginx/1.19.2 + php-fpm 7.4.10, WordPress is at the latest version, running the Customizr Pro theme, and major plugins are Jetpack, WordFence, and WP Fastest Cache (there are plenty of minor plugins as well, including a few of my own…). PHP 7.4+ is a bit stricter on a lot of functions, and it may be the reason why this warning started popping up 6 months ago. (note: this paragraph has been updated with my current setup)

Fix applied in latest release