下面我列出了您可以使用的两个挂钩。可能会有更好的挂钩,具体取决于您想要完成什么,但这是您所要求的。在底部,我列出了一些有用的资源:
Publish Post Hook
http://codex.wordpress.org/Plugin_API/Action_Reference/publish_post
function published_post( $ID, $post ) {
if( $post->post_type == \'post\' ) {
...
}
if( $post->post_type == \'page\' ) {
...
}
}
add_action( \'publish_post\', \'published_post\', 10, 2 );
Comment Post Hook
function maybe_published_comment( $ID, $approval_bool ) {
...
}
add_action( \'comment_post\', maybe_published_comment, 10, 2 );
Resources
- Action Reference
- Developer Reference
- WP_Publish_Post()
- Comment Post Hook