I have a function that I only want to run via a cron job. Is there a way I can check that a particular scheduled event is calling this function and not anything else?
Leave a Reply
You must be logged in to post a comment.
I have a function that I only want to run via a cron job. Is there a way I can check that a particular scheduled event is calling this function and not anything else?
You must be logged in to post a comment.
WordPress has a constant
DOING_CRON
that helps us know we’re doing the cron jobs or not. It’s defined inwp-cron.php
file.So, you can check this constant in your code:
Just take a look at the »Cron API inspector«, that I wrote for question #18017. The plugin builds a table that shows on the
shutdown
-hook/the end of the page.It uses the
_get_cron_array()
function to retrieve all registered & scheduled actions. Another useful function iswp_get_schedules()
. The third way is calling the underlying data for_get_cron_array()
directly, by callingget_option( 'cron' );
– it’s still better to use the default API functions from WP core.If you want to know if you’re currently inside a Cron Job, then you can check
defined( 'DOING_CRON' ) AND DOING_CRON
.I’m not studies development (I’m just an enthusiast) but I think you may add a add_action to the event
It’s just a resume…
To retrieve a list of your cron “your_function” where have this arg