[wp-trac] [WordPress Trac] #37656: Improve plugin bootstrapping processes with `WP_Plugin`

WordPress Trac noreply at wordpress.org
Sun Aug 14 11:32:29 UTC 2016


#37656: Improve plugin bootstrapping processes with `WP_Plugin`
-------------------------+-----------------------------
 Reporter:  flixos90     |      Owner:
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  Plugins      |    Version:
 Severity:  normal       |   Keywords:
  Focuses:               |
-------------------------+-----------------------------
 I recently thought about if we could make bootstrapping plugins easier and
 take away some common tasks that (should) happen in every plugin. It would
 also be nice to have a general plugin class registry.

 What I was thinking of is to introduce an abstract class `WP_Plugin` that
 plugin developers can extend for their plugin's main class. Then they
 would call a new function `register_plugin( __FILE__, $plugin_class_name
 )` to register that class with WordPress. We could take some regular
 processes away from the developer and, by doing that, also make sure that
 they don't implement it the wrong way. For example, we could take care of
 plugin installation routines: If the class implements a static method
 `install()`, the base class `WP_Plugin` would register an activation hook
 to an internal function that takes care of whether the plugin is activated
 network-wide. The actual `install()` method would only contain those steps
 necessary for the setup on the current site (`WP_Plugin` would take care
 of switching sites as appropriate). Many plugin developers overlook
 Multisite in their setup routines, causing the plugin to only install on
 the main site although being network-activated. We could also deal with
 other tasks, like hooking the `bootstrap()` method of the plugin class in
 `plugins_loaded` or `muplugins_loaded` (detected by the base class).

 I think this whole concept could improve the way plugins initialize
 themselves. It would not be mandatory (since several plugins don't even
 use classes), but it would become a best practice. This is just an idea
 that I wanted to throw on Trac to discuss about it. If we get to the point
 that we agree this is a good idea, we would need to come up with actual
 details (of which I don't have any yet).

--
Ticket URL: <https://core.trac.wordpress.org/ticket/37656>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list