Make WordPress Core

Opened 6 years ago

Closed 6 years ago

#51797 closed defect (bug) (fixed)

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

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

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 6 years ago.
Updates to docs
51797.2.diff​ (6.1 KB ) - added by audrasjb 6 years ago.
51797.3.patch​ (6.8 KB ) - added by david.kryzaniak 6 years ago.
51797.4.diff​ (10.7 KB ) - added by SergeyBiryukov 6 years ago.

Download all attachments as: .zip

Change History (10)

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


6 years ago

@david.kryzaniak
6 years ago

Updates to docs

@audrasjb
6 years ago

#2 @audrasjb
6 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
6 years ago

  • Milestone 5.7 → 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
6 years ago

  • Owner set to davidbaumwald
  • Status new → accepted

#5 @SergeyBiryukov
6 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
6 years ago

  • Resolution → fixed
  • Status accepted → 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.