admin管理员组文章数量:1130349
I have this answer in reference :
It sends to all users.
I want to notify the author of the post only when author's custom post type gets published.
Please help thanks
I have this answer in reference :
https://wordpress.stackexchange/a/100657/145078
It sends to all users.
I want to notify the author of the post only when author's custom post type gets published.
Please help thanks
Share Improve this question asked Nov 7, 2018 at 15:53 user145078user1450781 Answer
Reset to default 0This should work — make sure to change my_custom_type to the correct CPT slug:
add_action( 'transition_post_status', 'notify_author_on_publish', 10, 3 );
function notify_author_on_publish( $new_status, $old_status, $post ) {
if ( 'publish' !== $new_status ||
$new_status === $old_status ||
'my_custom_type' !== get_post_type( $post ) ) {
return;
}
// Get the post author data.
if ( ! $user = get_userdata( $post->post_author ) ) {
return;
}
// Compose the email message.
$body = sprintf( 'Hey %s, your awesome post has been published!
See <%s>',
esc_html( $user->display_name ),
get_permalink( $post )
);
// Now send to the post author.
wp_mail( $user->user_email, 'Your post published!', $body );
}
I have this answer in reference :
It sends to all users.
I want to notify the author of the post only when author's custom post type gets published.
Please help thanks
I have this answer in reference :
https://wordpress.stackexchange/a/100657/145078
It sends to all users.
I want to notify the author of the post only when author's custom post type gets published.
Please help thanks
Share Improve this question asked Nov 7, 2018 at 15:53 user145078user1450781 Answer
Reset to default 0This should work — make sure to change my_custom_type to the correct CPT slug:
add_action( 'transition_post_status', 'notify_author_on_publish', 10, 3 );
function notify_author_on_publish( $new_status, $old_status, $post ) {
if ( 'publish' !== $new_status ||
$new_status === $old_status ||
'my_custom_type' !== get_post_type( $post ) ) {
return;
}
// Get the post author data.
if ( ! $user = get_userdata( $post->post_author ) ) {
return;
}
// Compose the email message.
$body = sprintf( 'Hey %s, your awesome post has been published!
See <%s>',
esc_html( $user->display_name ),
get_permalink( $post )
);
// Now send to the post author.
wp_mail( $user->user_email, 'Your post published!', $body );
}
本文标签: Send email to author of the post when the custom post status changes to published
版权声明:本文标题:Send email to author of the post when the custom post status changes to published 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749199454a2331550.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论