Skip to content

Things to take note when dealing with WordPress cron

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 wp_insert_post, you will require /wp-load.php as shown below
require_once( ABSPATH . "wp-includes/wp-load.php" );
2. Cron does not run under admin, so the security level is higher 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 wp_insert_post and I came across a problem where my content would get filtered. Certain tags and characters like <iframe> 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..
Enjoyed the content ? Share it with your friends !
Published inDevelopmentProgramming

Be First to Comment

Leave a Reply

Your email address will not be published.