User approval email function

User
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');

// 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

Assistant
To send an email notification when a user is approved, you can extend your `approve_user()` function by adding the necessary email functionality. Here's an updated version of your function that includes sending an email:

### 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.

User
But I think I was not acknowledged about that
Correct above sentence
Assistant
The correct version of your sentence would be:

"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.

Leave a Comment

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