From 9ea5645ec29f0e63057a6d6a64dfc7c52cfdb863 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sun, 25 Jul 2021 09:55:33 +0000 Subject: [PATCH] Media: Check the `posts_per_page` value in `wp_ajax_query_attachments()` before using it as a divisor. This avoids a "Division by zero" PHP warning if a plugin changes the `posts_per_page` value to zero. Follow-up to [51145]. Props 2linctools, kapilpaul, audrasjb. Fixes #53773. git-svn-id: https://develop.svn.wordpress.org/trunk@51485 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/ajax-actions.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/wp-admin/includes/ajax-actions.php b/src/wp-admin/includes/ajax-actions.php index a4ed8efbfc..c05345e6e2 100644 --- a/src/wp-admin/includes/ajax-actions.php +++ b/src/wp-admin/includes/ajax-actions.php @@ -3003,7 +3003,9 @@ function wp_ajax_query_attachments() { $total_posts = $count_query->found_posts; } - $max_pages = ceil( $total_posts / (int) $attachments_query->query['posts_per_page'] ); + $posts_per_page = (int) $attachments_query->query['posts_per_page']; + + $max_pages = $posts_per_page ? ceil( $total_posts / $posts_per_page ) : 0; header( 'X-WP-Total: ' . (int) $total_posts ); header( 'X-WP-TotalPages: ' . (int) $max_pages );