Closed dd32 closed 7 years ago
We should do this as soon as possible, but I think that's likely to be when the command's callback fires. We can't really hook in any earlier.
Perhaps an option would be to enhance WP-CLI to accept certain constants on the command line? ie. wp --debug=true --cron=on
wp-cli itself only sets the constant late, so I'm fine with also setting it late.
FWIW this just bit me too!
I think the most earliest it can be currently set in WP-CLI bootstrap is with the --require
flag:
https://github.com/wp-cli/wp-cli/blob/104ccf37da491465b8d42bc73695865440ebd333/php/bootstrap.php#L26
In case you'll want to use that the cavalcade runner should have a file which can be required with wp-cli:
$ echo "<?php define( 'DOING_CRON', true );" > /tmp/define-cron.php
$ wp cavalcade run <id> --require /tmp/define-cron.php
Another hacky option is to use auto_prepend_file
in the cavalcade runner:
$ echo "<?php define( 'DOING_CRON', true );" > /tmp/define-cron.php
$ php -d auto_prepend_file="/tmp/define-cron.php" /usr/local/bin/wp cavalcade run <id>
This is kinda hacky and it shouldn't make a big difference if it's defined just before running the cron job.
I just noticed that DOING_CRON isn't defined when running jobs, this could cause unexpected behaviour for some jobs.
While running through WP-CLI, it won't be possible to define it before bootstrap occurs (AFAIK), but defining it late might be better than not at all.