Skip to content

Posts, Post Types: Pass the original array of arguments to hooks that fire within wp_insert_post() - #14796

Open
irozum wants to merge 2 commits into
WordPress:trunkfrom
irozum:enhancement/60038-pass-unsanitized-postarr-to-insert-post-hooks
Open

irozum wants to merge 2 commits into
WordPress:trunkfrom
irozum:enhancement/60038-pass-unsanitized-postarr-to-insert-post-hooks

Conversation

@irozum

@irozum irozum commented Oct 23, 2026

Copy link
Copy Markdown

Passes the original array of arguments given to wp_insert_post() ($unsanitized_postarr) as a trailing argument to the actions and filters that fire within it, matching what wp_insert_post_data and wp_insert_attachment_data have received since 5.4.1. This lets callbacks see custom keys such as tax_input, meta_input or plugin-specific arguments that are otherwise lost.

Hooks updated inside wp_insert_post()

  • Filter: add_trashed_suffix_to_trashed_posts
  • Actions: pre_post_update, edit_attachment, attachment_updated, add_attachment, edit_post_{$post_type}, edit_post, post_updated, save_post_{$post_type}, save_post, wp_insert_post

Other places these hooks fire
As noted by @johnbillion on the ticket, some of these hooks also fire outside wp_insert_post(): in wp_publish_post(), WP_Customize_Manager::trash_changeset_post() and wp_update_comment_count_now(). Those call sites now pass an empty array(), so a callback registered with the extra argument never hits an ArgumentCountError. The docblocks say the array is empty when the hook fires outside of wp_insert_post().

Notes

  • Existing arguments are not reordered; the new argument is always last.
  • The @since version is set to 7.3.0, since 7.2 is past feature freeze. A committer may adjust it.
  • Third-party code that fires these hooks itself without the new argument would trigger an ArgumentCountError in callbacks that require it, the same trade-off as when $update was added to save_post in 3.7.0. A dev note may be worthwhile.
  • phpstan.neon.dist gets a narrowly scoped ignore: PHPStan conflates the edit_post_{$post_type} action with the unrelated edit_post_{$field} filter in sanitize_post_field() because both normalise to edit_post_{...}.
  • Props to rizwan_47, sukhendu2002, marukou1976 and mrhatia for the earlier patches on the ticket.

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

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Sonnet 5.5
Used for: Implementation, tests, and PR description.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

🤖 Generated with Claude Code

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

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

Props irozum.

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


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@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