Opened 3 years ago
Closed 3 years ago
#53773 closed defect (bug) (fixed)
/wp-admin/includes/ajax-actions.php file line 3006 is creating divide by zero error
Reported by: | 2linctools | Owned by: | SergeyBiryukov |
---|---|---|---|
Milestone: | 5.8.1 | Priority: | normal |
Severity: | normal | Version: | 5.8 |
Component: | Media | Keywords: | good-first-bug has-patch commit fixed-major |
Focuses: | Cc: |
Description (last modified by )
In the /wp-admin/includes/ajax-actions.php file line 3006 it keeps popping up an error in our php error log that says it is trying to divide by zero. It produces an error over and over again.
PHP Warning: Division by zero in /wp-admin/includes/ajax-actions.php on line 3006
This is line 3006:
$max_pages = ceil( $total_posts / (int) $attachments_query->query['posts_per_page'] );
Here is the whole section:
/** * Filters the arguments passed to WP_Query during an Ajax * call for querying attachments. * * @since 3.7.0 * * @see WP_Query::parse_query() * * @param array $query An array of query variables. */ $query = apply_filters( 'ajax_query_attachments_args', $query ); $attachments_query = new WP_Query( $query ); $posts = array_map( 'wp_prepare_attachment_for_js', $attachments_query->posts ); $posts = array_filter( $posts ); $total_posts = $attachments_query->found_posts; if ( $total_posts < 1 ) { // Out-of-bounds, run the query again without LIMIT for total count. unset( $query['paged'] ); $count_query = new WP_Query(); $count_query->query( $query ); $total_posts = $count_query->found_posts; } $max_pages = ceil( $total_posts / (int) $attachments_query->query['posts_per_page'] ); header( 'X-WP-Total: ' . (int) $total_posts ); header( 'X-WP-TotalPages: ' . (int) $max_pages ); wp_send_json_success( $posts ); }
Our php error log looks like this: (truncated a lot)
[23-Jul-2021 18:46:05 UTC] PHP Warning: Division by zero in /wp-admin/includes/ajax-actions.php on line 3006 [23-Jul-2021 18:46:14 UTC] PHP Warning: Division by zero in /wp-admin/includes/ajax-actions.php on line 3006 [23-Jul-2021 18:46:32 UTC] PHP Warning: Division by zero in /wp-admin/includes/ajax-actions.php on line 3006 [23-Jul-2021 18:46:34 UTC] PHP Warning: Division by zero in /wp-admin/includes/ajax-actions.php on line 3006 [23-Jul-2021 18:58:34 UTC] PHP Warning: Division by zero in /wp-admin/includes/ajax-actions.php on line 3006 [23-Jul-2021 18:58:42 UTC] PHP Warning: Division by zero in /wp-admin/includes/ajax-actions.php on line 3006 [23-Jul-2021 19:35:22 UTC] PHP Warning: Division by zero in /wp-admin/includes/ajax-actions.php on line 3006 [23-Jul-2021 19:35:58 UTC] PHP Warning: Division by zero in /wp-admin/includes/ajax-actions.php on line 3006 [23-Jul-2021 19:36:01 UTC] PHP Warning: Division by zero in /wp-admin/includes/ajax-actions.php on line 3006
Attachments (1)
Change History (8)
#1
@
3 years ago
- Component changed from General to Media
- Description modified (diff)
- Keywords needs-patch good-first-bug added
- Milestone changed from Awaiting Review to 5.8.1
This ticket was mentioned in PR #1518 on WordPress/wordpress-develop by kapilpaul.
3 years ago
#2
- Keywords has-patch added; needs-patch removed
This PR will fix the /wp-admin/includes/ajax-actions.php file line 3006 is creating divide by zero error.
Trac Ticket: https://core.trac.wordpress.org/ticket/53773
#3
@
3 years ago
I tested the proposed patch with changing the posts_per_page
value using ajax_query_attachments_args
filter and it looks like it solves the issue.
Marking for commit
.
#5
@
3 years ago
- Owner set to SergeyBiryukov
- Resolution set to fixed
- Status changed from new to closed
In 51485:
Hi there, welcome to WordPress Trac! Thanks for the report.
Introduced in [51145].
It looks like a plugin or theme changes the
posts_per_page
value to0
using theajax_query_attachments_args
filter. By default, it's set to 40 in wp-includes/js/media-models.js.We should be able to check the value and set
$max_pages
to0
too in that case.