php - Real scheduler for wordpress plugins

905

I want to create a wordpress plugin that performs actions on certain minute intervals like X minutes. Looking into the WP-API there's the methodwp_schedule_event which can schedule actions hourly, daily or twice a day. Is there a way to really schedule events in WP where I can define the exact minute the event should run?

415

Answer

Solution:

Try

wp_schedule_event('YOUR_LINUX_TIMESTAMP', 'daily', 'my_wp_cron_file' );  

YOUR_LINUX_TIMESTAMP istime();

Or look at full article: http://codex.wordpress.org/Function_Reference/wp_schedule_event

The only valid values are 'hourly', 'twicedaily', and 'daily'

BUT:

Opencron.php and find a code in "wp_includes/" folder and find:

function wp_get_schedules() {
    $schedules = array(
        'hourly'     => array( 'interval' => HOUR_IN_SECONDS,      'display' => __( 'Once Hourly' ) ),
        'twicedaily' => array( 'interval' => 12 * HOUR_IN_SECONDS, 'display' => __( 'Twice Daily' ) ),
            // YOU CODE PUT THERE // 
        'daily'      => array( 'interval' => DAY_IN_SECONDS,       'display' => __( 'Once Daily' ) ),
    );
    return array_merge( apply_filters( 'cron_schedules', array() ), $schedules );
}

Add:

'minutes'     => array( 'interval' => 60,      'display' => __( 'Once Minutes' ) ),

or hourly:

'hourly'     => array( 'interval' => 3600,      'display' => __( 'Once Hourly' ) ),

And change it as simple:

wp_schedule_event('YOUR_LINUX_TIMESTAMP', 'hourly', 'my_wp_cron_file' );   // as exmaple hourly cron is called

People are also looking for solutions to the problem: php - Extending base_url() to base_url_admin() not working properly in CodeIgniter

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.