Make WordPress Core

Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#22165 closed enhancement (duplicate)

pre_post_insert missing?!

Reported by: thomask's profile thomask Owned by:
Milestone: Priority: normal
Severity: trivial Version: 3.4.2
Component: General Keywords: has-patch
Focuses: Cc:

Description

For client project I need to check user role and some post variable before post is saved and if there is not proper value, i want to return him error message, so he will knew he have to change it and then save again.

Problem is, that IMO it is not possible now as there is no pre_post_insert action. There is only pre_post_update action (http://core.trac.wordpress.org/browser/tags/3.4.2/wp-includes/post.php#L2617) but that is called only on update. There are save_post and wp_insert_post actions (http://core.trac.wordpress.org/browser/tags/3.4.2/wp-includes/post.php#L2698) but they are called AFTER the post is saved. Actually i do not know how to do it (OK, i can do javascript check, but it will not work without JS) unless there will be some pre_post_insert action.

Actually this was allready requested 2 years ago http://core.trac.wordpress.org/ticket/15230, there is a patch, but nothing happens.

Change History (6)

#1 @SergeyBiryukov
12 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #15230.

#2 @nacin
12 years ago

This hook isn't actually needed for most use cases. A post created from the admin will already be in the DB as an auto-draft, thus creating a post from post-new.php is actually an "update".

#3 @thomask
12 years ago

  • Resolution duplicate deleted
  • Status changed from closed to reopened

yes, but just for only most cases. There are e.g. news which can be written in less then 3 minutes, there are sites with longering the 3 minutes autodraft or turned it off completely and I hate to rely on functions which work just on most cases, when it is trivial to solve it.

if you do not want to add another filter (why? performance issues?) and say, that anyway the pre_post_update is called in "most cases" then please consider at least reposition of pre_post_update action before if ( $update ) condition.

And btw it would be great, if this action would have one or two other parameters $postarr and $post_before, (if not update, than ID and $post_before will be NULL), so that we can easily make decision logic based on previous and future post content.

#4 @nacin
12 years ago

  • Resolution set to duplicate
  • Status changed from reopened to closed

It's still a duplicate of #15230. You can make your case there.

Also, auto-drafts cannot be turned off (and most definitely shouldn't be).

#5 follow-up: @thomask
12 years ago

if i am right, this documented (and in some cases recommended) action will turn them off / change the interval (http://codex.wordpress.org/Editing_wp-config.php#Modify_AutoSave_Interval), but OK, i will move to #15230 (i just wanted to highlight it as it is not solved issue for long time)

#6 in reply to: ↑ 5 @johnbillion
12 years ago

Replying to thomask:

if i am right, this documented (and in some cases recommended) action will turn them off / change the interval (http://codex.wordpress.org/Editing_wp-config.php#Modify_AutoSave_Interval), but OK, i will move to #15230 (i just wanted to highlight it as it is not solved issue for long time)

Just to clarify, auto-drafts and autosave are two different things. When you visit post-new.php an empty post is created and given the status of auto-draft. The post remains as an auto-draft until you manually save the post or until autosave kicks in, at which point the post becomes a draft (or whatever other status you may have chosen).

Note: See TracTickets for help on using tickets.