Make WordPress Core

Opened 10 months ago

Closed 10 months ago

Last modified 8 months ago

#64085 closed defect (bug) (worksforme)

Missing parentheses in condition in delete_metadata()

Reported by: threadi Owned by:
Priority: normal Milestone:
Component: Options, Meta APIs Version: 6.8.3
Severity: normal Keywords:
Cc: Focuses:

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 (6)

#1 @jorbin
10 months 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
10 months ago

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

#3 @Presskopp
10 months ago

I go with @TobiasBg

#4 in reply to: ↑ 2 @SergeyBiryukov
10 months 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
10 months ago

  • Resolutionworksforme
  • Status newclosed

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.

#6 @swissspidy
8 months ago

  • Milestone Awaiting Review

Removing milestone from closed ticket.

Note: See TracTickets for help on using tickets.