I use the following script to run cron from crontab (it's using wp cron event run --due-now ...): https://gist.github.com/soderlind/bc28c6dc82fbf01f9cd539f470d504af
Looking at the log, I discovered that ghu cron events are triggered for very subsite:
Executed the cron event 'ghu_get_remote_plugin' in 0.005s.
Executed the cron event 'ghu_get_remote_theme' in 0.004s.
Success: Executed a total of 2 cron events.
Executed the cron event 'ghu_get_remote_plugin' in 0.004s.
Executed the cron event 'ghu_get_remote_theme' in 0.005s.
Success: Executed a total of 2 cron events.
Executed the cron event 'ghu_get_remote_plugin' in 0.004s.
Executed the cron event 'ghu_get_remote_theme' in 0.004s.
Success: Executed a total of 2 cron events.
Executed the cron event 'ghu_get_remote_plugin' in 0.005s.
Executed the cron event 'ghu_get_remote_theme' in 0.004s.
Success: Executed a total of 2 cron events.
.
.
.
It would be nice, on a multisite, that the cron events only were triggered on the main site , i.e., only once per crontab run.
I鈥檓 not certain there鈥檚 a way to specify setting a cron even on a per site or only for the network admin. If you know of one I鈥檓 happy to consider a PR.
I鈥檓 sorry if it clutters up your logs I鈥檓 really not certain there鈥檚 much I can do.
The cron event is only set when an admin level user is on the site.
A fix could be to wrap the scheduling in is_mail_site (i.e. only schedule the task once) as in
if ( is_main_site() ) {
if ( ! wp_next_scheduled( 'ghu_get_remote_theme' ) &&
! $this->is_duplicate_wp_cron_event( 'ghu_get_remote_theme' ) &&
! apply_filters( 'github_updater_disable_wpcron', false )
) {
wp_schedule_single_event( time(), 'ghu_get_remote_theme', [ $themes ] );
}
}
I've tested this and it works fine.
So what happens if an admin never really ventures on the Network Admin pages. GHU would never see updates. Do you think that's likely? I don't maintain sites for people so I'm asking.
Most likely (but that's a bad argument) a multisite admin ventures daily on the Network Admin pages.
Maybe only limit running on main site when using crontab?:
$schedule_event = true;
if ( defined('DISABLE_WP_CRON') && DISABLE_WP_CRON ) {
$schedule_event = is_main_site();
}
if ( $schedule_event ) {
if ( ! wp_next_scheduled( 'ghu_get_remote_theme' ) &&
! $this->is_duplicate_wp_cron_event( 'ghu_get_remote_theme' ) &&
! apply_filters( 'github_updater_disable_wpcron', false )
) {
wp_schedule_single_event( time(), 'ghu_get_remote_theme', [ $themes ] );
}
}
@soderlind Does the second instance work for you?
No, if you choose to add this it should also be added for ghu_get_remote_plugin
I would need to add it to both Plugins and Themes.
Did you mean to say that the second method of limited only on crontab doesn't work?
No, sorry, the second method works fine.
@soderlind let me know if this works for you. It's on the develop branch.
Works perfect, thank you :)