Skip to content

Allow programmatic control of which modules are enabled #33

Closed

Description

@felixarntz

Based on the settings screen from #27 which allows to toggle individual modules on/off via UI, it should alternatively be possible to programmatically control which modules should be enabled. This can be useful for advanced users or environments which would like to use certain modules from the plugin without confronting end users with control over them.

Suggested approach:

  • Introduce a filter perflab_active_modules that filters the return value of the perflab_get_active_modules() function.
  • Skip adding the plugin's settings screen (see perflab_add_modules_page()) if the above filter is being used (check via WP core's has_filter() function).

Activity

  1. added
    [Type] EnhancementA suggestion for improvement of an existing feature
    InfrastructureIssues for the overall performance plugin infrastructure
    Needs DevAnything that requires development (e.g. a pull request)
    on Dec 2, 2021
  2. felixarntz commented on Dec 2, 2021

    @felixarntz
    MemberAuthor

    cc @ThierryA I opened this based on your comment in #27 (comment).

  3. eugene-manuilov commented on Jan 8, 2022

    @eugene-manuilov
    Contributor

    Suggested approach:

    • Introduce a filter perflab_active_modules that filters the return value of the perflab_get_active_modules() function.
    • Skip adding the plugin's settings screen (see perflab_add_modules_page()) if the above filter is being used (check via WP core's has_filter() function).

    @felixarntz, how about using the theme support feature instead of the custom filter? In this case, if someone programmatically activates a module using the module slug (for example, add_theme_support( 'webp-uploads' )), they won't need to re-activate it in the future when this module makes it to the core.

    I have prepared a draft PR #82 that implements this idea. Do you mind taking a look at it?

    P.S: that PR contains some refactoring for the general utility functions defined in the admin/load.php and load.php files. Nothing special, just re-organised them a little bit and made it possible to use settings and module related functions not only in the admin.

  4. eclarke1 commented on Jan 11, 2022

    @eclarke1

    @eugene-manuilov can we remove the Needs Dev label from here too, as it is in Progress now? @bethanylang

  5. removed
    Needs DevAnything that requires development (e.g. a pull request)
    on Jan 11, 2022
  6. eugene-manuilov commented on Jan 11, 2022

    @eugene-manuilov
    Contributor

    Done.

  7. felixarntz commented on Jan 12, 2022

    @felixarntz
    MemberAuthor

    @eugene-manuilov I don't think add_theme_support is appropriate for this, since these modules aren't theme features. While it would work, as the name of that function states, it should be used for theme features provided by a plugin or core, which would be enabled from within the theme's codebase. But the use-case here will be most likely must-use plugins, e.g. injected by an agency or hosting provider that wants the site to use a predefined list of modules and not allow the user to change them.

    The typical core approach for modifying an option like this would be a filter as suggested in the issue description.

    Looking at #82, it is massive for this type of change :) I don't think this is the right place to do this refactoring, typically in WordPress core changes should be kept as simple as possible and avoid refactoring unless it is necessary for the issue or if the issue itself is about refactoring. Can you please simplify this to working with how things are currently written? I don't disagree with the changes there overall, but we should discuss this in a separate issue - feel free to open one. 👍

  8. eugene-manuilov commented on Jan 12, 2022

    @eugene-manuilov
    Contributor

    @felixarntz, ok, got it. Thanks for the feedback. I have decided to create a new PR with suggested changes: #87. Do you mind reviewing it?

  9. felixarntz commented on Jan 16, 2022

    @felixarntz
    MemberAuthor

    Could someone else review the PR #87? Approved from my end, but best to have at least two approvals. cc @JustinyAhin

  10. removed their assignment
    on Jan 16, 2022
  11. felixarntz commented on Jan 18, 2022

    @felixarntz
    MemberAuthor

    Fixed via #87

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

InfrastructureIssues for the overall performance plugin infrastructure[Type] EnhancementA suggestion for improvement of an existing feature

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions