Opened 6 years ago
Last modified 2 months ago
#48769 new enhancement
meta_input, tax_input, tags_input and post_category arguments are not available in functions or methods hooked to wp_insert_post
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Awaiting Review | Priority: | normal |
| Severity: | normal | Version: | |
| Component: | Posts, Post Types | Keywords: | has-patch reporter-feedback |
| Focuses: | Cc: |
Description
Functions and methods hooked to wp_insert_post are currently passed $post_ID, $post and $update. When a call to wp_insert_post() is made we can pass an array argument. The array can have meta_input, tax_input, tags_input and post_category elements.
Current call to do_action():
do_action( 'wp_insert_post', $post_ID, $post, $update );
Proposal:
do_action( 'wp_insert_post', $post_ID, $post, $update, $postarr );
Thoughts:
$postarr could be either the raw array passed to wp_insert_post() or the result of the raw array being merged with the set of defaults used.
There are more hooks in the wp_insert_post() function such as save_post. These could be updated in the same way for consistency.
Attachments (1)
Change History (7)
#2
@
6 years ago
- Keywords dev-feedback added
In order to make the argument data available we may need to add a new hook. Looking at the wp_insert_post() function definition I'm struggling to find a suitable existing hook
#3
@
6 years ago
- Keywords has-patch added
48769.diff introduces a new hook post_inserted in wp_insert_post().
post_inserted is very much like post_updated but it will run when a post is created only. post_inserted will give hooked functions access to the $postarr array. The existing post_updated hook has been extended so that $postarr is available to hooked functions.
This ticket was mentioned in Slack in #core by sirlouen. View the logs.
2 months ago
#6
@
2 months ago
- Keywords reporter-feedback added; dev-feedback removed
@henrywright what can you find in $postarr that you will not be able to pick from the post object at that point. I've been trying to check differences with some example and I cannot see a value that could make the difference
Rather than just theorizing about the utility of this change, can you put a specific use case example where you showcase a useful scenario of taking this extra parameter?
This may not be feasible because I notice the
wp_insert_posthook is used elsewhere and$postarrdoesn't seem to be available in that context