-
-
Save lvnilesh/d59a1d6d23c3dd3a03caa4c09b42d5c8 to your computer and use it in GitHub Desktop.
WordPress Cron and Email Test
This file contains hidden or 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 | |
/** | |
* Plugin Name: Cron Test | |
* Plugin URI: https://gist.github.com/lvnilesh/d59a1d6d23c3dd3a03caa4c09b42d5c8 | |
* Description: WordPress cron and email test. | |
* Author: Nilesh | |
* Version: 1.0 | |
* Author URI: https://be.a.cloudgeni.us | |
*/ | |
/** | |
* Schedules | |
* | |
* @param array $schedules | |
* | |
* @return array | |
*/ | |
function db_crontest_schedules( $schedules ) { | |
$schedules['everyminute'] = array( | |
'interval' => 60, | |
'display' => 'Once Every Minute', | |
); | |
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(), 'everyminute', '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