I’ve just been looking into some WordPress code that needs to run only when a post is first published.
WordPress provides a number of hooks for post status transitions. You’d think the one to use would be
post_publish. However, testing shows that this also fires when a post is updated. Also, consider the scenario where an editor sets a post back to draft, then re-publishes. Do you also want the code to run then?