Repository navigation
Allow programmatic control of active modules - #82
eugene-manuilov wants to merge 8 commits into
Conversation
…ivate a module using the add_theme_support function.
felixarntz
left a comment
There was a problem hiding this comment.
@eugene-manuilov I left most of my feedback already in #33 (comment). The main technical problem with the approach is that we should not use perflab_get_modules outside of the admin. And there is way too much refactoring going on here, most of which isn't needed for this and in the case of the perflab_get_modules function for example isn't even desirable - this function should remain limited to the admin.
Can you simplify this to apply a filter in perflab_get_active_modules? Last but not least, as far as I can tell the second bullet point in the #33 issue description isn't covered here yet.
| */ | ||
| function perflab_get_active_modules() { | ||
| $module_settings = perflab_get_module_settings(); | ||
| $all_modules = perflab_get_modules(); |
There was a problem hiding this comment.
This function shouldn't be used outside of the admin, intentionally, as getting all available modules is considered an "expensive" function. We don't need to know which modules exist to get the active modules, we can just look at the option. With the originally proposed approach of a filter we also don't need to. The filter would control the entire list of which modules should be active.
FYI the entire functionality here is based on how plugins work in WordPress core: Active plugins are simply read from the option, while parsing all plugins that are available is limited to the admin as it should be avoided e.g. on every page load.
|
@felixarntz, I have created a new PR #87. Do you mind looking at it? Going to close this one. |
add_theme_support( 'module-slug' )call.To test the theme support feature, add
add_theme_support( 'webp-uploads' )to your theme'sfunctions.phpfile. Once you add this, the module will be programmatically activated and you won't be able to disable it in the settings: