[wp-trac] [WordPress Trac] #45273: get_postmeta: Inconsistent behavior of the 'single'-argument
WordPress Trac
noreply at wordpress.org
Sat Nov 3 19:29:48 UTC 2018
#45273: get_postmeta: Inconsistent behavior of the 'single'-argument
--------------------------+-----------------------------
Reporter: josk79 | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: trunk
Severity: normal | Keywords: 2nd-opinion
Focuses: |
--------------------------+-----------------------------
The phpdoc of the ''get_postmeta''-function in meta.php mentions that the
''single''-argument has no effect if ''meta_key'' is not specified.
This is not true when the ''get_{$meta_type}_metadata''-filter is used. If
this filter returns an array and ''single'' is true only the first item of
the array is returned. This not the expected behavior when ''meta_key'' is
empty.
In my opinion this part:
{{{#!php
$check = apply_filters( "get_{$meta_type}_metadata", null,
$object_id, $meta_key, $single );
if ( null !== $check ) {
if ( $single && is_array( $check ) ) {
return $check[0];
}
else {
return $check;
}
}
}}}
should be replace by:
{{{#!php
$check = apply_filters( "get_{$meta_type}_metadata", null,
$object_id, $meta_key, $single );
if ( null !== $check ) {
if ( $meta_key && $single && is_array( $check ) ) {
return $check[0];
}
else {
return $check;
}
}
}}}
(Notice how I added {{{$meta_key && }}})
NOTE: This is a breaking change in the rare occasion that
''get_{$meta_type}_metadata''-filter is used in combination with an empty
''meta_key'' and ''single'' == true. If a fix is not desired; phpdoc must
be changed to document this inconsistent behavior.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/45273>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list