We have a claim listing plugin, it allows items(posts) to be claimed by users. It requires the user to “register” in order to claim that item therefore they have to enter a username and their email.
After they have submitted a claim, an email will be sent to the admin email(us) that a user is claiming for the item and gives us the option to approve or deny it.
When we approve or deny it, unfortunately no email is sent to the user informing them that the item has been approved or denied.
How could we get wordpress to send an email to the user informing them of our response?
Code: CodeShare (the code is too long and is breaking when I paste it here guys, sorry!)
As you can see, there is a wp_mail functionality in there but that’s for when an email is sent to the admin that a request of an item ownership has been requested)
This seems to be function with the issue(code below), what do we then need to add to send an email to the user to say that their request has been approved?
public static function claimListingActions(){
if(isset($_GET['post_type']) && $_GET['post_type'] === 'ait-item'){
if (isset($_GET['claim-action']) && !empty($_GET['post-id'])) {
$postID = intval($_GET['post-id']);
// admin can approve all ratings
if (current_user_can('manage_options')) {
switch($_GET['claim-action']){
case 'approve':
$redirect = admin_url('edit.php?post_type=ait-item&ait-notice=claim-approved');
$data = get_post_meta($postID, 'ait-claim-listing', true);
$data['status'] = 'approved';
update_post_meta($postID, 'ait-claim-listing', $data);
$user = get_user_by('email', $data['owner']);
// update also the _ait-item_item-author data field -> prevent errors
update_post_meta($postID, '_ait-item_item-author', array('author' => $user->ID));
wp_update_post( array('ID' => $postID, 'post_author' => $user->ID), true );
break;
case 'decline':
$redirect = admin_url('edit.php?post_type=ait-item&ait-notice=claim-declined');
$data = get_post_meta($postID, 'ait-claim-listing', true);
$data['status'] = 'unclaimed';
$data['owner'] = '-';
$data['date'] = '-';
update_post_meta($postID, 'ait-claim-listing', $data);
$user = new WP_User($data['author']);
// update also the _ait-item_item-author data field -> prevent errors
update_post_meta($postID, '_ait-item_item-author', array('author' => $user->ID));
wp_update_post( array('ID' => $postID, 'post_author' => $user->ID) );
break;
}
wp_safe_redirect( $redirect );
exit();
}
}
}
}