Notify new post on page

时间:2014-09-05 作者:Casper

如果有新帖子,是否有方法在仪表板页面上通知?还是只有在wp_mail();

谢谢卡斯珀

1 个回复
SO网友:Tomás Cot

您可以使用publish_post 操作,该操作在发布帖子时触发。知道了这一点,您可以创建一个函数并在publish_post 使用add_action 作用

文档中的示例:

function post_published_notification( $ID, $post ) {
    $author = $post->post_author; /* Post author ID. */
    $name = get_the_author_meta( \'display_name\', $author );
    $email = get_the_author_meta( \'user_email\', $author );
    $title = $post->post_title;
    $permalink = get_permalink( $ID );
    $edit = get_edit_post_link( $author, \'\' );
    $to[] = sprintf( \'%s <%s>\', $name, $email );
    $subject = sprintf( \'Published: %s\', $title );
    $message = sprintf (\'Congratulations, %s! Your article “%s” has been published.\' . "\\n\\n", $name, $title );
    $message .= sprintf( \'View: %s\', $permalink );
    $headers[] = \'\';
    wp_mail( $to, $subject, $message, $headers );
}

add_action( \'publish_post\', \'post_published_notification\', 10, 2 );

结束