Detect if Cron is Running

admin2025-06-05  1

Many times I have code and I want to make sure it only runs in a cron context, or it never runs in a cron context.

Is there an is_cron_running style function?

Many times I have code and I want to make sure it only runs in a cron context, or it never runs in a cron context.

Is there an is_cron_running style function?

Share Improve this question asked Dec 1, 2018 at 19:44 Tom J NowellTom J Nowell 61.2k7 gold badges79 silver badges150 bronze badges 1
  • 1 I'm a bit fed up of constantly googling for the answer to this then forgetting it, and the SEO on stack exchange is pretty good – Tom J Nowell Commented Dec 1, 2018 at 20:10
Add a comment  | 

1 Answer 1

Reset to default 2

Yes, wp_doing_cron will return true if the current request is a WP Cron request, or if it's triggered from WP CLI

https://developer.wordpress/reference/functions/wp_doing_cron/

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749135599a316661.html

最新回复(0)