[wp-hackers] Best Practice for hooking wp_insert_post()
wp at andrewnacin.com
Sat Jul 24 20:54:39 UTC 2010
On Sat, Jul 24, 2010 at 2:49 PM, Mark E <mark at simplercomputing.net> wrote:
> On 07/24/2010 08:14 AM, Mike Schinkel wrote:
>> Hi all:
>> I'd like to ask about best practices for hooking wp_insert_post().
>> The questions are when and why to use "save_post" vs.
>> "wp_insert_post" and more importantly what's the best way to
>> determine if a post is being added or updated, or is an auto-post?
>> Actually, I'd love to have that all clarified.
> If I remember right, auto-draft is a copy of post saved automatically while
> the WP post screen is open, and that particular save process is driven by
Auto-drafts are new in 3.0. They're designed to prevent the need to wait for
an autosave, which is what you're describing. The moment you visit the
post-new.php screen, you now have a post ID in the form of an auto-draft.
This allows you to immediately attach media, work with custom fields,
featured images, and the like. The auto-drafts that don't turn into posts
are then cleaned up after a week or so.
Here's the ticket we managed the development of this in:
It does have the side effect of triggering save_post. The post status
transition hooks are probably better to use in most cases however.
More information about the wp-hackers