#63115 closed enhancement (fixed)
wp_insert_post missing do_action for pre_post_insert
| Reported by: | | Owned by: | |
|---|---|---|---|
| Milestone: | 6.9 | Priority: | normal |
| Severity: | normal | Version: | |
| Component: | Posts, Post Types | Keywords: | has-patch commit |
| Focuses: | Cc: |
Description
Hi, it is possible add new action
https://github.com/WordPress/wordpress-develop/blob/6.7/src/wp-includes/post.php#L4382-L5078
to line 4792
<?php do_action( 'pre_post_insert', $data );
like we have in update
<?php do_action( 'pre_post_update', $post_id, $data );
It would be usefull for detection duplicate content in database for example. We can rewire our post_id.
Change History (10)
This ticket was mentioned in PR #8527 on WordPress/wordpress-develop by @sainathpoojary.
8 months ago #1
- Keywords has-patch added
#2
@
8 months ago
- Milestone changed from Awaiting Review to 6.9
- Type changed from feature request to enhancement
- Version 6.7 deleted
I can see how this would be useful for consistency with the actions for updating a post.
As it's an enhancement, it won't be possible to get in to WordPress 6.8 so I've added it to the milestone for WordPress 6.9.
#3
@
6 months ago
- Keywords commit added
- Owner set to audrasjb
- Status changed from new to accepted
This looks good to me. Self assigning for commit.
@audrasjb commented on PR #8527:
6 months ago #4
I added a commit to update the since declaration.
Looks good to go.
#7
@
6 months ago
@audrasjb Since it is an action, how would this allow for developers to modify the data prior to insertion?
For modification wouldn't the the wp_insert_post_data filter be used for this? It gets applied for inserts as well as updates.
In any case, having an action to compliment pre_post_update seems to make sense.
#9
@
5 weeks ago
I agree with @westonruter, the wp_insert_post_data filter is indeed the right place for developers to modify data before insertion or update.
I also think having a pre_post_insert action would be valuable. It could serve as a companion to pre_post_update, allowing developers to run additional logic before a new post is inserted.
For example, one practical use case would be enforcing a unique post title cross the site for a specific post type. The pre_post_insert action would make this type of validation straightforward to implement.
#10
@
4 days ago
The miscellaneous developer-focused changes developer note mentioned that the new pre_insert_post hook was introduced in [60293]: https://make.wordpress.org/core/2025/11/17/miscellaneous-developer-focused-changes-in-6-9/.
This PR introduces the pre_post_insert hook, allowing developers to modify or inspect post data before insertion, similar to pre_post_update. This enhances flexibility for use cases like duplicate content detection.
Trac ticket: #63115