最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Send email to admin with post author

programmeradmin2浏览0评论

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

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论