Options, Meta APIs: Pass $delete_all to the delete_{$meta_type}_meta and deleted_{$meta_type}_meta actions. - #13292
Conversation
…and deleted_{$meta_type}_meta actions.
The $delete_all flag passed to delete_metadata() was not exposed to the
delete_{$meta_type}_meta and deleted_{$meta_type}_meta action hooks, so
callbacks could not tell whether the metadata being deleted is removed
for all objects, with the given object ID ignored. Pass it as an
additional argument, matching the delete_{$meta_type}_metadata filter
which already receives it.
delete_metadata_by_mid() fires the same actions and now passes an
explicit false, so callbacks opting into the additional argument receive
it on both code paths.
Claude-Session: https://claude.ai/code/session_01Bjv7bM9MF844TKLMqueyF7
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
Trac ticket: https://core.trac.wordpress.org/ticket/65976
What
Passes the
$delete_allflag given todelete_metadata()through to thedelete_{$meta_type}_metaanddeleted_{$meta_type}_metaaction hooks as an additional (5th) argument.delete_metadata_by_mid(), which fires the same actions, passes an explicitfalse.Why
When
$delete_allis true, matching metadata is deleted for all objects and the$object_idpassed to these hooks is ignored — but callbacks currently have no way to know that. Thedelete_{$meta_type}_metadatashort-circuit filter already receives$delete_all; this brings the actions in line with it, following the same approach as #39706 / PR #12768 did for$uniqueon the add actions.Passing an explicit
falseindelete_metadata_by_mid()ensures callbacks that opt into the additional argument work on both code paths that fire these hooks.The change is backward compatible: existing callbacks declared their accepted argument count against the old signature and continue to receive exactly the arguments they did before.
Testing
New unit tests in
tests/phpunit/tests/meta/deleteMetadata.phpassert that both actions receive$delete_allfor bothtrueandfalse, and that they receivefalsewhen deleting viadelete_metadata_by_mid().Notes
@since 7.2.0matches the version used in PR #12768; happy to adjust.https://claude.ai/code/session_01Bjv7bM9MF844TKLMqueyF7