I create a WordPress plugin when the plugin is activated. I need the cron job to be scheduled to run every 5 minutes.
Here is my code;
function my_plugin_activate() {
if( !wp_next_scheduled( 'my_function_hook' ) ) {
wp_schedule_event( time(), '5', 'my_function_hook' );
}
}
register_activation_hook( __FILE__, 'my_plugin_activate' );
function my_plugin_deactivate(){
wp_clear_scheduled_hook('my_function_hook');
}
register_deactivation_hook(__FILE__,'my_plugin_deactivate');
function my_function(){
}
add_action( 'my_function_hook', 'my_function');
When I use this plugin https://wordpress.org/plugins/wp-crontrol/ to check for cron events, nothing has been added, I expect the cron event to be added, that "my_function" is executed at 5 minute intervals, I have no mistakes
source
share