When I schedule an event at the top of the main plugin file (plugin.php), cron is added to the wp_options cron parameter.
wp_schedule_event( time() + 10, 'hourly', 'this_is_my_action' );
This works great, adds a new cron. But, when I try to use the same function in my activation function inside the plugin class, it does not work.
Inside plugin.php I have:
$plugin = new My_Plugin(__FILE__); $plugin->initialize();
Inside the My_Plugin class, I have:
class My_Plugin{ function __construct($plugin_file){ $this->plugin_file = $plugin_file; } function initialize(){ register_activation_hook( $this->plugin_file, array( $this, 'register_activation_hook' ) ); } function register_activation_hook() { $this->log( 'Scheduling action.' ); wp_schedule_event( time() + 10, 'hourly', 'this_is_my_action' ); } function log($message){ } }
The log is logged when I activate the plugin, but cron is not added to the wordpress database. Any ideas why?
source share