Skip to content

Pause Engine in PMPro Core#3595

Closed
dalemugford wants to merge 5 commits intodevfrom
feature/pause-engine
Closed

Pause Engine in PMPro Core#3595
dalemugford wants to merge 5 commits intodevfrom
feature/pause-engine

Conversation

@dalemugford
Copy link
Contributor

@dalemugford dalemugford commented Feb 27, 2026

This pull request was closed after we determined internally that pause functionality can be better served inside PMPro Hosting's MU plugin for migration purposes.

All Submissions:

Changes proposed in this Pull Request:

Adds a modular Pause Engine (PMPro_Pause_Engine) for progressive site lockdown during site migrations, or maintenance. This replaces the PMPro_Migration_Site_Suspender class in the PMPro Hosting plugin with a reusable, composable system any tooling can leverage.

The existing pmpro_is_paused() remains untouched, and only detects URL mismatches and halts Action Scheduler. It doesn't freeze membership changes, block gateway calls, suppress emails, or lock down the frontend. The hosting plugin's suspender handles some of this but wasn't reusable and blocked email permanently with no queue mechanism.

Architecture: A singleton orchestrator with 6 toggleable modules, activated in a defined order:

Module Slug What it does
Mutations pmpro_mutations Blocks checkout, level changes, and order creation
Gateways pmpro_gateways Blocks outbound HTTP to gateway APIs + returns 503 to inbound webhooks
Mail pmpro_mail Intercepts wp_mail(), queues to Action Scheduler for replay on resume
Schedules background_schedules Halts Action Scheduler and blocks cron spawning
Frontend frontend_block 503 maintenance page, blocks REST API, POST requests, and non-admin logins
Sessions logged_in_sessions Clears non-admin sessions on activation, blocks non-admin logins

Two built-in presets: Migration (all 6 modules) and Maintenance (mutations + mail + schedules). Modules can be enabled/disabled individually at runtime for progressive lockdown. Admin bypass via pmpro_manage_pause_mode capability. Presets and modules are extensible via filters.

Files added:

  • classes/class-pmpro-pause-engine.php — Interface, orchestrator, all 6 modules, convenience functions
  • tests/test-pause-engine.php — Browser-based test harness (see testing instructions)

Files modified:

  • paid-memberships-pro.php — Loads the pause engine on plugins_loaded priority 5
  • includes/admin.php — Admin notice when engine is active with module list and "Resume All Services" button

Public API:

PMPro_Pause_Engine::instance()->pause_with_preset( 'migration' );
PMPro_Pause_Engine::instance()->pause( array( 'pmpro_mutations', 'pmpro_gateways' ), 'my-tool' );
PMPro_Pause_Engine::instance()->enable_module( 'frontend_block' );
PMPro_Pause_Engine::instance()->disable_module( 'frontend_block' );
PMPro_Pause_Engine::instance()->resume();
pmpro_pause_engine_is_active();
pmpro_pause_module_is_active( 'pmpro_mutations' );

How to test the changes in this Pull Request:

A browser-based test harness is included at tests/test-pause-engine.php. To set it up:

  1. Copy the file into your site's mu-plugins directory: cp wp-content/plugins/paid-memberships-pro/tests/test-pause-engine.php wp-content/mu-plugins/
  2. As an admin, navigate to /wp-admin/?pmpro_pause=status to open the test dashboard.
  3. From there you can activate presets, enable custom module combinations, view live diagnostics, and resume — all via clickable links.

Available URLs (append to /wp-admin/):

URL Action
?pmpro_pause=status Dashboard with module states, diagnostics, and quick action links
?pmpro_pause=migration Activate the Migration preset (full lockdown)
?pmpro_pause=maintenance Activate the Maintenance preset
?pmpro_pause=custom&modules=pmpro_mutations,pmpro_gateways Activate specific modules
?pmpro_pause=resume Resume all modules
?pmpro_pause=test_mail Send a test email (verifies mail queuing)

What to verify:

  1. Activate the migration preset. Visit the site in an incognito window — you should see a 503 maintenance page.
  2. Confirm your admin session remains fully functional while paused.
  3. Check the status page diagnostics: gateway blocking, mail queue count, cron/AS halt status.
  4. Click "Send a test email", return to status, confirm the queued email count increments.
  5. Test webhook blocking: curl -vk -X POST "https://yoursite.local/wp-admin/admin-ajax.php?action=stripe_webhook" — should return 503.
  6. Log out, log back in as admin — should succeed. Attempt non-admin login — should be rejected.
  7. Hit resume, confirm all modules deactivate and the site returns to normal.
  8. Remove the mu-plugin when done: rm wp-content/mu-plugins/test-pause-engine.php

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you successfully run tests with your changes locally?

Changelog entry

Added a modular Pause Engine (PMPro_Pause_Engine) for progressive site lockdown during migrations and maintenance.

Signed-off-by: Dale Mugford <dmugford@paidmembershipspro.com>
For better clarity, use “pause engine” vs. pause mode. (PMPro_Pause_Engine(), etc.).

Signed-off-by: Dale Mugford <dmugford@paidmembershipspro.com>
- Allow admins to login after pause engine started
- Clear non-admin logged-in sessions inline using batch processing

Signed-off-by: Dale Mugford <dmugford@paidmembershipspro.com>
Signed-off-by: Dale Mugford <dmugford@paidmembershipspro.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new core “Pause Engine” to Paid Memberships Pro to progressively lock down parts of the site (mutations, gateways, mail, background schedules, frontend, sessions) during migrations/maintenance, plus admin UI feedback and a testing harness.

Changes:

  • Introduces PMPro_Pause_Engine singleton orchestrator with toggleable pause modules and presets.
  • Loads the pause engine early on plugins_loaded and adds an admin notice + “Resume All Services” action when active.
  • Adds a test harness script under tests/ for exercising engine behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 8 comments.

File Description
classes/class-pmpro-pause-engine.php New pause engine orchestrator + six built-in modules + convenience functions.
includes/admin.php Adds admin notice and admin action handler to resume the pause engine.
paid-memberships-pro.php Loads/initializes the pause engine during plugin bootstrap.
tests/test-pause-engine.php Adds a pause-engine test script/harness.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +222 to +223
// Get the module label from the registered modules.
$all_presets = PMPro_Pause_Engine::get_presets();
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the module label list, the comment says it’s pulling labels from registered modules, but it only outputs the slug (esc_html( $slug )), and $all_presets = PMPro_Pause_Engine::get_presets(); is unused. Either fetch/display each module’s get_label() (requires an accessor on the engine) or remove the misleading comment and unused variable.

Suggested change
// Get the module label from the registered modules.
$all_presets = PMPro_Pause_Engine::get_presets();

Copilot uses AI. Check for mistakes.
Fixes for Copilot suggestions, tested.

Signed-off-by: Dale Mugford <dmugford@paidmembershipspro.com>
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.

2 participants