Skip to content

Instantly share code, notes, and snippets.

@damiencarbery
Created June 17, 2020 21:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save damiencarbery/0cc44905d38ef47f6378917106fc7e34 to your computer and use it in GitHub Desktop.
Save damiencarbery/0cc44905d38ef47f6378917106fc7e34 to your computer and use it in GitHub Desktop.
<?php
/*
Plugin Name: Weekly email
Plugin URI: http://www.damiencarbery.com
Description: Project status weekly automated email.
Author: Damien Carbery
Version: 0.1
*/
// Set up the scheduled task when the plugin is activated.
register_activation_hook(__FILE__, 'dcwd_status_setup_schedule');
function dcwd_status_setup_schedule() {
if ( ! wp_next_scheduled( 'dcwd_status_status_email' ) ) {
// Schedule weekly at 2:12am.
wp_schedule_event( mktime(2,12,0), 'weekly', 'dcwd_status_status_email');
}
}
add_action('dcwd_status_status_email', 'dcwd_project_send_status_email');
/**
* On the scheduled action hook, run a function.
*/
function dcwd_project_send_status_email() {
$subject = 'Weekly Project Status';
$table_styles = '<style type="text/css">p { padding: 5px; }</style>'; // Add CSS if needed
// Do your CF7 DB query here.
$message = '<p>This is the list of tasks that need attention.</p><p>&nbsp;</p>'.$table_styles.;
add_filter( 'wp_mail_content_type', 'dcwd_status_set_html_content_type' );
$headers[] = 'From: Project Website <damien@damiencarbery.com>';
wp_mail('me@domain.com', $subject, $message, $headers);
// Reset content-type to avoid conflicts -- http://core.trac.wordpress.org/ticket/23578
remove_filter( 'wp_mail_content_type', 'dcwd_status_set_html_content_type' );
}
function dcwd_status_set_html_content_type() {
return 'text/html';
}
// Clear the scheduled task when the plugin is deactivated.
register_deactivation_hook(__FILE__, 'dcwd_status_status_email_deactivation');
function dcwd_status_status_email_deactivation() {
wp_clear_scheduled_hook('dcwd_status_status_email');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment