#63115 closed enhancement (fixed)
wp_insert_post missing do_action for pre_post_insert
| Reported by: | Hrohh | Owned by: | audrasjb |
|---|---|---|---|
| Priority: | normal | Milestone: | 6.9 |
| Component: | Posts, Post Types | Version: | |
| Severity: | normal | Keywords: | has-patch commit |
| Cc: | Focuses: |
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.
18 months ago
#1
- Keywords has-patch added
#2
@
18 months ago
- Milestone Awaiting Review → 6.9
- Type feature request → enhancement
- Version 6.7
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
@
15 months ago
- Keywords commit added
- Owner set to
- Status new → accepted
This looks good to me. Self assigning for commit.
@audrasjb commented on PR #8527:
15 months ago
#4
I added a commit to update the since declaration.
Looks good to go.
#7
@
15 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
@
11 months 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
@
10 months 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/.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
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