[wp-trac] [WordPress Trac] #41346: Introduce a hook for individual plugin loaded

WordPress Trac noreply at wordpress.org
Mon Jul 17 17:10:02 UTC 2017


#41346: Introduce a hook for individual plugin loaded
-----------------------------+------------------------------
 Reporter:  Rarst            |       Owner:
     Type:  feature request  |      Status:  new
 Priority:  normal           |   Milestone:  Awaiting Review
Component:  Plugins          |     Version:  trunk
 Severity:  normal           |  Resolution:
 Keywords:                   |     Focuses:  performance
-----------------------------+------------------------------

Comment (by schlessera):

 Why not go all in and make it a flexible system that can be the basis of
 additional work?

 {{{#!php
 // Pre action to allow for timing hooks to be set,
 // debugging information to be initialized, etc...
 // Could also allow for the loading to be skipped.
 // Dangerous hook, though, needs careful consideration.
 $should_load = apply_filters( 'pre_plugin_loaded', $plugin );

 // Actually load the plugin.
 $should_load && include_once( $plugin );

 // Post hook to catch timings, debugging state, etc...
 do_action( 'post_plugin_loaded', $plugin );

 // Named hook to actually have a proper chance of building a simple
 // dependency resolution mechanism.
 $plugin_slug = some_method_to_efficiently_retrieve_plugin_slug();
 do_action( "plugin_loaded_{$plugin_slug}", $plugin );
 }}}

 As an example for the usefulness of the named hook, such a very simple
 system has been used in WP_CLI to automatically resolve dependencies
 between commands. The basic principle would be applicable as well here. If
 a plugin knows it depends on `jetpack`, it can check whether `jetpack` is
 available when loading, and if not, it can postpone its loading by
 attaching its own loading process onto the `plugin_loaded_jetpack` hook.

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


More information about the wp-trac mailing list