Make WordPress Core

Opened 4 years ago

Closed 4 years ago

#51797 closed defect (bug) (fixed)

Clarify return results for a non-existing ID in metadata functions

Reported by: sergeybiryukov's profile SergeyBiryukov Owned by: davidbaumwald's profile davidbaumwald
Milestone: 5.8 Priority: normal
Severity: normal Version: 5.5
Component: Options, Meta APIs Keywords: has-patch commit
Focuses: docs Cc:

Description

Background: #40519

[48658] documented that various metadata functions return false for an invalid ID. However, that does not clarify what an invalid ID is: a non-numeric, zero, or negative value.

For example, if a valid but non-existing post ID is passed, get_post_meta() returns an empty string, not false, but it's not mentioned in the documentation.

This applies to:

  • get_comment_meta()
  • get_site_meta()
  • get_post_meta()
  • get_term_meta()
  • get_user_meta()

And potentially these functions too:

  • get_metadata()
  • get_metadata_raw()
  • get_metadata_default()

Props to @icopydoc for the report on support forums.

Attachments (4)

51797.diff (5.4 KB) - added by david.kryzaniak 4 years ago.
Updates to docs
51797.2.diff (6.1 KB) - added by audrasjb 4 years ago.
51797.3.patch (6.8 KB) - added by david.kryzaniak 4 years ago.
51797.4.diff (10.7 KB) - added by SergeyBiryukov 4 years ago.

Download all attachments as: .zip

Change History (10)

This ticket was mentioned in Slack in #core by metalandcoffee. View the logs.


4 years ago

@david.kryzaniak
4 years ago

Updates to docs

@audrasjb
4 years ago

#2 @audrasjb
4 years ago

  • Keywords has-patch added

Thanks @davidkryzaniak. In 51797.2.diff I completed the docs with more details and I also updated get_metadata() and get_metadata_raw(). I didn't change get_metadata_default() because I'm not sure this comment for the returned value is relevant for this function.

#3 @SergeyBiryukov
4 years ago

  • Milestone changed from 5.7 to 5.8

Thanks for the patch!

Looks like this needs some minor adjustments to replace "post ID" with "term ID", "user ID", etc. where appropriate. Moving to the next release for now for a closer review.

#4 @davidbaumwald
4 years ago

  • Owner set to davidbaumwald
  • Status changed from new to accepted

#5 @SergeyBiryukov
4 years ago

  • Keywords commit added

Thanks for the patch! This mostly looks good.

51797.4.diff makes some further adjustments for consistency and accuracy.

#6 @davidbaumwald
4 years ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 50641:

Docs: Clarify return results for a non-existing ID in metadata functions.

[48658] documented that various metadata functions return false for an invalid ID. However, that does not clarify what an invalid ID is: a non-numeric, zero, or negative value. This change adds the clarification in all relevant metadata function docblocks.

Props icopydoc, SergeyBiryukov, davidkryzaniak, audrasjb.
Fixes #51797.

Note: See TracTickets for help on using tickets.