stuttter / wp-spider-cache

Your friendly neighborhood caching solution for WordPress
GNU General Public License v2.0
134 stars 16 forks source link

Remove plugin headers from drop-ins #18

Closed swissspidy closed 7 years ago

swissspidy commented 8 years ago

When installing the plugin from WordPress.org, WordPress wrongly detects the drop-ins as the main plugin files because they contain a valid plugin header. That means the plugin can't be activated right away after installing.

On the "Installed Plugins" screen, it works as expected.

JJJ commented 8 years ago

Interesting.

I'd be more inclined to call this a bug in WordPress. Plugin folders shouldn't legitimately contain more than 1 header, and it should probably stop once it's found one. That way packages like this are possible, and drop-ins -- which support plugin headers -- can continue to have them.

I wonder if it's actually allowed/supported for a plugin's directory to have multiple. Hmm.

swissspidy commented 8 years ago

It's possible to have multiple plugin files in one folder, WordPress allows it. In the early days Jetpack "bundled" a few plugins, for example. I thought it's not allowed in the repository, but your plugin seems to prove me wrong.

Of course it's a bad practice, but, you know, back compat.

swissspidy commented 8 years ago

It's pretty weird. Normally, plugins in the same folder are all displayed in the plugin list table, here that doesn't seem to be the case. So it might indeed be a bug in WordPress. That would explain the behaviour (not working after install but working in the plugin list table).

I hope I'll find time to test this more…

Related: https://core.trac.wordpress.org/ticket/35145

swissspidy commented 8 years ago

@swissspidy can you confirm if this is still an issue with drop-ins being nested a second directory deep?

Can't really test since it's not yet on WordPress.org, but I had another look at core. The relevant code in wp_ajax_install_plugin() is as follows:

$api = plugins_api( 'plugin_information', array(
    'slug'   => sanitize_key( wp_unslash( $_POST['slug'] ) ),
    'fields' => array(
        'sections' => false,
    ),
) );

$install_status = install_plugin_install_status( $api );

$status['activateUrl'] = add_query_arg( array(
    '_wpnonce' => wp_create_nonce( 'activate-plugin_' . $install_status['file'] ),
    'action'   => 'activate',
    'plugin'   => $install_status['file'],
), network_admin_url( 'plugins.php' ) );

In install_plugin_install_status():

$installed_plugin = get_plugins('/' . $api->slug);
$key = array_keys( $installed_plugin );
$key = reset( $key ); // Use the first plugin regardless of the name, Could have issues for multiple-plugins in one directory if they share different version numbers

There it is!

szepeviktor commented 7 years ago

Please consider keeping a line comment: Spider-Cache advanced cache drop-in

swissspidy commented 7 years ago

Can't seem to reproduce this anymore when "shiny" installing & activating WP Spider Cache. 🤷‍♂️