Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix race condition with Update Manager #3321

Merged

Conversation

dparker1005
Copy link
Member

All Submissions:

Changes proposed in this Pull Request:

Currently in core PMPro, includes/addons.php is loaded in 3 places:

  • Whenever is_admin() is true (This is the most common case)
  • When sending the Admin Activity email
  • When sending telemetry data to Wisdom

In the PMPro Update Manager Add On, a duplicate version of includes/addons.php is also sometimes loaded after the init hook completes. The duplicate version is only loaded if function_exists() returns false for one of the addons.php functions.

Whenever is_admin() is true, core PMPro will load addons.php when that plugin is initially loaded, meaning that the Update Manager will never try to load the duplicate version. This is good.

Things get trickier with the other two cases (the Admin Activity email and the telemetry data). In these cases, since the core addons.php file is not always loaded before init, there is a chance that the Update Manager Add On will load its addons.php file. If this happens and core PMPro later sends the Admin Activity email or telemetry data, the core PMPro plugin may also try to load its addons.php file which does not have the same function_exists() safeguards as the Update Manager Add On. This could in turn trigger a fatal error.

Off the top of my head, there are two straightforward solutions here:

  1. Add function_exists() checks around all of the function declarations in core PMPro
  2. Always load the core addons.php file when loading the plugin files

Although the function_exists() check feels safe, it feels iffy that it will be a toss-up between which addons.php file will be loaded when both PMPro and the Update Manager Add On are active. Instead, ensuring that the core PMPro addons.php file is always loaded when possible helps to simplify this logic. The main concern here is around performance issues which this PR resolves by only hooking the functions in this file when is_admin() is true. Otherwise, all functions will be present, but not "active".

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

Enter a summary of all changes on this Pull Request. This will appear in the changelog if accepted.

@dparker1005 dparker1005 merged commit 4ddb3a2 into strangerstudios:dev Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants