Adding a button to send email to a user in WordPress Admin Users table

I would like to add a button for each user in the user page in wordpress admin area that will send an email to that specific user when clicked.

The code adds the action link “Send Verification Email” to each user in the table. But for some reason, the email is only sent to the user on the first row. It is not sent to the other users when I click the “Send Verification Email” on their row.

The strange thing though is that when I use this code on my development site, the email is sent to every user there. I only have about 6 users registered on the development site while my main site has over 200 users. I am not sure the number of registered users is causing the problem since the email is sent to a specific user when the button is clicked on that user’s row.

What am I doing wrong that is causing the issue. Any ideas?

P.S. I am not a coder, I saw this code online and only tried to modify it to my requirements. I will appreciate it if you can provide me with a working solution and not just a comment.

// Adds “Send verification email” action to Users page
function send_verification_email_link($actions, $user_object) {
if( ($_GET[‘action’] == ‘send_verification_email’) && ($_GET[‘user’] == $user_object->user_email) ) {

$my_logo = “<img src=’https://example.com/’ alt=’logo’ />”;
$sendto = $_GET[‘user’];
$subject = ‘Your Example Account is not yet verified’;
$headers = array(‘Content-Type: text/html; charset=UTF-8’);

$message = ‘<p style=”text-align: center;”>’.$my_logo.'</p>

<div style=”max-width: 600px; margin: 30px auto; padding: 15px; font-family: Roboto,Open Sans,Helvetica,Arial; border: 1px solid #e8e8e8; line-height: 1.6; text-align: center; background-color: white;”>

<div style=”text-align: left;”>
<p>Hi ‘.$user_object->first_name.’,</p>

<p>Thank you for registering your business on Example.com. Your account is not yet verified because you have not provided the verification information or the information you provided is invalid. Please provide the necessary information below to get verified:</p>

<p><strong>Private person:</strong></p>
<ul>
<li>Upload a profile photo.</li>
<li>Upload an identification document.</li>
</ul>

<p><strong>Company:</strong></p>
<ul>
<li>Upload a profile photo.</li>
<li>Upload an identification document.</li>
<li>Provide your registered company name.</li>
<li>Provide your company registration number.</li>
</ul>

<a style=”text-align: center;” href=”https://example.com/login/” rel=”noopener noreferrer” target=”_blank”>Click here to login to your account.</a>

<p>When you are logged in, click the settings icon on your profile page and click edit profile. Scroll to the verification section to provide the verification information.</p>

<p>Please let us know if you have any questions.</p>

<p>Kind regards,<br>Example Team</p>

</div>
</div>

wp_mail($sendto, $subject, $message, $headers);
echo ‘<div class=”updated notice”><p>Success! The verification email has been sent to ‘ . $_GET[‘user’] . ‘.</p></div>’;
}

$actions[‘send_rejection’] = “<a class=’send_verification_email’ href='” . admin_url( “users.php?action=send_verification_email&amp;user=” . $user_object->user_email ) . “‘>” . __( ‘Send Verification Email’ ) . “</a>”;
return $actions;
}
add_filter(‘user_row_actions’, ‘send_verification_email_link’, 10, 2);

Read more here:: Adding a button to send email to a user in WordPress Admin Users table

Leave a Reply

Your email address will not be published. Required fields are marked *