Skip to content

Run scheduled jobs on sites with Disable Front-End turned on - #114

Draft
LiamSarsfield wants to merge 1 commit into
trunkfrom
fm/crm-disable-frontend-cron
Draft

LiamSarsfield wants to merge 1 commit into
trunkfrom
fm/crm-disable-frontend-cron

Conversation

@LiamSarsfield

Copy link
Copy Markdown
Contributor

This lets scheduled jobs run on HTTP cron requests when the Disable Front-End setting is on.

What

The front-end check in ZeroBSCRM::init() moves into jpcrm_should_stop_front_end(), which lets a request through when wp_doing_cron() is true.

Why

WordPress runs due jobs on a request to wp-cron.php, which loads the site like a front-end page. With Disable Front-End on, CRM redirected that request to the login page during init, so due jobs from CRM and other plugins never ran on it. Cron requests show visitors no page.

For the release notes

There is no switch: every site with Disable Front-End on gets this when it updates, and other sites are unaffected. On those sites, the first cron request after the update runs each overdue job once, including sends queued by the Mail Campaigns extension if it is installed.

Testing

Disable_Front_End_Test: the check says to stop a front-end request but not a cron request; the cron test fails without the fix. Full suite passes (310 tests); composer cs clean.

Manual steps, run on a local site on trunk and on this branch (there I turned the setting on from WP-CLI):

  1. In Jetpack CRM > CRM Settings (General tab), turn on Disable Front-End.
  2. Run wp cron event schedule jpcrm_test_hook now.
  3. Log out and open the home page: you are redirected to the login page.
  4. After a few seconds, run wp cron event list --hook=jpcrm_test_hook. On trunk the event is still listed; on this branch it is gone.

With Disable Front-End on, a request to wp-cron.php was redirected and
stopped during init, before WordPress ran any scheduled jobs. Due jobs
from CRM and from other plugins did not run on those requests.

The front-end check moves into jpcrm_should_stop_front_end(), which
lets a request through when wp_doing_cron() is true. Cron requests
show visitors no page.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant