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.

I would need to know how much time is left between now and the next time a specifc Cron Job is done.

For another answer I built a basic cron inspector plugin which can be found here.

Reason I'm asking is that I'm already that wasted from working that I can't think straight at the moment. :/

Thanks in advance.

share|improve this question
    
For what it's worth: wordpress.org/extend/plugins/debug-bar-cron –  helenhousandi Jan 27 '13 at 15:08
add comment

1 Answer

up vote 5 down vote accepted

Edit: wp_next_scheduled() returns the timestamp of the next scheduled job of a specified wp-cron job-arguments pair.

Please note that this differs slightly in functionality to the answer below, in that you have to provide the arguments passed to cron job's callback (if it has any). The original answer would provide the time of the next specified job regardless of the arguments it would run with.


The cron array (_get_cron_array()) returns an array of cron jobs indexed by timestamp (each timestamp will have an array of crons associated with it - i.e. those jobs which shall be triggered).

/**
 * Returns the time in seconds until a specified cron job is scheduled.
 *
 *@param string $cron_name The name of the cron job
 *@return int|bool The time in seconds until the cron job is scheduled. False if
 *it could not be found.
*/
function sh_get_next_cron_time( $cron_name ){

    foreach( _get_cron_array() as $timestamp => $crons ){

        if( in_array( $cron_name, array_keys( $crons ) ) ){
            return $timestamp - time();
        }

    }

    return false;
}
share|improve this answer
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.