Fix race condition with Update Manager #3321
Merged
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.
All Submissions:
Changes proposed in this Pull Request:
Currently in core PMPro,
includes/addons.php
is loaded in 3 places:is_admin()
istrue
(This is the most common case)In the PMPro Update Manager Add On, a duplicate version of
includes/addons.php
is also sometimes loaded after theinit
hook completes. The duplicate version is only loaded iffunction_exists()
returnsfalse
for one of theaddons.php
functions.Whenever
is_admin()
is true, core PMPro will loadaddons.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 beforeinit
, there is a chance that the Update Manager Add On will load itsaddons.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 itsaddons.php
file which does not have the samefunction_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:
function_exists()
checks around all of the function declarations in core PMProaddons.php
file when loading the plugin filesAlthough the
function_exists()
check feels safe, it feels iffy that it will be a toss-up between whichaddons.php
file will be loaded when both PMPro and the Update Manager Add On are active. Instead, ensuring that the core PMProaddons.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 whenis_admin()
istrue
. Otherwise, all functions will be present, but not "active".Other information:
Changelog entry