DevinVinson / WordPress-Plugin-Boilerplate

[WordPress] A foundation for WordPress Plugin Development that aims to provide a clear and consistent guide for building your plugins.
http://wppb.io
7.69k stars 2.27k forks source link

wp_schedule_event #406

Open ajulien-fr opened 8 years ago

ajulien-fr commented 8 years ago

Hi (I am beginner in the wordpress plugin creation),

I need to create a Cron Job in "my plugin". I am using this tutorial : http://wpguru.co.uk/2014/01/how-to-create-a-cron-job-in-wordpress-teach-your-plugin-to-do-something-automatically/

Where to put these two lines:

if( !wp_next_scheduled( 'mycronjob' ) ) { wp_schedule_event( time(), 'daily', 'mycronjob' ); }

In "function activate_my_plugin()" stored in "my-plugin.php" or in "public static function activate()" stored in "includes/class-my-plugin-activator.php" ?

Please

natterstefan commented 7 years ago

@juavenel I would suggest you add it to the includes/class-my-plugin-activator.php. But it depends where your mycronjob is defined too I think.

markheydon commented 6 years ago

Hi,

An old issue I know but recently had to use a daily job in a project and came up with the following example of how it could be done #495.

Mark

blaz-blazer commented 4 years ago

I recently had a need for CRON (wp_schedule_event) functionality in a plugin which I was developing (based on WP Plugin Boilerplate). I wrote a short tutorial which explains the procedure. I hope it's okay to share it here.

Regards, Blaz