WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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()
        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...
share|improve this question
WordPress Codex recommends scheduling an event during plugin activation, see: codex.wordpress.org/Function_Reference/… Have you already tried that? Because there is no need to run that on every page load. Could be an easy solution. – swissspidy Nov 7 '13 at 18:20
I copied and pasted your code and worked form me. And cron debug bar correctly display next schedule in 59 minutes after first run... – gmazzap Nov 7 '13 at 18:49

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.