Make WordPress Core

Opened 9 months ago

Closed 7 months ago

Last modified 7 months ago

#54129 closed defect (bug) (fixed)

Undefined index 'posts_per_page' in ajax-actions.php

Reported by: davidwebca's profile davidwebca Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 5.8.2 Priority: normal
Severity: normal Version: 5.8
Component: Media Keywords: has-patch needs-testing commit
Focuses: Cc:

Description

This is a follow-up to #53773.

The fix was unsifficient to prevent some errors, such as 'undefined index: posts_per_page' which I am getting right now on line 3006 in 5.8.1.

The problem comes from the fact that we are trying to get "posts_per_page" on the query sub-object directly instead of using getter methods on the WP_Query instance. With the getter methods of WP_Query, a default value is always provided if none is set by the user and defaults to 12 like the WordPress global posts_per_page value.

Line 3006 should be changed from

$posts_per_page = (int) $attachments_query->query['posts_per_page'];

to

$posts_per_page = (int) $attachments_query->get('posts_per_page');

Change History (9)

#1 @SergeyBiryukov
9 months ago

  • Milestone changed from Awaiting Review to 5.8.2

Hi there, welcome back to WordPress Trac! Thanks for the ticket.

Moving to 5.8.2, as this was introduced in [51145].

#2 @SergeyBiryukov
9 months ago

  • Version set to 5.8

This ticket was mentioned in PR #1679 on WordPress/wordpress-develop by mukeshpanchal27.


8 months ago

  • Keywords has-patch added

#4 @mukesh27
8 months ago

PR added with required change.

Feel free to update

This ticket was mentioned in Slack in #core-media by antpb. View the logs.


8 months ago

#6 @circlecube
7 months ago

  • Keywords needs-testing added

#7 @desrosj
7 months ago

  • Keywords commit added

#8 @SergeyBiryukov
7 months ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 51982:

Media: Use WP_Query::get() method to retrieve the posts_per_page value in wp_ajax_query_attachments().

This avoids a PHP notice and ensures that a default value is always provided if none is set by the user.

Follow-up to [51145], [51485].

Props davidwebca, mukesh27.
Fixes #54129.

#9 @SergeyBiryukov
7 months ago

In 51983:

Media: Use WP_Query::get() method to retrieve the posts_per_page value in wp_ajax_query_attachments().

This avoids a PHP notice and ensures that a default value is always provided if none is set by the user.

Follow-up to [51145], [51485].

Props davidwebca, mukesh27, circlecube, desrosj.
Merges [51982] to the 5.8 branch.
Fixes #54129.

Note: See TracTickets for help on using tickets.