包括发布WordPress-电子邮件通知内容

时间:2018-09-12 作者:Jesus García Lopera

我有这封新邮件的通知。

所有新帖子包含大约100个单词,没有图片,所以我想在通知中包括帖子内容,如果可能的话,还包括帖子中的单词数。

有人能帮我吗?

谢谢大家

    /* avisar al admin*/
function submit_send_email ($post) {

        $user_info = get_userdata ($post->post_author);
        $strTo = array (\'[email protected]\');
        $strSubject = \'Your website name: \' . $user_info->user_nicename . \' submitted a post\';
        $strMessage = \'A post "\' . $post->post_title . \'" by \' . $user_info->user_nicename . \' was submitted for review at \' . wp_get_shortlink ($post->ID) . \'&preview=true. Please proof.\';
        wp_mail( $strTo, $strSubject, $strMessage );

}
add_action(\'future_to_pending\', \'submit_send_email\');
add_action(\'new_to_pending\', \'submit_send_email\');
add_action(\'draft_to_pending\', \'submit_send_email\');
add_action(\'auto-draft_to_pending\', \'submit_send_email\');

2 个回复
SO网友:mpes.

使用此功能:

function word_count() {
    $content = get_post_field( \'post_content\', $post->ID );
    $word_count = str_word_count( strip_tags( $content ) );
    return $word_count;
}
然后调用它以显示字数:

echo word_count();

SO网友:mpes.

我找到了更好的解决方案

function bavotasan_word_count() {
   return sprintf(
      __( \'%s words\', \'text-domain\' ),
      str_word_count( strip_tags( get_post_field( \'post_content\', get_the_ID() ) ) )
   );
}
了解更多如何使用它function bavotasan_word_count()

结束

相关推荐