Make WordPress Core


Ignore:
Timestamp:
02/19/2010 09:16:14 PM (13 years ago)
Author:
nacin
Message:

Show must-use plugins and drop-ins in the plugins admin panel. First pass. See #11861

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/plugin.php

    r13167 r13233  
    267267
    268268/**
     269 * Check the mu-plugins directory and retrieve all mu-plugin files with any plugin data.
     270 *
     271 * WordPress only includes mu-plugin files in the base mu-plugins directory (wp-content/mu-plugins).
     272 *
     273 * @since 3.0.0
     274 * @return array Key is the mu-plugin file path and the value is an array of the mu-plugin data.
     275 */
     276function get_mu_plugins() {
     277    $wp_plugins = array();
     278    // Files in wp-content/mu-plugins directory
     279    $plugin_files = array();
     280
     281    if ( ! is_dir( WPMU_PLUGIN_DIR ) )
     282        return $wp_plugins;
     283    if ( $plugins_dir = @ opendir( WPMU_PLUGIN_DIR ) ) {
     284        while ( ( $file = readdir( $plugins_dir ) ) !== false ) {
     285            if ( substr( $file, -4 ) == '.php' )
     286                $plugin_files[] = $file;
     287        }
     288    }
     289
     290    @closedir( $plugins_dir );
     291
     292    if ( !$plugins_dir || empty($plugin_files) )
     293        return $wp_plugins;
     294
     295    foreach ( $plugin_files as $plugin_file ) {
     296        if ( !is_readable( WPMU_PLUGIN_DIR . "/$plugin_file" ) )
     297            continue;
     298
     299        $plugin_data = get_plugin_data( WPMU_PLUGIN_DIR . "/$plugin_file", false, false ); //Do not apply markup/translate as it'll be cached.
     300
     301        if ( empty ( $plugin_data['Name'] ) )
     302            $plugin_data['Name'] = $plugin_file;
     303
     304        $wp_plugins[ $plugin_file ] = $plugin_data;
     305    }
     306
     307    if ( isset( $wp_plugins['index.php'] ) && filesize( WPMU_PLUGIN_DIR . '/index.php') <= 30 ) // silence is golden
     308        unset( $wp_plugins['index.php'] );
     309
     310    uasort( $wp_plugins, create_function( '$a, $b', 'return strnatcasecmp( $a["Name"], $b["Name"] );' ));
     311
     312    return $wp_plugins;
     313}
     314
     315/**
     316 * Check the wp-content directory and retrieve all drop-ins with any plugin data.
     317 *
     318 * @since 3.0.0
     319 * @return array Key is the file path and the value is an array of the plugin data.
     320 */
     321function get_dropins() {
     322    $dropins = array();
     323    $plugin_files = array();
     324
     325    $_dropins = _get_dropins();
     326
     327    // These exist in the wp-content directory
     328    if ( $plugins_dir = @ opendir( WP_CONTENT_DIR ) ) {
     329        while ( ( $file = readdir( $plugins_dir ) ) !== false ) {
     330            if ( isset( $_dropins[ $file ] ) )
     331                $plugin_files[] = $file;
     332            }
     333    }
     334
     335    @closedir( $plugins_dir );
     336
     337    if ( !$plugins_dir || empty($plugin_files) )
     338            return $dropins;
     339
     340    foreach ( $plugin_files as $plugin_file ) {
     341            if ( !is_readable( WP_CONTENT_DIR . "/$plugin_file" ) )
     342                    continue;
     343            $plugin_data = get_plugin_data( WP_CONTENT_DIR . "/$plugin_file", false, false ); //Do not apply markup/translate as it'll be cached.
     344            if ( empty ( $plugin_data['Name'] ) )
     345                $plugin_data['Name'] = $plugin_file;
     346            $dropins[ $plugin_file ] = $plugin_data;
     347    }
     348
     349    uksort( $dropins, create_function( '$a, $b', 'return strnatcasecmp( $a, $b );' ));
     350
     351    return $dropins;
     352}
     353
     354/**
     355 * Returns drop-ins that WordPress uses.
     356 *
     357 * Includes Multisite drop-ins only when is_multisite()
     358 *
     359 * @since 3.0.0
     360 * @return array Key is file name. The value is an array, with the first value the
     361 *  purpose of the drop-in and the second value the name of the constant that must be
     362 *  true for the drop-in to be used, or true if no constant is required.
     363 */
     364function _get_dropins() {
     365    $dropins = array(
     366        'advanced-cache.php' => array( __( 'Advanced caching plugin.'       ), 'WP_CACHE' ), // WP_CACHE
     367        'db.php'             => array( __( 'Custom database class.'         ), true ), // auto on load
     368        'db-error.php'       => array( __( 'Custom database error message.' ), true ), // auto on error
     369        'install.php'        => array( __( 'Custom install script.'         ), true ), // auto on install
     370        'maintenance.php'    => array( __( 'Custom maintenance message.'    ), true ), // auto on maintenance
     371        'object-cache.php'   => array( __( 'External object cache.'         ), true ), // auto on load
     372    );
     373
     374    if ( is_multisite() ) {
     375        $dropins['sunrise.php'       ] = array( __( 'Executed before Multisite is loaded.' ), 'SUNRISE' ); // SUNRISE
     376        $dropins['blog-deleted.php'  ] = array( __( 'Custom blog deleted message.'   ), true ); // auto on deleted blog
     377        $dropins['blog-inactive.php' ] = array( __( 'Custom blog inactive message.'  ), true ); // auto on inactive blog
     378        $dropins['blog-suspended.php'] = array( __( 'Custom blog suspended message.' ), true ); // auto on archived or spammed blog
     379    }
     380
     381    return $dropins;
     382}
     383
     384/**
    269385 * Check whether the plugin is active by checking the active_plugins list.
    270386 *
Note: See TracChangeset for help on using the changeset viewer.