Drop is_plugin_active() guard in favor of per-function PMPro checks#71
Merged
dparker1005 merged 1 commit intoMay 7, 2026
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 likepaid-memberships-pro-rc1) and could fatal on frontend requests sinceis_plugin_active()lives inwp-admin/includes/plugin.php.Replaces it with narrow
function_exists()checks at each entry point that actually depends on PMPro:pmpro_getOption()so the/toolkit/v1/*REST endpoints (whose handlers callpmpro_loadTemplate/pmpro_getLevel/pmpro_changeMembershipLevel/ usePMPRO_DIR) are not registered when PMPro is not loaded.adminpages/scripts.phpreferencing$wpdb->pmpro_*and callingpmpro_changeMembershipLeveletc.) are not registered.pmprodev_process_migration_export()— gated onpmpro_getAllLevels()sincePMProDev_Migration_Assistant::export()calls it.pmprodev_settings_page()— gated onpmpro_getParam()sinceadminpages/toolkit.phpusesPMPRO_DIRandpmpro_getParamat parse time.Other handlers do not need guards:
pmprodev_checkout_debug_emailalready self-guards withfunction_exists( 'pmpro_is_checkout' ).pmprodev_gateway_debug_setupis already defensive withclass_existschecks and harmlessdefine()/remove_action()calls.pmprodev_admin_menu/pmprodev_admin_menu_barsilently no-op when their PMPro parent menu does not exist.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
paid-memberships-pro-rc1) — Toolkit features (settings page, debug emails, migration assistant) should all work./wp-json/toolkit/v1/*should 404 instead of fataling.wp pmpro-toolkit <cmd>should report "Command not found" instead of fataling.?page=pmpro-toolkit) loads cleanly under all combinations.🤖 Generated with Claude Code