Make WordPress Core

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#53411 closed defect (bug) (fixed)

Incorrect isset check in media bulk actions

Reported by: davidbinda's profile david.binda Owned by: davidbaumwald's profile davidbaumwald
Milestone: 5.8 Priority: normal
Severity: normal Version: 5.8
Component: Media Keywords: has-patch commit
Focuses: Cc:

Description

After r51111 which makes sure that the $post_ids variable is always set, the isset() check later in the code is never matched.

The checks failure results in an extra redirect to wp-admin/upload.php?deleted=0 and then finally back to wp-admin/upload.php in case there are no IDs passed to some default bulk actions (eg.: delete).

Prior this change, in case there were no IDs passed to the bulk action, the request was redirected directly to wp-admin/upload.php.

It can be easily tested by visiting the wp-admin/upload.php screen and submitting any bulk action w/o selecting any media.

My understanding is, that with r51111 in place, the checks in question should be updated to empty(). See attached patch.

Related code lines:

Follow-up to #39589

Attachments (1)

53411.diff (820 bytes) - added by david.binda 3 years ago.

Download all attachments as: .zip

Change History (7)

@david.binda
3 years ago

#1 @desrosj
3 years ago

  • Milestone changed from Awaiting Review to 5.8

Thanks @davidbinda!

@whyisjake @hellofromtonya are you able to take a look at this one?

#2 @hellofromTonya
3 years ago

@desrosj I'm on it. Reviewing and testing now.

#3 @hellofromTonya
3 years ago

  • Keywords has-patch commit added

Review summary:

Yes, @davidbinda is right. The variable is now initialized and set to an empty array. This means isset() is no longer the appropriate construct. The check in this context is for no post IDs, which means checking for an empty array. empty() is a good guard clause as well as a valid check for this context.

  • The patch looks good
  • Manually tested with expected results
  • Tests passing
  • Linting passing

Marking for commit.

#4 @davidbaumwald
3 years ago

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

In 51161:

Media: Ensure $post_ids is evaluated properly when processing bulk actions.

After [51111], the $post_ids variable is now initialized as an empty array when processing a bulk action. As such, the original check using isset on $post_ids will always evaluate to true. This change swaps the isset checks for empty to check array length instead.

Props david.binda, hellofromTonya.
Fixes #53411.

#5 @SergeyBiryukov
3 years ago

In 51163:

Quick/Bulk Edit: Ensure that $post_ids variable is initialized ahead of usage.

This brings some consistency between similar fragments of wp-admin/edit.php and wp-admin/upload.php.

Follow-up to [51111], [51161].

See #39589, #53411.

Note: See TracTickets for help on using tickets.