[wp-trac] [WordPress Trac] #15906: validate_plugin needs all_plugins filter

WordPress Trac noreply at wordpress.org
Sun Oct 25 17:33:22 UTC 2015


#15906: validate_plugin needs all_plugins filter
--------------------------+-----------------------------
 Reporter:  wpmuguru      |       Owner:
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Future Release
Component:  Plugins       |     Version:
 Severity:  normal        |  Resolution:
 Keywords:  has-patch     |     Focuses:
--------------------------+-----------------------------

Comment (by ocean90):

 I just stumbled over this one. Adding a plugin via `all_plugins` can't be
 activated, because `validate_plugin()` doesn't know the plugin.

 The filter was moved to core in [12722], but was originally requested in
 https://mu.trac.wordpress.org/ticket/656. The reporter wanted to have the
 filter in [https://mu.trac.wordpress.org/browser/trunk/wp-
 admin/includes/plugin.php#L191 `get_plugins()`], but it got added to the
 list table instead, see https://mu.trac.wordpress.org/changeset/1333/.

 Adding the filter to `get_plugins()` itself would be tricky because it
 already does plenty of work and also caching. I think adding the filter to
 each `get_plugins()` call where it could make sense should be harmless. In
 this case it's only `validate_plugin()` because I don't think that the
 plugin editor and the upgrade/install process are quite useful for custom
 plugins.

 My current code is:
 {{{#!php
 <?php
 add_filter( 'all_plugins', function( $plugins ) {
         $_gp_plugins = get_plugins( '/gp-plugins' );  // WP_PLUGIN_DIR .
 '/gp-plugins'

         // Fix plugin file path
         $gp_plugins = array();
         foreach ( $_gp_plugins as $file => $data ) {
                 $gp_plugins[ 'gp-plugins/' . $file ] = $data;
         }

         $plugins = array_merge( $plugins, $gp_plugins );
         unset( $_gp_plugins );

         return $plugins;
 } );
 }}}

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


More information about the wp-trac mailing list