WordPress.org

Ready to get started?Download WordPress

Forums

How to schedule event in my wordpress plugin : wp_schedule_event (1 post)

  1. ben.IT
    Member
    Posted 1 year ago #

    HI,
    I am trying to schedule event in my wordpress plugin, but this doesn't work. I have tried this :

    register_activation_hook(__FILE__, 'my_activation');
    add_action('my_hourly_event', 'do_this_hourly');
    
    function my_activation() {
    	//create dable for data sync
    	plugin_create_table() ;
    
    	wp_schedule_event( current_time( 'timestamp' ), 'hourly', 'my_hourly_event');
    	global $wpdb ;
    	$wpdb->insert('afn_test_cron',
    	array(	'chaine'=>'activation hook'
    	)
    	);
    }
    
    function do_this_hourly() {
    	global $wpdb ;
    	$wpdb->insert('afn_test_cron',
    	array(	'chaine'=>'cron'
    	)
    	);
    }
    
    register_deactivation_hook(__FILE__, 'my_deactivation');
    
    function my_deactivation() {
    	wp_clear_scheduled_hook('my_hourly_event');
    	global $wpdb ;
    	$wpdb->insert('afn_test_cron',
    	array(	'chaine'=>'deactivation hook'
    	)
    	);

    This doesn't work, I have got not error.
    Does anybody can help me ?
    Thanks,
    greetings.Ben

Topic Closed

This topic has been closed to new replies.

About this Topic