Make WordPress Core

Opened 14 years ago

Last modified 6 years ago

#15906 new defect (bug)

validate_plugin needs all_plugins filter

Reported by: wpmuguru's profile wpmuguru Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Plugins Keywords: has-patch
Focuses: Cc:

Description

If a plugin adds plugins to the plugin list in the plugin admin screens using the all_plugins filter, the added plugins will not validate. If the all_plugins filter is added to the validate function, then the plugin validates and activates fine.

Attachments (1)

15906.diff (615 bytes) - added by wpmuguru 14 years ago.

Download all attachments as: .zip

Change History (10)

@wpmuguru
14 years ago

#1 @SergeyBiryukov
14 years ago

get_plugins() function is used in several more places (e.g. in Plugin Editor). Shouldn't we use all_plugins filter in get_plugins() itself?

#2 @wpmuguru
14 years ago

If it was added to get_plugins, then both the $plugin_folder parameter & context (ex. plugin_editor) should be provided to the filter. So, I'm not sure that moving the filter there would provide any benefit.

#3 follow-up: @nacin
14 years ago

We killed off the all_plugins filters in 3.0, I believe.

#4 in reply to: ↑ 3 @wpmuguru
14 years ago

Replying to nacin:

We killed off the all_plugins filters in 3.0, I believe.

It's in https://core.trac.wordpress.org/browser/trunk/wp-admin/includes/class-wp-plugins-list-table.php#L47

as of R17228.

#5 @nacin
14 years ago

I was thinking of active_plugins: [12947].

#6 @wpmuguru
14 years ago

I'm good with punting this one to 3.2.

#7 @dd32
14 years ago

  • Milestone changed from Awaiting Review to Future Release

*Punt*

#8 @chriscct7
10 years ago

Patch still valid. @dd32 did you want to re-evaluate this?

#9 @ocean90
9 years ago

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 `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
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;
} );
Note: See TracTickets for help on using tickets.