Skip to content

Options, Meta APIs: Pass $delete_all to the delete_{$meta_type}_meta and deleted_{$meta_type}_meta actions. - #13292

Open
derseitenschneider wants to merge 1 commit into
WordPress:trunkfrom
derseitenschneider:65976-pass-delete-all-to-delete-meta-actions
Open

Options, Meta APIs: Pass $delete_all to the delete_{$meta_type}_meta and deleted_{$meta_type}_meta actions.#13292
derseitenschneider wants to merge 1 commit into
WordPress:trunkfrom
derseitenschneider:65976-pass-delete-all-to-delete-meta-actions

Conversation

@derseitenschneider

Copy link
Copy Markdown

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

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

…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
@github-actions

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.

@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.

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.

1 participant