Wordpress PHP Cron jobs
cron, php, scheduled-tasks, wordpress
Solution
You’ve got to include 2 files to get access to admin side functions: First, wp-load.php. wp-load.php gets everything set up, and fires up wordpress. However, you are calling this function from the plugin folder, inside the content directory (as opposed to the admin directory) – so when wp-load is called, you are not going to be in the admin section, and not going to get access to those functions. On the bright side, you also don’t have to deal with WordPress forcing you to login. Since you still need those admin functions, include wp-admin/admin-functions.php. This loads up the admin side and gives you access to the admin functions – and you are set to go
Problem
I have a plugin that imports csv data into wordpress tables. It runs through the Wordpress dashboard where you input some details and click a button to execute it. I've altered the plugin so that the input data is static(from the same csv every time) and is now all located in one php file. I want to schedule a Cron job to execute this script every hour or so. I tried to set it up using cPanel and directly accessing the php file but it does not work(nothing is displayed). I believe this is because the plugin uses wordpress functions such as wp_insert_post. How can i run this script, as if it were run through wordpress dashboard, as a scheduled event? Note: the file also contains some javascript.