Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Sends an email to the review author (or a custom email) when their review has been approved.
- * Paste this in your active theme's functions.php file.
- *
- * @param string $oldStatus
- * @param string $newStatus
- * @param \WP_Post $post
- * @return void
- * @action transition_post_status
- */
- add_action('transition_post_status', function ($newStatus, $oldStatus, $post) {
- if (in_array($oldStatus, ['new', $newStatus])
- || 'site-review' != $post->post_type
- || 'publish' != $post->post_status) {
- return;
- }
- $review = apply_filters('glsr_get_review', null, $post->ID);
- // Start: change these values as needed
- $email = $review->email;
- $subject = "Your review has been published!";
- $message = "Thank you so much for your review! Just letting you know that it's now live on our website.";
- // End
- $metaKey = '_sent_approved_notification';
- $alreadySentNotification = get_post_meta($post->ID, $metaKey, true);
- if (!empty($email) && !$alreadySentNotification) {
- if ($sent = wp_mail($email, $subject, $message)) {
- update_post_meta($post->ID, $metaKey, true);
- } else {
- apply_filters('glsr_log', null, 'The notification to <'.$email.'> was not sent. Please verify that your server is able to send emails correctly through WordPress.');
- }
- }
- }, 10, 3);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement