Things to take note when dealing with WordPress cron
WordPress crons might be rather tricky for someone new to them so here are some stuff to keep in mind when dealing with them in development.
1. Cron does not include/require files that your admin dashboard (/wp-admin) does by default.
When your cron function is running, you will need to manually required files. For example, for the function
, you will require
as shown below
2. Cron does not run under admin, so the security level is higher
require_once( ABSPATH . "wp-includes/wp-load.php" );
I have not fully investigated this, but believe it is so. I was developing a plugin where the cron would create a post automatically using
and I came across a problem where my content would get filtered. Certain tags and characters like
might be filtered away. Specific to my case, I simply had to remove the WordPress filter and add them back again after the cron ended
3. Install the WP Crontrol plugin to make your cron development easier
Trust me, you will need it. It helps with everything related to cron – scheduling, function callbacks, creating/editing crons, etc..