The solution I came up with here goes as follows:
- Installed WP-CLI and made use of the eval-file command.
- Converted my wordpress plugin to a standalone script.
- In the standalone script, I initiated wordpress so i didn’t have to modify most of it. I just removed my the activation hooks and other wordpress plugin specific code.
-
My final cron line looked like this:
/usr/local/bin/wp –path=”/var/www/vhosts/path/to/site/” eval-file
/var/www/vhosts/path/to/site/and/file/location/standalone-cron-send-email.php -
For security purposes, I’ve added this to the top of the script so outside intruders can not run the script. Only WP-CLI can run the script otherwise the meant to be run from command line message is returned to the browser.
if( php_sapi_name() !== ‘cli’ ) {
die(“Meant to be run from command line”);
}