I just realised that in wp-includes/post.php
(source), at the end of wp_insert_post()
, both the save_post
and wp_insert_post
actions are called one after the other, with the exact same parameters:
3520 /**
3521 * Fires once a post has been saved.
3522 *
3523 * @since 1.5.0
3524 *
3525 * @param int $post_ID Post ID.
3526 * @param WP_Post $post Post object.
3527 * @param bool $update Whether this is an existing post being updated or not.
3528 */
3529 do_action( 'save_post', $post_ID, $post, $update );
3530
3531 /**
3532 * Fires once a post has been saved.
3533 *
3534 * @since 2.0.0
3535 *
3536 * @param int $post_ID Post ID.
3537 * @param WP_Post $post Post object.
3538 * @param bool $update Whether this is an existing post being updated or not.
3539 */
3540 do_action( 'wp_insert_post', $post_ID, $post, $update );
Nothing happens between them, so there appears to be no difference between using one or the other.
The same redundancy is repeated a little further down in wp_publish_post()
(source), and the oldest tracked version of the file also has the same two actions (thanks toscho for pointing these out).
Am I missing something? Why are they both there, and if I am choosing an action to use, is there a reason to choose one over the other?
wp_insert_post
was added later as a way to make hook names within functions guessable?wp_publish_post()
. And there, the same redundancy exists.