Opened 6 weeks ago
Last modified 6 weeks ago
#65976 new enhancement
Pass $delete_all to the delete_{$meta_type}_meta and deleted_{$meta_type}_meta actions
| Reported by: | brianboy | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Options, Meta APIs | Version: | 2.9 |
| Severity: | normal | Keywords: | has-patch has-unit-tests |
| Cc: | Focuses: |
Description (last modified by )
Follow-up to #39706, as suggested there in comment:1 by @barryceelen.
delete_metadata() accepts a $delete_all flag that significantly changes the semantics of the operation: when true, matching metadata is deleted for all objects and the given $object_id is ignored. The delete_{$meta_type}_meta and deleted_{$meta_type}_meta actions receive $meta_ids, $object_id, $meta_key and $_meta_value, but not $delete_all. So a callback cannot tell that the $object_id it received is meaningless for the operation.
The delete_{$meta_type}_metadata short-circuit filter already receives $delete_all this brings the actions in line with it, in the same way #39706 does for $unique on the add actions.
Note these actions also fire in delete_metadata_by_mid(), where false would be passed explicitly so that callbacks opting into the additional argument work on both code paths.
Like #39706, the change is backward compatible: existing callbacks keep receiving exactly the arguments they registered for.
Change History (3)
This ticket was mentioned in PR #13292 on WordPress/wordpress-develop by @brianboy.
6 weeks ago
#1
- Keywords has-patch has-unit-tests added
#2
@
6 weeks ago
- Description modified (diff)
- Summary Pass $delete_all to the delete_{$meta_type}meta and deleted{$meta_type}_meta actions → Pass $delete_all to the delete_{$meta_type}_meta and deleted_{$meta_type}_meta actions
#3
@
6 weeks ago
I've opened a pull request for this: https://github.com/WordPress/wordpress-develop/pull/13292
It passes $delete_all to both the delete_{$meta_type}_meta and deleted_{$meta_type}_meta actions as an additional argument, matching the delete_{$meta_type}_metadata filter which already receives it, and includes unit tests covering both hooks.
One note for reviewers: these actions also fire in delete_metadata_by_mid(), which now passes an explicit false so that callbacks opting into the additional argument work on both code paths.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
## 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