Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Send an email notification to the review author after responding to a review
- * Paste this code in your theme’s functions.php file.
- * @param \GeminiLabs\SiteReviews\Review $review
- * @param string $response
- * @return void
- */
- add_action('site-reviews/review/responded', function ($review, $response) {
- $hasResponse = !empty($review->response);
- $hasResponseUserId = !empty(get_post_meta($review->ID, '_response_by', true));
- if (empty($response) || $hasResponse || $hasResponseUserId) {
- return; // only send an email if the response is not empty and there is no previous response
- }
- if (empty($review->email)) {
- return; // this review has not been submitted with an email
- }
- if (empty($review->assigned_posts)) {
- return; // this review has not been assigned to any Post
- }
- $postId = $review->assigned_posts[0]; // Get the first assigned Post ID
- $permalink = get_permalink($postId); // Get the permalink of the assigned Post
- $subject = sprintf('[%s], We have responded to your review!', get_bloginfo('name'));
- $message = sprintf('Just letting you know that we have <a href="%s">responded to your review</a>!', $permalink);
- $email = glsr('Modules\Email')->compose([
- 'to' => $review->email,
- 'subject' => $subject,
- 'message' => $message,
- ]);
- $email->send();
- }, 10, 2);
Add Comment
Please, Sign In to add comment