Advanced Hooks Enable Minimal Code
Building on the autoloader, the files are loaded automatically but by using dynamic hooks and filters with a few conditional checks where it isn't possible to use a dynamic hook.
This allows for the code to be well abstracted with the least amount of code on a given page load.
- Class based files are automatically loaded so you don't have to check if a class exists before loading it
- Code is extremely simple
- Even bigger gains in efficiency over the previous autoload method
- Continues to encourage properly abstracted code which can improve testability and keep code more streamlined
- Ensures JS and CSS files are loaded only when needed with the fewest conditional statements to reduce potential for code conflict and logic errors.
- Requires planning and research
- Not all dynamic hooks are documented
- Not all dynamic hooks are intended to be used (they aren't being used for this example plugin so it requires some additional work arounds)
Compared to all previous versions this is the most efficient loading method. On any given page load no extraneous files are loaded, but when needed the files are automatically loaded with minimal conditional logic.
The scripts and styles are loaded only on the intended pages.
With the reduced loading, average page load speeds and page size is dramatically improved. While much of this size and time is intentionally added through a loop, it is intended to simulate load in a medium complex plugin.
Because some hooks and filters do not have dynamic equivalents some code has to be added with conditional logic. With care, even this code can be minimized so it is run as seldom as possible.
There are still some ways the code can be improved. DRY code, views, small units, and other improvements can always be used. The goal is not perfect code, but continually perfecting code.