Skip to content

Drop is_plugin_active() guard in favor of per-function PMPro checks#71

Merged
dparker1005 merged 1 commit into
strangerstudios:devfrom
dparker1005:fix/pmpro-active-check
May 7, 2026
Merged

Drop is_plugin_active() guard in favor of per-function PMPro checks#71
dparker1005 merged 1 commit into
strangerstudios:devfrom
dparker1005:fix/pmpro-active-check

Conversation

@dparker1005
Copy link
Copy Markdown
Member

Summary

Fixes #68 — the top-of-file is_plugin_active( 'paid-memberships-pro/paid-memberships-pro.php' ) early return failed when PMPro was installed under a non-standard folder name (e.g. release-candidate zips like paid-memberships-pro-rc1) and could fatal on frontend requests since is_plugin_active() lives in wp-admin/includes/plugin.php.

Replaces it with narrow function_exists() checks at each entry point that actually depends on PMPro:

  • API loader registration — gated on pmpro_getOption() so the /toolkit/v1/* REST endpoints (whose handlers call pmpro_loadTemplate / pmpro_getLevel / pmpro_changeMembershipLevel / use PMPRO_DIR) are not registered when PMPro is not loaded.
  • WP-CLI commands registration — same gate, so toolkit CLI commands (which load adminpages/scripts.php referencing $wpdb->pmpro_* and calling pmpro_changeMembershipLevel etc.) are not registered.
  • pmprodev_process_migration_export() — gated on pmpro_getAllLevels() since PMProDev_Migration_Assistant::export() calls it.
  • pmprodev_settings_page() — gated on pmpro_getParam() since adminpages/toolkit.php uses PMPRO_DIR and pmpro_getParam at parse time.

Other handlers do not need guards:

  • pmprodev_checkout_debug_email already self-guards with function_exists( 'pmpro_is_checkout' ).
  • pmprodev_gateway_debug_setup is already defensive with class_exists checks and harmless define() / remove_action() calls.
  • pmprodev_admin_menu / pmprodev_admin_menu_bar silently no-op when their PMPro parent menu does not exist.
  • The rest (pmprodev_init_options, pmprodev_redirect_emails, pmpro_toolkit_load_textdomain, pmprodev_plugin_row_meta, pmprodev_enqueue_scripts, pmprodev_enqueue_admin_scripts, pmprodev_create_button) are either purely toolkit-internal or only fire via PMPro hooks.

Test plan

  • Install Toolkit with PMPro active under a non-standard folder name (e.g. paid-memberships-pro-rc1) — Toolkit features (settings page, debug emails, migration assistant) should all work.
  • Install Toolkit without PMPro active — no fatal errors on frontend, admin, REST, or WP-CLI.
  • With Toolkit performance endpoints enabled, deactivate PMPro — /wp-json/toolkit/v1/* should 404 instead of fataling.
  • With Toolkit CLI commands enabled, deactivate PMPro — wp pmpro-toolkit <cmd> should report "Command not found" instead of fataling.
  • Settings page (?page=pmpro-toolkit) loads cleanly under all combinations.
  • Migration export still works under normal install.

🤖 Generated with Claude Code

The top-of-file is_plugin_active( 'paid-memberships-pro/paid-memberships-pro.php' )
early return failed when PMPro was installed under a non-standard folder
(e.g. release-candidate zips like paid-memberships-pro-rc1) and could fatal
on frontend requests since is_plugin_active() lives in
wp-admin/includes/plugin.php.

Replace it with narrow function_exists() checks at each entry point that
actually depends on PMPro:

- API loader registration: gate on pmpro_getOption() so REST endpoints
  whose handlers call pmpro_loadTemplate / pmpro_getLevel /
  pmpro_changeMembershipLevel / use PMPRO_DIR are not registered when
  PMPro is not loaded.
- WP-CLI commands registration: same gate so toolkit CLI commands (which
  load adminpages/scripts.php referencing $wpdb->pmpro_* and calling
  pmpro_changeMembershipLevel etc.) are not registered.
- pmprodev_process_migration_export(): gate on pmpro_getAllLevels() since
  PMProDev_Migration_Assistant::export() calls it.
- pmprodev_settings_page(): gate on pmpro_getParam() since
  adminpages/toolkit.php uses PMPRO_DIR and pmpro_getParam at parse time.

Other handlers do not need guards: pmprodev_checkout_debug_email already
self-guards with function_exists( 'pmpro_is_checkout' );
pmprodev_gateway_debug_setup is already defensive with class_exists checks
and harmless define()/remove_action() calls; menu callbacks silently
no-op when their PMPro parent does not exist; the rest are either purely
toolkit-internal or only fire via PMPro hooks.

Fixes strangerstudios#68.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.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.

Plugin not working if PMPro folder name is incorrect

1 participant