Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Hello i'm using this :

add_action('publish_post', 'send_admin_email'); function send_admin_email($post_id){
    $to = 'admin@email.here';
    $subject = 'subject';
    $message = "Here is :".get_permalink($post_id);
    wp_mail($to, $subject, $message );

to send out a mail to wordpress admin when a post is publish by author. And I would like to add the post author in $message.

I try get_the_author(); and the_author(); but nothing happens.

Any ideas guys ?

Thank u !

(Sorry i'm french)

share|improve this question
add comment

1 Answer 1

Missing global ?

global $post;

No global variable available if you are using publish_post action hook!

Ref : http://hungred.com/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

share|improve this answer
    
Like that ? : add_action('publish_post', 'send_admin_email'); function send_admin_email($post_id){global $post; $to = 'admin@email.here'; $subject = 'subject'; $message = "The author is :".get_the_author(); wp_mail($to, $subject, $message ); –  Cat Oct 24 '12 at 13:32
    
I'm french so i don't understand your Ref very well. Sorry. :s –  Cat Oct 24 '12 at 13:34
    
I forgot to say, my code work perfectly but i want to "add" the author in the mail. –  Cat Oct 24 '12 at 13:49
    
Edited, check it out my answer @Cat –  l2aelba Oct 24 '12 at 13:53
    
I try this add_action('publish_post', 'send_admin_email'); function send_admin_email($post_id){ $to = 'adress@email.fr'; $subject = "Un nouveau contrat SMP-PRO a été enregistré par".get_userdata($post->post_author); $message = "Sandra, le dossier ".get_the_title($post_id)." est visible sur cette page : ".get_edit_post_link( $id, $context ); wp_mail($to, $subject, $message ); } but it's not working… :( –  Cat Oct 24 '12 at 14:04
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.