Make WordPress Core

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 brianboy)

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

## What

Passes the $delete_all flag given to delete_metadata() through to the delete_{$meta_type}_meta and deleted_{$meta_type}_meta action hooks as an additional (5th) argument. delete_metadata_by_mid(), which fires the same actions, passes an explicit false.

## Why

When $delete_all is true, matching metadata is deleted for all objects and the $object_id passed to these hooks is ignored — but callbacks currently have no way to know that. The delete_{$meta_type}_metadata short-circuit filter already receives $delete_all; this brings the actions in line with it, following the same approach as #39706 / PR #12768 did for $unique on the add actions.

Passing an explicit false in delete_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.php assert that both actions receive $delete_all for both true and false, and that they receive false when deleting via delete_metadata_by_mid().

  • New tests: 3 tests, 6 assertions, passing
  • Full meta group: 461 tests, 1224 assertions, passing
  • PHPCS: no new issues on changed files
  • PHPStan: no new errors (only pre-existing baseline drift in unrelated files)

## Notes

@since 7.2.0 matches the version used in PR #12768; happy to adjust.

​https://claude.ai/code/session_01Bjv7bM9MF844TKLMqueyF7

#2 @brianboy
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 @brianboy
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.

Note: See TracTickets for help on using tickets.