[wp-hackers] applying a filter to when a new post is made

Scott Reilly coffee2code at scottreilly.net
Mon Aug 9 23:19:53 UTC 2004


From what I gather in the code,  'publish_post' and 'edit_post' are triggered 
at the end of those respective events.  The post has by then been 
published/edited and stored into the database.

Those particular events are handled differently than the usual filter usage 
(i.e. add_filter('the_content', myFunction); ) where your function is defined 
as: function myFunction ($text)

When hooking these two actions, your function will be sent the postID, not its 
content.  Therefore, if you want to manipulate the post when it gets 
published/edited, your plugin will have to accept the postID (i.e. function 
myFunction ($post_ID)) and use it to retrieve the post from the database, and 
then store it back into the database when you're done.

Then again, I haven't tried it myself... yet.

-Scott
http://www.coffee2code.com



On Monday 09 August 2004 06:13 pm, Giacomo Lacava wrote:
> Chuck Guenther wrote:
> > add_action('publish_post', 'functionName', 0);
> > add_action('edit_post', 'functionName', 0);
>
> I'll jump on this thread to ask for some clarifications...
>
> When does WP actually call these two interfaces, "publish_post" and
> "edit_post"? is it _before_ publishing/editing (that is, committing
> changes to db) or _after_ the fact?
>
> I ask because I'm writing a simple version control plugin right now :)
> If it's like I hope, these hooks are invoked before actually committing
> the new data to the db, and my plugin is almost done ;) otherwise I'm
> back to the drawing board.
>
> Giacomo
> (who's becoming strangely addicted to WP plugin scripting)



More information about the hackers mailing list