This is first time I try OOP method to write application, not quite understand yet. Currently I have a cron like this:
if( !wp_next_scheduled( 'my_cron_hook' ) ) {
//schedule the event to run daily
wp_schedule_event( current_time( 'timestamp' ), 'daily', 'my_cron_hook' );
}
add_action('my_cron_hook',array($this,'do_daily_job'));
It seem it can't use 'if' within a class directly. Do I need to put the entire codes above into __construct() function?
Also, I found this in wordpres wp_schedule_event documentation.
function my_activation() {
if ( !wp_next_scheduled( 'my_hourly_event' ) ) {
wp_schedule_event( current_time( 'timestamp' ), 'hourly', 'my_hourly_event');
}
}
add_action('wp', 'my_activation');
What dose 'wp' hook here means? I never seen this in the hook api. Should I wrapped my cron above in a function and put this 'wp' action in the __construct() function, like this?
function __construct() {
add_action('wp', array($this,'my_activation'));
}
function my_activation() {
if( !wp_next_scheduled( 'my_cron_hook' ) ) {
//schedule the event to run daily
wp_schedule_event( current_time( 'timestamp' ), 'daily', 'my_cron_hook' );
}
add_action('my_cron_hook',array($this,'do_daily_job'));
}
