trash_post action with Custom Post Type

I have a Custom Post Type “empresa” and would like to send email when a post type is deleted (moved to trash).

I have this function below for my POSTS, How can I use with my Post Type “empresa”?

add_action("trash_post", "my_awesome_publication_notification");
function my_awesome_publication_notification($post_id) {
$post = get_post($post_id);
$author = get_userdata($post->post_author);

$author_email = get_post_meta( $post->ID , 'empresa_contato_email' , true );
$email_subject = "A Sua Empresa foi aprovada!";

ob_start();

include("email_header.php");

?>

<p>
    Hi, <?php echo $author->display_name ?>. I've just published one of your articles
    (<?php echo $post->post_title ?>) on MyAwesomeWebsite!
</p>

<p>
    If you'd like to take a look, <a href="https://wordpress.stackexchange.com/questions/33017/<?php echo get_permalink($post->ID) ?>">click here</a>.
    I would appreciate it if you could come back now and again to respond to some comments.
</p>

<?php

include("email_footer.php");

$message = ob_get_contents();

ob_end_clean();

wp_mail($author_email, $email_subject, $message);

}

2 Answers
2

Use wp_trash_post instead, and keep in mind {post_status}_{post_type} so originally it should have been trash_empresa not trash_post, try wp_trash_empresa too

Leave a Comment