Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

1 Answer

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');
        return;
    }else{
        //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
add comment

Your Answer

 
discard

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.