Make WordPress Core

Opened 5 weeks ago

Closed 4 weeks ago

#64085 closed defect (bug) (worksforme)

Missing parentheses in condition in delete_metadata()

Reported by: threadi's profile threadi Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 6.8.3
Component: Options, Meta APIs Keywords:
Focuses: Cc:

Description

In wp-includes/meta.php inside the function delete_metadata() if the following if-condition:

if ( ! $meta_type || ! $meta_key || ! is_numeric( $object_id ) && ! $delete_all ) {
 return false;
}

There is a missing parentheses around the last two conditions on this line. As a result, the condition will not be true in the cases where it should be.

A correction would look like this:

if ( ! $meta_type || ! $meta_key || ( ! is_numeric( $object_id ) && ! $delete_all ) ) {
 return false;
}

Source: https://github.com/WordPress/WordPress/blob/master/wp-includes/meta.php#L402

Change History (5)

#1 @jorbin
5 weeks ago

Introduced in [29421].

Can you write some unit tests that demonstrate this being an issue? With it being 11 years that this behavior has been a part of core, I think it's important to understand exactly what the change would mean.

#2 follow-up: @TobiasBg
5 weeks ago

I actually think that the && is evaluated before the || even without parentheses.

#3 @Presskopp
5 weeks ago

I go with @TobiasBg

#4 in reply to: ↑ 2 @SergeyBiryukov
5 weeks ago

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

Replying to TobiasBg:

I actually think that the && is evaluated before the || even without parentheses.

Yes, see PHP: Operator Precedence. The condition is correct as is, and the additional parentheses would be redundant here.

#5 @Presskopp
4 weeks ago

  • Resolution set to worksforme
  • Status changed from new to closed

Nowhere in the coding standards does it say that we should use parentheses for clarity. Since this works well as it is, let's close the case.

Note: See TracTickets for help on using tickets.