I am currently building a wordpress plugin to send email notification to list of users roles who comments on a post.
For Example:
If a user with "subscriber" role comments on a post all the other users who have "subscriber" role gets email alert.Currently i have achieved this through the following code
if( current_user_can('subscriber'))
{
$user_query = new WP_User_Query( array( 'role' => 'subscriber');
foreach ( $user_query->results as $user )
{
$mail=$user->user_email;
$subject ="this is example";
$message = "";
$message .= "$post_permalink\n";
wp_mail($user->user_email, $subject,$message);
}
}
The above code sends email to all the users who have "subscriber" role.
Output:
It gets even the current user who comments on the post and send the email notification.
Problem to be solved:
How can i exclude the current user email and send only notification to other users those who have "subscriber" role .