Skip to content

Instantly share code, notes, and snippets.

@jsoningram
Last active April 17, 2016 14:10
Show Gist options
  • Save jsoningram/7ececf7523e983e21849a251bf05e49c to your computer and use it in GitHub Desktop.
Save jsoningram/7ececf7523e983e21849a251bf05e49c to your computer and use it in GitHub Desktop.
<?php
$plugin_dir = realpath( dirname( __FILE__ ) . '/..' );
$plugin = $plugin_dir . '/plugin.php';
register_activation_hook( $plugin, 'f2d_activation' );
function f2d_activation() {
if ( ! wp_next_scheduled( 'send_f2d' ) ) {
wp_schedule_event( time(), 'weekly', 'send_f2d' );
}
}
add_action( 'send_f2d', 'send_sweepstakes_entries' );
function send_sweepstakes_entries() {
date_default_timezone_set('America/Los_Angeles');
$to = '[email protected]';
$date = date( 'Y-m-d' );
$attachment = [ ABSPATH . 'to/file.csv' ];
$headers = [];
add_filter( 'wp_mail_content_type', 'f2d_content_type' );
wp_mail(
$to,
'Sweepstakes Entries as of ' . $date,
'Attached are the sweepstakes entries as of ' . $date,
$headers,
$attachment
);
}
register_deactivation_hook( $plugin, 'f2d_deactivation' );
function f2d_deactivation() {
wp_clear_scheduled_hook( 'send_f2d' );
}
function ten_weekly_reccurence() {
return [
'weekly' => [ 'interval' => 604800, 'display' => 'Once Weekly' ]
];
}
add_filter( 'cron_schedules', 'ten_weekly_reccurence' );
function f2d_content_type() {
return 'text/html';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment