0

Obviously WordPress knows where the plugins that are installed are located.

Compared to other CMS software, the specifications for the location of a WordPress plugin are very loose. If I'm not mistaken, a plugin file is not required to be in the standard plugin folder, and it can be in a subfolder of the plugin folder, or a subfolder in a subfolder. There may even be multiple plugins in the same folder, or another plugin in a folder of an already existing plugin.

The path must, at some point during the installation, be "registered" stored by WordPress. Where exactly does WordPress document this information, and is it easily accessible for the administrator?

  • so what is the question? how does wordpress know to find a directory plugins under wp-content under the root seems to be too trivial to be asked – Mark Kaplun Oct 1 '15 at 8:20
  • The actual question is: Where is the information about the plugin locations stored, taking into account that they might not always be in the wp-content/plugins folder. Or am I mistaken and they are always? – R.G. Oct 1 '15 at 8:27
  • They always (99.99%) have to be there. You can configure it to be in another location by setting up some constants in wp-config.php but it is very rarely done. IIRC you can programmatically add possible location, but I never heard of anyone doing that. – Mark Kaplun Oct 1 '15 at 8:48
0

It's false that a plugin file is not required to be in the standard plugin folder. This plugin folder is defined by the constant WP_PLUGIN_DIR, whose value is WP_CONTENT_DIR . '/plugins'. And if you open /wp-includes/load.php, you will find that function wp_get_active_and_valid_plugins(), defined by

function wp_get_active_and_valid_plugins() {
    $plugins = array();
    $active_plugins = (array) get_option( 'active_plugins', array() );

    // Check for hacks file if the option is enabled
    if ( get_option( 'hack_file' ) && file_exists( ABSPATH . 'my-hacks.php' ) ) {
        _deprecated_file( 'my-hacks.php', '1.5' );
        array_unshift( $plugins, ABSPATH . 'my-hacks.php' );
    }

    if ( empty( $active_plugins ) || defined( 'WP_INSTALLING' ) )
        return $plugins;

    $network_plugins = is_multisite() ? wp_get_active_network_plugins() : false;

    foreach ( $active_plugins as $plugin ) {
        if ( ! validate_file( $plugin ) // $plugin must validate as file
            && '.php' == substr( $plugin, -4 ) // $plugin must end with '.php'
            && file_exists( WP_PLUGIN_DIR . '/' . $plugin ) // $plugin must exist
            // not already included as a network plugin
            && ( ! $network_plugins || ! in_array( WP_PLUGIN_DIR . '/' . $plugin, $network_plugins ) )
            )
        $plugins[] = WP_PLUGIN_DIR . '/' . $plugin;
    }
    return $plugins;
}

retrieves an array of valid and active plugins from the default directory defined by WP_PLUGIN_DIR.

  • Thank you! Seems like I was mistaken. This makes things much easier for me. Many thanks also for the detailed explanation! – R.G. Oct 1 '15 at 8:55
0

Here is the code from where he can get the list if plugins check where is installed

function get_mu_plugins() {
$wp_plugins = array();
// Files in wp-content/mu-plugins directory
$plugin_files = array();

if ( ! is_dir( WPMU_PLUGIN_DIR ) )
    return $wp_plugins;
if ( $plugins_dir = @ opendir( WPMU_PLUGIN_DIR ) ) {
    while ( ( $file = readdir( $plugins_dir ) ) !== false ) {
        if ( substr( $file, -4 ) == '.php' )
            $plugin_files[] = $file;
    }
} else {
    return $wp_plugins;
}

@closedir( $plugins_dir );

if ( empty($plugin_files) )
    return $wp_plugins;

foreach ( $plugin_files as $plugin_file ) {
    if ( !is_readable( WPMU_PLUGIN_DIR . "/$plugin_file" ) )
        continue;

    $plugin_data = get_plugin_data( WPMU_PLUGIN_DIR . "/$plugin_file", false, false ); //Do not apply markup/translate as it'll be cached.

    if ( empty ( $plugin_data['Name'] ) )
        $plugin_data['Name'] = $plugin_file;

    $wp_plugins[ $plugin_file ] = $plugin_data;
}

if ( isset( $wp_plugins['index.php'] ) && filesize( WPMU_PLUGIN_DIR . '/index.php') <= 30 ) // silence is golden
    unset( $wp_plugins['index.php'] );

uasort( $wp_plugins, '_sort_uname_callback' );

return $wp_plugins;

}

code is written in wp-admin\includes\plugin.php

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.