Skip to content

Replace is_plugin_active() guard with plugins_loaded hook#69

Open
flintfromthebasement wants to merge 1 commit intostrangerstudios:devfrom
flintfromthebasement:fix/pmpro-version-check
Open

Replace is_plugin_active() guard with plugins_loaded hook#69
flintfromthebasement wants to merge 1 commit intostrangerstudios:devfrom
flintfromthebasement:fix/pmpro-version-check

Conversation

@flintfromthebasement
Copy link
Copy Markdown

Problem

The plugin uses is_plugin_active() at the top of the main file to bail early if PMPro isn't active:

if ( ! is_plugin_active( 'paid-memberships-pro/paid-memberships-pro.php' ) ) {
    return;
}

This has two issues:

  1. is_plugin_active() lives in wp-admin/includes/plugin.php which isn't loaded on frontend requests — so this call can produce a fatal error or silently fail depending on load context.
  2. The check is hardcoded to the folder name 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

  • Remove the is_plugin_active() guard entirely.
  • Move define( 'PMPRODEV_DIR' ) and the migration assistant require_once outside the init function — these have no PMPro dependency and are safe at any load time.
  • Wrap all initialization in a new pmprodev_plugins_loaded() function hooked to plugins_loaded, gated on defined( '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

  1. Install Toolkit with PMPro active under a non-standard folder name (e.g. paid-memberships-pro-rc1) — plugin should initialize correctly.
  2. Install Toolkit without PMPro active — plugin should do nothing, no fatal errors.
  3. Normal install with PMPro active — all Toolkit features work as before.

- 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
@dparker1005
Copy link
Copy Markdown
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.

Copy link
Copy Markdown
Member

@dparker1005 dparker1005 left a comment

Choose a reason for hiding this comment

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

See comment above

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

2 participants