I added the code snippet referenced above but am not getting the email notification of a posted response.
Here is where I inserted the snippet:
class Theme {
public function __construct( $check = false ) {
if ( $check ) {
add_action( 'wp', [ $this, 'check_theme_requirements' ] );
}
}
public function init( $options ) {
$this->constants( $options );
$this->backward_compatibility();
$this->helpers();
$this->functions();
$this->menu_walkers();
$this->admin();
$this->theme_activated();
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_action(
'admin_menu', array(
&$this,
'admin_menus',
)
);