0

Hook publish_post, which does not necessary need to be run on post publishing only, it can be used for any post type and any post status in this format {status}_{post_type} which also makes it hard to find in wordpress core

Does anyone know where it's fired exactly in wordpress core? It does not seem to be related to wp_insert_post because it's not called when this function is run

1

As @shanebp suggested you in a comment to OP, that is one of the hook fired by the function wp_transition_post_status, it's a bit hard to find it doing a search in code because is a dynamic hook, in facts the line in code that fires it looks like:

do_action( "{$new_status}_{$post->post_type}", $post->ID, $post );

Where $new_status is the new status a post has after un update and $post->post_type is, as you can guess, the post type.

So the form "publish_post" is only one of possible hooks, fired when a post of standard post type has been published, to make an example same line in code will also fire "trash_page" when you delete a page, and so on.

As you can see in the source it is the last of status transition hooks being fired.

For the others and also for additional info look at Post Status Transitions page in Codex.

If you mind have a look, the function wp_transition_post_status is called inside the wp_insert_post function, in current version at line #3431 of wp-includes/post.php.

There you can see

if ( 'attachment' !== $postarr['post_type'] ) {
  wp_transition_post_status( $data['post_status'], $previous_status, $post );
}

making clear that function and related hooks aren't called for 'attachment' post type.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.