#5766 - Many missing addon guards
0 guests and 0 members have recently viewed this.
The top 3 point earners from 14th Dec 2025 to 21st Dec 2025.
| PDStig |
|
|
|---|---|---|
| Gabri |
|
|
| sholzy |
|
|
There are no events at this time
This hotfix adds guards for addons based on get_option . There is no guarantee we got all of them.
The addon_guards test has been modified to pick up on get_option (and ignore ones whose second parameter (missing_ok) is true).
We still need to account for templates sometime. Also, the test should ideally be modified to be more concise... scan by function instead of by entire file (e.g. if one addon_installed check is detected, it determines the entire file as good even if the guard may actually be needed in another function).
The modifications to addon_guards include the following:
- Primarily, it now uses the phpdoc.php API function to parse code based on class and function. That way, we can check for guards by function and not by entire file.
- The test is much more smart with smart exceptions to define cases where a class might define its guards in a specific function to be applied to all functions in the class (assumed). For example, info.
- The test checks for, and fails on, use of !addon_installed when we should use !addon_installed__messaged.
- The test checks for, and fails on, use of positive assertions for cohesion (instead, for stability, we should be using negative assertions towards the top of a function with a return).
- When checking implicit code calls, the test keeps track of which addon guards are active by tokenising the code and storing the active guards in an array "stack", popping out as we close out of code blocks. Additionally, this check assumes negative assertions will always return, therefore it treats it as a positive assertion on the parent code block (e.g. one level up in the stack).
Many, many fixes were implemented thanks to the changes to this test and what it detected. Again, not perfect, and the test cannot handle $missing_okay on get_option yet (nor does it check templates). But it's a big step forward.