[wp-trac] [WordPress Trac] #60504: Plugin dependencies: Account for mu-plugin as dependency

WordPress Trac noreply at wordpress.org
Sun Feb 25 03:57:50 UTC 2024


#60504: Plugin dependencies: Account for mu-plugin as dependency
-------------------------------------------------+-------------------------
 Reporter:  johnbillion                          |       Owner:  costdev
     Type:  defect (bug)                         |      Status:  assigned
 Priority:  normal                               |   Milestone:  6.5
Component:  Upgrade/Install                      |     Version:  trunk
 Severity:  critical                             |  Resolution:
 Keywords:  needs-testing dev-feedback has-      |     Focuses:
  patch has-unit-tests                           |
-------------------------------------------------+-------------------------

Comment (by afragen):

 It seems the issue isn't that some devs use mu-plugins, but that some devs
 add normal dot org plugins into the mu-plugins folder. This means they
 must add a loader to `require` the main plugin file. This will load the
 plugin but the plugin will return a false value for `is_plugin_active()`,
 will not properly show as installed, and makes updating the plugins a
 completely manual process.

 This is non-standard behavior even though WordPress has the ability to
 "make it work". The problem as @johnbillion points out is that mu-plugins
 are managed manually. The primary issue is that once installed and active
 in the mu-plugins folder these plugins are no longer capable of receiving
 updates. This will cause an undue burden on the site admin who must now
 manually update the plugin and will likely just miss the update as they
 would receive no indication that an update is available. It makes
 integration as a plugin dependency difficult, and it may leave a security
 update missing.

 As @knutsp suggested this could be handled by a default MU loader file.
 @costdev and I have created a
 [https://gist.github.com/afragen/9117fd930d9be16be8a5f450b809dfa8 MU
 Loader] that only requires the plugin file name (eg.
 `woocommerce/woocommerce.php`) to be entered as an array variable in the
 loader file. This MU Loader will forcibly load the designated plugin
 within the "normal plugin directory" and filters the `active_plugins`
 option so it is detected as active.

 This isn't a huge barrier to entry for devs as they must already create a
 loader file. Further, I believe this solves all issues that have been
 outlined such as returning a truthy value for `is_plugin_active()` and
 showing as installed.

 All that is required is the normal installation of the plugin and the
 addition of the plugin file as an array variable in the MU Loader file. In
 the case of WooCommerce, simply adding `woocommerce/woocommerce.php` is
 sufficient to load WooCommerce as an mu-plugin. If WooCommerce is declared
 somewhere as a dependency this is also accounted for and WooCommerce also
 shows as an active plugin.


 The mu-loader.php ensures that the plugin shows as both active and
 installed making use as a plugin dependency seamlessly and doesn't require
 any addition modifications to core to use plugins loaded as mu-plugins as
 dependencies. This can also handle multiple plugins ''installed'' as ''mu-
 plugins''.

 Using this type of ''mu-loader'', mu-plugins can work as dependencies
 without needed to modify core.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/60504#comment:15>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list