Send email to admin with post author

I'm using the following to send an email to the admin when a post is publish by anauthor:add_action('publish

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.

Share Improve this question edited May 13, 2019 at 15:27 butlerblog 5,1313 gold badges28 silver badges44 bronze badges asked Oct 24, 2012 at 12:56 CatCat 12 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 1

Missing 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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745498957a4630323.html

相关推荐

  • Send email to admin with post author

    I'm using the following to send an email to the admin when a post is publish by anauthor:add_action('publish

    1天前
    50

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信