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.
Built from https://develop.svn.wordpress.org/trunk@51485


git-svn-id: http://core.svn.wordpress.org/trunk@51096 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2021-07-25 09:56:57 +00:00
parent b67f94503e
commit b218b7504c
2 changed files with 4 additions and 2 deletions

View File

@ -3003,7 +3003,9 @@ function wp_ajax_query_attachments() {
$total_posts = $count_query->found_posts; $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-Total: ' . (int) $total_posts );
header( 'X-WP-TotalPages: ' . (int) $max_pages ); header( 'X-WP-TotalPages: ' . (int) $max_pages );

View File

@ -13,7 +13,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '5.9-alpha-51484'; $wp_version = '5.9-alpha-51485';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.