Skip to content

Instantly share code, notes, and snippets.

@A5hleyRich
Last active July 26, 2022 17:25
Show Gist options
  • Save A5hleyRich/6de1712ce5f46662c8ba to your computer and use it in GitHub Desktop.
Save A5hleyRich/6de1712ce5f46662c8ba to your computer and use it in GitHub Desktop.
WordPress Cron and Email Test
<?php
/**
* Plugin Name: Cron Test
* Plugin URI: https://gist.github.com/A5hleyRich/6de1712ce5f46662c8ba
* Description: WordPress cron and email test.
* Author: Ashley Rich
* Version: 1.0
* Author URI: http://ashleyrich.com
*/
/**
* Schedules
*
* @param array $schedules
*
* @return array
*/
function db_crontest_schedules( $schedules ) {
$schedules['five_minutes'] = array(
'interval' => 300,
'display' => 'Once Every 5 Minutes',
);
return $schedules;
}
add_filter( 'cron_schedules', 'db_crontest_schedules', 10, 1 );
/**
* Activate
*/
function db_crontest_activate() {
if ( ! wp_next_scheduled( 'db_crontest' ) ) {
wp_schedule_event( time(), 'five_minutes', 'db_crontest' );
}
}
register_activation_hook( __FILE__, 'db_crontest_activate' );
/**
* Deactivate
*/
function db_crontest_deactivate() {
wp_unschedule_event( wp_next_scheduled( 'db_crontest' ), 'db_crontest' );
}
register_deactivation_hook( __FILE__, 'db_crontest_deactivate' );
/**
* Crontest
*/
function db_crontest() {
wp_mail( get_option( 'admin_email' ), 'Cron Test', 'All good in the hood!' );
}
add_action( 'db_crontest', 'db_crontest' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment