Created
May 16, 2020 17:29
-
-
Save codename065/9787c4703ea1208a9bcf29d62538d1c9 to your computer and use it in GitHub Desktop.
Send update notification to the users who previously downloaded the package
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function wpdm_send_update_notification($ID, $post, $update){ | |
global $wpdb; | |
if (get_post_type() != 'wpdmpro' || wp_is_post_revision( $ID ) || $post->post_status !== 'publish') return; | |
$users = $wpdb->get_results("select uid from {$wpdb->prefix}ahm_download_stats where pid = '{$ID}' and uid != 0"); | |
$emails = []; | |
foreach ($users as $user){ | |
if((int)$user->uid > 0) | |
$emails[] = get_user_by('ID', $user->uid)->user_email; | |
} | |
$link = get_permalink($ID); | |
$title = get_the_title($ID); | |
$params = [ | |
'to' => "noreply@yourdomain.com", | |
'from' => "admin@yourdomainn.com", | |
'bcc' => implode(",", $emails), | |
'subject' => "Updated: ".$title, | |
'message' => "Hello,<br/>There is an update available for the following item:<br/><a href='{$link}'>{$title}</a>" | |
]; | |
\WPDM\Email::send("default", $params); | |
} | |
add_action('save_post', 'wpdm_send_update_notification', 10, 3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment