Opened 10 years ago
Last modified 6 weeks ago
#39706 new enhancement
Add $unique param to add_{$meta_type}_meta actions
| Reported by: | barryceelen | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Future Release |
| Component: | Options, Meta APIs | Version: | 3.1 |
| Severity: | normal | Keywords: | good-first-bug has-patch has-unit-tests |
| Cc: | Focuses: |
Description
The hooks add_{$meta_type}_meta and similar provide context about $object_id, $meta_key, $_meta_value and such, but do not tell whether the meta data added or updated is supposed to be $unique.
Adding this information could be helpful. My use case for instance is propagating meta data across posts.
Change History (6)
#2
@
2 months ago
- Keywords good-first-bug needs-patch added
- Milestone Awaiting Review → Future Release
- Version → 3.1
This ticket was mentioned in PR #12768 on WordPress/wordpress-develop by derseitenschneider.
2 months ago
#4
- Keywords has-patch has-unit-tests added; needs-patch removed
## What
Passes the $unique flag given to add_metadata() through to the add_{$meta_type}_meta and added_{$meta_type}_meta action hooks, as an additional (4th respectively 5th) argument.
## Why
Callbacks on these hooks can currently see what metadata is being added, but not whether the caller requested it to be unique for the object, even though that flag changes the semantics of the operation. The related add_{$meta_type}_metadata filter already receives $unique; this brings the actions in line with it.
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. Only callbacks that opt in to the additional argument receive it.
## Testing
New unit tests in tests/phpunit/tests/meta/addMetadata.php assert that both actions receive the $unique value for both true and false, using callbacks that opt in to the new argument count.
- New tests: 2 tests, 4 assertions, passing.
- Full
metagroup: 460 tests, 1222 assertions, passing. - PHPCS: no new issues on changed files.
- PHPStan hook docblock verification: no errors.
## Notes
@since 7.2.0was used because trunk is currently in the 7.1 beta cycle; happy to adjust.- Comment 1 on the ticket suggests similarly passing
$delete_allto thedelete_{$meta_type}_metahooks. That is left out here to keep this PR scoped to the ticket summary, and could be a follow-up.
#5
@
2 months ago
I've opened a pull request for this: https://github.com/WordPress/wordpress-develop/pull/12768
It passes $unique to both the add_{$meta_type}_meta and added_{$meta_type}_meta actions as an additional argument, matching the add_{$meta_type}_metadata filter which already receives it, and includes unit tests covering both hooks.
The $delete_all suggestion from comment:1 is intentionally not included to keep this scoped to the ticket summary. Happy to tackle that as a follow-up.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
In a similar fashion, the
delete_{$meta_type}_metacould have the$delete_allparam added.