User approval email function
November 15, 2024 ยท AI Conversations
if (isset($_GET['action']) && $_GET['action'] === 'userwp_approve_user' && !empty($_GET['user_id'])) {
$user_id = intval($_GET['user_id']);
// Update 'aiowps_account_status' to allow login
update_user_meta($user_id, 'aiowps_account_status', 'active');
// Optional: Add a success notice
add_action('admin_notices', function() {
echo 'User approved successfully!';
});
wp_redirect(admin_url('admin.php?page=userwp-user-approval'));
exit;
}
}
also send an email that approved
### Updated `approve_user()` Function
function approve_user() {
if (isset($_GET['action']) && $_GET['action'] === 'userwp_approve_user' && !empty($_GET['user_id'])) {
$user_id = intval($_GET['user_id']);
// Update 'aiowps_account_status' to allow login
update_user_meta($user_id, 'aiowps_account_status', 'active');
// Get user information
$user_info = get_userdata($user_id);
$user_email = $user_info->user_email;
$user_name = $user_info->display_name;
// Send approval email
$subject = 'Your Account Has Been Approved';
$message = "Hello $user_name,nnYour account has been successfully approved. You can now log in using your credentials.nnThank you,nTeam";
// Use wp_mail to send the email
wp_mail($user_email, $subject, $message);
// Optional: Add a success notice
add_action('admin_notices', function() {
echo '<div class="updated"><p>User approved successfully!</p></div>';
});
// Redirect back to the user approval page
wp_redirect(admin_url('admin.php?page=userwp-user-approval'));
exit;
}
}
### Explanation
1. **User Information**: I added a section to retrieve the user's email and display name using `get_userdata($user_id)`.
2. **Email Notification**: The `wp_mail()` function sends an email to the user notifying them that their account has been approved.
– **Subject**: "Your Account Has Been Approved".
– **Message**: A simple text message notifying the user of their account approval.
3. **Redirect and Notices**: The rest of the code remains the same, with a notice for successful approval and a redirect to the admin page.
### Additional Tips
– Make sure your WordPress site is configured to send emails (you may need to set up SMTP if emails are not being sent).
– If you want to use HTML formatting in your email, you can add a `headers` parameter:
$headers = ['Content-Type: text/html; charset=UTF-8'];
wp_mail($user_email, $subject, $message, $headers);
This will allow you to send a more stylized email if needed.
Correct above sentence
"But I don't think I was informed about that."
or
"I don't think I was made aware of that."
These versions are clearer and more grammatically correct.