Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
EDD Weekly Domain Report via Email
/**
* Add a weekly email report that summarizes which domains that
* your products are being used on.
*/
add_filter( 'cron_schedules', function( $schedules ) {
$schedules['weekly'] = array(
'interval' => 604800,
'display' => __('Once Weekly')
);
return $schedules;
} );
add_action('edd_send_domain_report_email', function() {
global $wpdb;
$records = $wpdb->get_results('SELECT la.site_name, l.date_created, c.name, c.email, p.post_title FROM wp_edd_license_activations la JOIN wp_edd_licenses l ON l.id = la.license_id JOIN wp_edd_customers c ON c.id = l.customer_id JOIN wp_posts p ON p.id = l.download_id WHERE l.status = "active" AND l.date_created BETWEEN date_sub(now(), INTERVAL 1 WEEK) AND now()');
$sitename = get_bloginfo('name');
$admin_email = get_option('admin_email');
$subject = "Weekly Domain Report for $sitename";
$html = "<h1>Weekly Domain Report for $sitename</h1>";
$html .= "<p>Here's the activity for the week.</p>";
$html .= "<ul>";
foreach ( $records as $record ) {
$html .= '<li>' . "<a href='mailto:$record->email'>$record->name</a>" . ' started using ' . $record->post_title . ' on ' . "<a href='https://$record->site_name'>$record->site_name</a>" . '</li>';
}
$html .= "</ul>";
$html .= "<p>Bye for now!</p>";
wp_mail($admin_email, $subject, $html);
});
if (! wp_next_scheduled ( 'edd_send_domain_report_email' )) {
wp_schedule_event(time(), 'weekly', 'edd_send_domain_report_email');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment