admin管理员组文章数量:1024924
I'm using the following to send an email to the admin when a post is publish by an author:
add_action('publish_post', 'send_admin_email'); function send_admin_email($post_id){
$to = '[email protected]';
$subject = 'subject';
$message = "Here is :".get_permalink($post_id);
wp_mail($to, $subject, $message );
I would like to add the post author in $message
.
I try get_the_author();
and the_author();
but nothing happens.
I'm using the following to send an email to the admin when a post is publish by an author:
add_action('publish_post', 'send_admin_email'); function send_admin_email($post_id){
$to = '[email protected]';
$subject = 'subject';
$message = "Here is :".get_permalink($post_id);
wp_mail($to, $subject, $message );
I would like to add the post author in $message
.
I try get_the_author();
and the_author();
but nothing happens.
1 Answer
Reset to default 1Missing global ?
global $post;
No global variable available if you are using publish_post action hook!
Ref : http://hungred/how-to/tutorial-post-id-publishpost-action-hook-wordpress/
Update 2 :
or try this
$author = get_userdata($post->post_author);
So you can use $author
where you will :D
I'm using the following to send an email to the admin when a post is publish by an author:
add_action('publish_post', 'send_admin_email'); function send_admin_email($post_id){
$to = '[email protected]';
$subject = 'subject';
$message = "Here is :".get_permalink($post_id);
wp_mail($to, $subject, $message );
I would like to add the post author in $message
.
I try get_the_author();
and the_author();
but nothing happens.
I'm using the following to send an email to the admin when a post is publish by an author:
add_action('publish_post', 'send_admin_email'); function send_admin_email($post_id){
$to = '[email protected]';
$subject = 'subject';
$message = "Here is :".get_permalink($post_id);
wp_mail($to, $subject, $message );
I would like to add the post author in $message
.
I try get_the_author();
and the_author();
but nothing happens.
1 Answer
Reset to default 1Missing global ?
global $post;
No global variable available if you are using publish_post action hook!
Ref : http://hungred/how-to/tutorial-post-id-publishpost-action-hook-wordpress/
Update 2 :
or try this
$author = get_userdata($post->post_author);
So you can use $author
where you will :D
本文标签: Send email to admin with post author
版权声明:本文标题:Send email to admin with post author 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745498954a2153299.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论