WordPress.org

Ready to get started?Download WordPress

Forums

cron wp_schedule_event (3 posts)

  1. lordcoste
    Member
    Posted 4 years ago #

    I can't get wordpress' cronjob work:

    Here what I have done:

    <?php
    
    function hlex_install() {
    	wp_schedule_event(time(), 'hourly', 'hlex_timing_job');
    }
    
    function hlex_cronjob() {
        die('cronjob');
    }
    
    function hlex_deactivation() {
    	wp_clear_scheduled_hook('hlex_timing_job');
    }
    
    register_activation_hook(__FILE__, 'hlex_install');
    
    register_deactivation_hook(__FILE__, 'hlex_deactivation');
    
    add_action('hlex_timing_job', 'hlex_cronjob');
    ?>

    The wp_schedule_event works cause I can see in the table wp_options (option_name='cron' ) something like: i:1270343829;a:1:{s:15:"hlex_timing_job";

    wp_clear_scheduled_hook works too because if I deactivate the plugin "hlex_timing_job" has gone from the "cron" row of the wp_options table.

    The problem is that hlex_cronjob() is never executed or at least I've never seen the word 'cronjob' printed.

    I hope someone can help me.

    Thanks

  2. lordcoste
    Member
    Posted 4 years ago #

    I wasn't sure if the cron function will be called directly or by CURL so I changed the hlex_cronjob() to see if it's called:

    function hlex_cronjob() {
    	update_option('hlex_test', now());
    }

    Now i'm sure that is not called because I can see in wp_options that the row hlex_test is not updated.

    So i still can't find a solutions :/

  3. javiarques
    Member
    Posted 3 years ago #

    I recommend you to install "GD Press Tools" plugin where you can see if your event has been correctly scheduled.

Topic Closed

This topic has been closed to new replies.

About this Topic