Replace is_plugin_active() guard with plugins_loaded hook#69
Open
flintfromthebasement wants to merge 1 commit intostrangerstudios:devfrom
Open
Replace is_plugin_active() guard with plugins_loaded hook#69flintfromthebasement wants to merge 1 commit intostrangerstudios:devfrom
flintfromthebasement wants to merge 1 commit intostrangerstudios:devfrom
Conversation
- Remove is_plugin_active() check which requires plugins-api.php and breaks when PMPro is installed in a non-standard folder name - Wrap all plugin initialization in pmprodev_plugins_loaded() hooked to plugins_loaded, gated on defined( 'PMPRO_VERSION' ) - Bump version to 1.1.1 Fixes strangerstudios#68
873e3b2 to
78563d0
Compare
Member
|
Skipping as our preferred approach is to have a plugin check at the top of every function that needs it, not wrapping the entire file. This ensures that all functions are always reliably defined when the plugin is active and avoids changing the whitespace on every line in the diff. |
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.
Problem
The plugin uses
is_plugin_active()at the top of the main file to bail early if PMPro isn't active:This has two issues:
is_plugin_active()lives inwp-admin/includes/plugin.phpwhich isn't loaded on frontend requests — so this call can produce a fatal error or silently fail depending on load context.paid-memberships-pro, which means it fails when PMPro is installed from a release candidate zip (e.g.paid-memberships-pro-rc1).Fixes #68.
Solution
is_plugin_active()guard entirely.define( 'PMPRODEV_DIR' )and the migration assistantrequire_onceoutside the init function — these have no PMPro dependency and are safe at any load time.pmprodev_plugins_loaded()function hooked toplugins_loaded, gated ondefined( 'PMPRO_VERSION' ).This is the standard pattern used across PMPro add-ons and works correctly regardless of PMPro's folder name or plugin load order.
Testing
paid-memberships-pro-rc1) — plugin should initialize correctly.