Skip to content

Commit

Permalink
Docs: Further clarify return results for a non-existing ID in metadat…
Browse files Browse the repository at this point in the history
…a functions.

This adds a note that the functions return either an empty array or an empty string for a valid but non-existing ID, depending on the `$single` parameter.

Follow-up to [48658], [50641].

Props rodrigosprimo, jrf.
See #61608.

git-svn-id: https://develop.svn.wordpress.org/trunk@58962 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
SergeyBiryukov committed Sep 1, 2024
1 parent ac9dc92 commit ab523eb
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/wp-includes/comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,8 @@ function delete_comment_meta( $comment_id, $meta_key, $meta_value = '' ) {
* @return mixed An array of values if `$single` is false.
* The value of meta data field if `$single` is true.
* False for an invalid `$comment_id` (non-numeric, zero, or negative value).
* An empty string if a valid but non-existing comment ID is passed.
* An empty array if a valid but non-existing comment ID is passed and `$single` is false.
* An empty string if a valid but non-existing comment ID is passed and `$single` is true.
*/
function get_comment_meta( $comment_id, $key = '', $single = false ) {
return get_metadata( 'comment', $comment_id, $key, $single );
Expand Down
3 changes: 2 additions & 1 deletion src/wp-includes/meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,8 @@ function delete_metadata( $meta_type, $object_id, $meta_key, $meta_value = '', $
* The value of the meta field if `$single` is true.
* False for an invalid `$object_id` (non-numeric, zero, or negative value),
* or if `$meta_type` is not specified.
* An empty string if a valid but non-existing object ID is passed.
* An empty array if a valid but non-existing object ID is passed and `$single` is false.
* An empty string if a valid but non-existing object ID is passed and `$single` is true.
*/
function get_metadata( $meta_type, $object_id, $meta_key = '', $single = false ) {
$value = get_metadata_raw( $meta_type, $object_id, $meta_key, $single );
Expand Down
3 changes: 2 additions & 1 deletion src/wp-includes/ms-site.php
Original file line number Diff line number Diff line change
Expand Up @@ -1069,7 +1069,8 @@ function delete_site_meta( $site_id, $meta_key, $meta_value = '' ) {
* @return mixed An array of values if `$single` is false.
* The value of meta data field if `$single` is true.
* False for an invalid `$site_id` (non-numeric, zero, or negative value).
* An empty string if a valid but non-existing site ID is passed.
* An empty array if a valid but non-existing site ID is passed and `$single` is false.
* An empty string if a valid but non-existing site ID is passed and `$single` is true.
*/
function get_site_meta( $site_id, $key = '', $single = false ) {
return get_metadata( 'blog', $site_id, $key, $single );
Expand Down
3 changes: 2 additions & 1 deletion src/wp-includes/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -2607,7 +2607,8 @@ function delete_post_meta( $post_id, $meta_key, $meta_value = '' ) {
* @return mixed An array of values if `$single` is false.
* The value of the meta field if `$single` is true.
* False for an invalid `$post_id` (non-numeric, zero, or negative value).
* An empty string if a valid but non-existing post ID is passed.
* An empty array if a valid but non-existing post ID is passed and `$single` is false.
* An empty string if a valid but non-existing post ID is passed and `$single` is true.
*/
function get_post_meta( $post_id, $key = '', $single = false ) {
return get_metadata( 'post', $post_id, $key, $single );
Expand Down
3 changes: 2 additions & 1 deletion src/wp-includes/taxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -1430,7 +1430,8 @@ function delete_term_meta( $term_id, $meta_key, $meta_value = '' ) {
* @return mixed An array of values if `$single` is false.
* The value of the meta field if `$single` is true.
* False for an invalid `$term_id` (non-numeric, zero, or negative value).
* An empty string if a valid but non-existing term ID is passed.
* An empty array if a valid but non-existing term ID is passed and `$single` is false.
* An empty string if a valid but non-existing term ID is passed and `$single` is true.
*/
function get_term_meta( $term_id, $key = '', $single = false ) {
return get_metadata( 'term', $term_id, $key, $single );
Expand Down
3 changes: 2 additions & 1 deletion src/wp-includes/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,8 @@ function delete_user_meta( $user_id, $meta_key, $meta_value = '' ) {
* @return mixed An array of values if `$single` is false.
* The value of meta data field if `$single` is true.
* False for an invalid `$user_id` (non-numeric, zero, or negative value).
* An empty string if a valid but non-existing user ID is passed.
* An empty array if a valid but non-existing user ID is passed and `$single` is false.
* An empty string if a valid but non-existing user ID is passed and `$single` is true.
*/
function get_user_meta( $user_id, $key = '', $single = false ) {
return get_metadata( 'user', $user_id, $key, $single );
Expand Down

0 comments on commit ab523eb

Please sign in to comment.