You shouldn’t call wp_clear_scheduled_hook
on every page load, because then you’re always restarting your wp-cron shcedule, with your current setup.
Additionally this call:
wp_clear_scheduled_hook( 'le_do_this' );
doesn’t make any difference, since le_do_this
isn’t a hook name in your setup.
You could try for example this test plugin:
<?php
/**
* Plugin Name: Daily WP-Cron
* Description: Call the my_daily_cron_script() function daily, if it exists.
*/
add_action( 'mydailyevent', function()
{
// Our script:
if( function_exists( 'my_daily_cron_script' ) )
my_daily_cron_script();
});
register_activation_hook( __FILE__, function()
{
// Start the cron job:
wp_schedule_event( time(), 'daily', 'mydailyevent' );
});
register_deactivation_hook( __FILE__, function()
{
// Stop the cron job:
wp_clear_scheduled_hook( 'mydailyevent' );
});
where you have to define the my_daily_cron_script()
function to your needs.
There’s a warning in the Codex on wp_schedule_event
:
The name of an action hook to execute. For some reason there seems to
be a problem on some systems where the hook must not contain
underscores or uppercase characters.
so let’s just use mydailyevent
as our hook name, instead of my_daily_event
, just in case.