Skip to content

Implement mechanism to not load module if core version is available #293

@felixarntz

Description

@felixarntz

As entire modules eventually get merged into core, the plugin should provide a mechanism to not load certain modules if their core counterpart is already available on the site.

We need some centralized infrastructure that each module can leverage to determine when the module is relevant to be loaded. If a module defines that based on the current situation it is no longer needed to be loaded, this should furthermore surface to the administrator on the Performance Lab modules admin screen.

Proposed implementation:

  • Add support for an optional can-load.php file that can be present in each module directory.
    • If the file is present, it should be expected to return a closure function that computes whether the module is relevant to be loaded in the current environment. For example, if a module has already been merged into WordPress core and that core version is already running on the current site, the closure function should return false. This can be typically accomplished by checking for the existence of certain WordPress core functions related to the module's feature set.
    • If the file is not present, it should be assumed that the module can be loaded (similar to today).
    • The foundation for this should be implemented in a perflab_can_load_module( $module ) : bool function which expects the module directory relative to the modules root directory to be passed (e.g. images/webp-uploads).
  • When loading the active modules, for each module the above should be checked via perflab_can_load_module(). In case the can-load.php file exists and its closure function returns false, that module should not be loaded.
  • The "Performance" admin screen should be enhanced so that modules that cannot be loaded in the current environment (checked via perflab_can_load_module()) are marked as such:
    • Each module that cannot be loaded in the current environment should have its input[type="checkbox"] as readonly.
    • In addition, the checkbox label should in that case be overwritten to say: %s is already part of your WordPress version and therefore cannot be loaded as part of the plugin. (where %s is the module name)

As part of this issue, the new feature should only be implemented by the images/webp-uploads module:

Metadata

Metadata

Labels

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

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions