wp cron – Custom cronjob not executing at all, but manually
In my themes function.php, I’ve added that code to load a custom code based on the cron:
add_action( 'wp', 'schedule_test_cron' );
function schedule_test_cron() {
if ( !wp_next_scheduled( 'test_cron' ) ) {
wp_schedule_event( time(), 'hourly', 'test_cron' );
}
}
add_action( 'test_cron', 'test_cron_runner' );
function test_cron_runner() {
error_log( 'Test cron running...', 0 );
}
This code does not get executed at all (meaning the text is not in the php error log)
I installed wp crontrol to check if the cronjob exists, it is in the table of the scheduled events.
Only the time of the next execution always shows up as now
.
I already deleted the cronjob with the plugin, as expected it gets added every time with the next website reload.
If I add for test reasons add_action( 'wp', 'test_cron_runner' );
to the functions.php, the text gets logged to the php error log.
Maybe I should mention that website access has been blocked by wp-staging for all but administrators, but I added a system cronjob running all 5 minutes running php_cli /wp-cron.php
Any idea why it is not working?
Leave an answer