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

On the documentation page it says "The action will trigger when someone visits your WordPress site, if the scheduled time has passed."

Is it possible to make this action trigger only when the admin is visited? I am trying to prevent a slow operation from impacting users on the front side.

share|improve this question
I know this question is old, but I think it assumes something that is not true. WordPress "cron jobs" are designed to avoid impacting normal requests with expensive operations. Every time someone visits your WordPress website, a separated, non-blocking request is initiated. The cron job is executed in the second request, while the first one continues generating the content of the page normally. Here is a good explanation of how WordPress Cron Jobs work: sitepoint.com/wordpress-scheduling. – wvega Oct 13 '14 at 0:48
up vote 2 down vote accepted

In your event callback function check to see if the user id the admin then run the function else just reschedule it. So using the example from the codex's page you linked in the question it would be something like this:

function my_activation() {
    if ( !wp_next_scheduled( 'my_hourly_event' ) ) {
        wp_schedule_event(time(), 'hourly', 'my_hourly_event');
add_action('wp', 'my_activation');

function do_this_hourly() {
    // do something every hour only if this is the admin
    if (!current_user_can('administrator')){
        // time()+1800 = 1/2 hour from now.
        wp_schedule_single_event(time()+1800, 'my_hourly_event');
        //do your thing
share|improve this answer
so just a check of is_admin() will not suffice? – Mike Nov 16 '11 at 15:07
depends if you have users that go into the admin pages or not, if its not a problem then yes a simple is_admin would do just fine – Bainternet Nov 16 '11 at 15:31

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.