Opened 7 years ago
Closed 8 months ago
#48769 closed enhancement (maybelater)
meta_input, tax_input, tags_input and post_category arguments are not available in functions or methods hooked to wp_insert_post
| Reported by: | henry.wright | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Posts, Post Types | Version: | |
| Severity: | normal | Keywords: | has-patch reporter-feedback |
| Cc: | Focuses: |
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 (8)
#2
@
7 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
@
7 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.
11 months ago
#6
@
11 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?
#7
@
8 months ago
- Milestone Awaiting Review
- Resolution → maybelater
- Status new → closed
Given that this post has been stale for too long and no feedback has been received, I will preventively close it as maybelater. @henrywright if you are still experiencing this trouble or you can provide more testing information so we can proceed with this ticket, feel free to comment here, and I will be happy to reopen it and keep working on it.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
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