if (!defined('ABSPATH')) exit; new My_Cron(); class My_Cron { public function __construct() { add_filter('cron_schedules', array($this, 'cron_time_intervals')); add_action( 'wp', array($this, 'cron_scheduler')); add_action( 'cast_my_spell', array( $this, 'auto_spell_cast' ) ); } public function cron_time_intervals($schedules) { $schedules['minutes_10'] = array( 'interval' => 10 * 60, 'display' => 'Once 10 minutes' ); return $schedules; } function cron_scheduler() { if ( ! wp_next_scheduled( 'cast_my_spell' ) ) { wp_schedule_event( time(), 'minutes_10', 'cast_my_spell'); } } function auto_spell_cast(){ My_Plugin_Class::instance()->launch_spell(); } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter