Skip to content

Options, Meta APIs: Pass $unique to the add_{$meta_type}_meta and added_{$meta_type}_meta actions. - #12768

Open
derseitenschneider wants to merge 2 commits into
WordPress:trunkfrom
derseitenschneider:39706-add-unique-param-to-meta-actions
Open

Options, Meta APIs: Pass $unique to the add_{$meta_type}_meta and added_{$meta_type}_meta actions.#12768
derseitenschneider wants to merge 2 commits into
WordPress:trunkfrom
derseitenschneider:39706-add-unique-param-to-meta-actions

Conversation

@derseitenschneider

Copy link
Copy Markdown

Trac ticket: https://core.trac.wordpress.org/ticket/39706

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 meta group: 460 tests, 1222 assertions, passing.
  • PHPCS: no new issues on changed files.
  • PHPStan hook docblock verification: no errors.

Notes

  • @since 7.2.0 was used because trunk is currently in the 7.1 beta cycle; happy to adjust.
  • Comment 1 on the ticket suggests similarly passing $delete_all to the delete_{$meta_type}_meta hooks. That is left out here to keep this PR scoped to the ticket summary, and could be a follow-up.

…ed_{$meta_type}_meta actions.

The $unique flag passed to add_metadata() was not exposed to the
add_{$meta_type}_meta and added_{$meta_type}_meta action hooks, so
callbacks could not tell whether the metadata being added was meant to
be unique for the object. Pass it as an additional argument, matching
the add_{$meta_type}_metadata filter which already receives it.
Copilot AI review requested due to automatic review settings July 30, 2026 11:33
@github-actions

github-actions Bot commented Jul 30, 2026

Copy link
Copy Markdown

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 props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props brianboy.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the core Metadata API so that the $unique flag passed to add_metadata() is forwarded to the dynamic action hooks fired before/after insertion, aligning the action signatures with the existing add_{$meta_type}_metadata filter.

Changes:

  • Pass $unique as an additional argument to add_{$meta_type}_meta (4th arg) and added_{$meta_type}_meta (5th arg).
  • Update the corresponding hook docblocks to document the new argument and @since tag.
  • Add PHPUnit coverage verifying both actions receive the correct $unique value for true and false.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/wp-includes/meta.php Forwards $unique into the relevant add_*_meta/added_*_meta actions and updates hook documentation.
tests/phpunit/tests/meta/addMetadata.php Adds unit tests ensuring the action callbacks receive the $unique flag when opting into the new accepted-args count.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/wp-includes/meta.php Outdated
* @since 2.9.0
* @since 7.2.0 The `$unique` parameter was added.
*
* @param int $mid The meta ID after successful update.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 3e6927a

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The 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

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Copilot AI review requested due to automatic review settings July 30, 2026 12:42

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants