This is a MU-plugin I’m developing, and I want it to run hourly. Unfortunately, it’s running every time I visit any site’s wp-admin page. I’ve used the Debug Bar plugin with the Cron plugin, and it consistently says that the next event is in the past. Any ideas?
add_action('admin_menu', 'dhg_cron_menu');
function dhg_cron_menu()
{
add_options_page('NEW WPMS Stats', 'NEW WPMS Stats', 'manage-options', 'dhg-cron', 'dhg_cron_settings');
}
function dhg_cron_settings()
{
if(!wp_next_scheduled('dhg_cron_hook'))
{
wp_schedule_event(time(), 'hourly', 'dhg_cron_hook');
}
}
add_action('dhg_cron_hook', 'dhg_cron_get_stats');
function dhg_cron_get_stats()
{
// this is a custom function I use to log to a file for testing...
log_wpms_stats("testing!");
}
1 Answer
An idea I came up with was using the new WP Heartbeat API as opposed to using cron. Have your plugin fire off a call to your logging system every hour.
Pippin’s tutorial contains the majority of the code you’ll need to get started.