Hello Friends, Today I am going to share how to send post approval mail to guest poster on post approval on your wordpress website. In this code I am going to use custom field (ap_author_email) to get author email used in AccessPresss Anonymous Post Plugin. You can use your custom field instead of ap_author_email.
To make it work you just have to copy and paste below code in your theme’s functions.php file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
add_action('transition_post_status', 'send_mails_on_publish', 10, 3); function send_mails_on_publish($new_status, $old_status, $post) { if ('publish' !== $new_status or 'publish' === $old_status) return; $postid = $post->ID; /* fetching email from custom field here ap_author_email is custom used in AccessPress Anonymous Post Plugin */ $emails[] = get_post_meta($postid, '<strong>ap_author_email</strong>', true); $body = sprintf('Hi Your post has been approved! See <%s>', get_permalink($post)); wp_mail($emails, 'Your Post Approved!', $body); } |
Thanks
Please share if you like
Good work, very helpful for me