[wp-trac] [WordPress Trac] #63797: Unexpected short‑circuit return values from add_metadata() and update_metadata()
WordPress Trac
noreply at wordpress.org
Thu Aug 7 20:02:33 UTC 2025
#63797: Unexpected short‑circuit return values from add_metadata() and
update_metadata()
--------------------------------+------------------------------
Reporter: marian1 | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Options, Meta APIs | Version:
Severity: normal | Resolution:
Keywords: | Focuses:
--------------------------------+------------------------------
Comment (by abcd95):
Thanks, @marian1, for the ticket.
I was able to reproduce the issue and can confirm that this behavior
occurs. I agree that this type of behaviour is definitely misleading in
the sense that return values can be unexpected.
The thing with the suggested approach to always return false is - Always
returning false on short circit assumes all filters intend to block the
operation, which may not be accurate. Existing plugins might rely on the
current behavior where filters can perform metadata operations themselves
and indicate success.
I'd like to propose an alternative approach that maintains backward
compatibility while fixing the core problem -
{{{
For add_metadata() -
if ( null !== $check ) {
if ( is_int( $check ) || false === $check ) {
return $check;
}
_doing_it_wrong(
__FUNCTION__,
'Filter hooks for add_metadata() must return an integer (the new
meta_id) or false.',
'6.8.something'
);
return false;
}
}}}
A similar thing can also be done for the update_metadata() function as
well. Let me know if this works well for you.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/63797#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list