How to run a function every 5 minutes?

You can create new schedule times via cron_schedules: function my_cron_schedules($schedules){ if(!isset($schedules[“5min”])){ $schedules[“5min”] = array( ‘interval’ => 5*60, ‘display’ => __(‘Once every 5 minutes’)); } if(!isset($schedules[“30min”])){ $schedules[“30min”] = array( ‘interval’ => 30*60, ‘display’ => __(‘Once every 30 minutes’)); } return $schedules; } add_filter(‘cron_schedules’,’my_cron_schedules’); Now you can schedule your function: wp_schedule_event(time(), ‘5min’, ‘my_schedule_hook’, $args); To only schedule … Read more

Running WP Cron on multisite the right way

I think the best way is to use WP-CLI but you’d need to write a bash script to do this. Here is one that should do it for you: WP_PATH=”/path/to/wp” for SITE_URL in = $(wp site list –fields=domain,path,archived,deleted –format=csv –path=”$WP_PATH” | grep “,0,0$” | awk -F ‘,’ ‘{print $1 $2}’) do for EVENT_HOOK in $(wp … Read more

How to test wp_cron?

My favorite plugin for that is Core Control which has very nice module for display of what is going in the cron – which events are set up, when are they next firing, etc. On getting your hands dirty level see _get_cron_array(), which returns internal stored data for cron events (top level of keys are … Read more