Make WordPress Core

Changeset 13233


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

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

Location:
trunk/wp-admin
Files:
2 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 *
  • trunk/wp-admin/plugins.php

    r13167 r13233  
    2828    $default_status = 'all';
    2929$status = isset($_REQUEST['plugin_status']) ? $_REQUEST['plugin_status'] : $default_status;
    30 if ( !in_array($status, array('all', 'active', 'inactive', 'recent', 'upgrade', 'network', 'search')) )
     30if ( !in_array($status, array('all', 'active', 'inactive', 'recent', 'upgrade', 'network', 'mustuse', 'dropins', 'search')) )
    3131    $status = 'all';
    3232if ( $status != $default_status && 'search' != $status )
     
    366366$upgrade_plugins = array();
    367367$network_plugins = array();
     368$mustuse_plugins = get_mu_plugins();
     369$dropins_plugins = get_dropins();
    368370
    369371set_transient( 'plugin_slugs', array_keys($all_plugins), 86400 );
     
    377379$current = get_site_transient( 'update_plugins' );
    378380
    379 foreach ( (array)$all_plugins as $plugin_file => $plugin_data) {
    380 
    381     // Translate, Apply Markup, Sanitize HTML
    382     $plugin_data = _get_plugin_data_markup_translate($plugin_file, $plugin_data, false, true);
    383     $all_plugins[ $plugin_file ] = $plugin_data;
    384 
     381foreach ( array( 'all_plugins', 'mustuse_plugins', 'dropins_plugins' ) as $plugin_array_name) {
     382    foreach ( (array) $$plugin_array_name as $plugin_file => $plugin_data ) {
     383        // Translate, Apply Markup, Sanitize HTML
     384        $plugin_data = _get_plugin_data_markup_translate($plugin_file, $plugin_data, false, true);
     385        $$plugin_array_name[ $plugin_file ] = $plugin_data;
     386    }
     387}
     388unset( $plugin_array_name );
     389
     390foreach ( (array) $all_plugins as $plugin_file => $plugin_data) {
    385391    // Filter into individual sections
    386392    if ( is_plugin_active_for_network($plugin_file) && is_super_admin() ) {
     
    407413$total_upgrade_plugins = count($upgrade_plugins);
    408414$total_network_plugins = count($network_plugins);
     415$total_mustuse_plugins = count($mustuse_plugins);
     416$total_dropins_plugins = count($dropins_plugins);
    409417
    410418//Searching.
     
    470478function print_plugins_table($plugins, $context = '') {
    471479    global $page;
     480    $checkbox = ! in_array( $context, array( 'mustuse', 'dropins' ) ) ? '<input type="checkbox" />' : '';
    472481?>
    473482<table class="widefat" cellspacing="0" id="<?php echo $context ?>-plugins-table">
    474483    <thead>
    475484    <tr>
    476         <th scope="col" class="manage-column check-column"><input type="checkbox" /></th>
     485        <th scope="col" class="manage-column check-column"><?php echo $checkbox; ?></th>
    477486        <th scope="col" class="manage-column"><?php _e('Plugin'); ?></th>
    478487        <th scope="col" class="manage-column"><?php _e('Description'); ?></th>
     
    482491    <tfoot>
    483492    <tr>
    484         <th scope="col" class="manage-column check-column"><input type="checkbox" /></th>
     493        <th scope="col" class="manage-column check-column"><?php echo $checkbox; ?></th>
    485494        <th scope="col" class="manage-column"><?php _e('Plugin'); ?></th>
    486495        <th scope="col" class="manage-column"><?php _e('Description'); ?></th>
     
    498507    foreach ( (array)$plugins as $plugin_file => $plugin_data) {
    499508        $actions = array();
    500         $is_active_for_network = is_plugin_active_for_network($plugin_file);
    501         $is_active = $is_active_for_network || is_plugin_active( $plugin_file );
    502 
    503         if ( $is_active_for_network && !is_super_admin() )
    504             continue;
    505 
    506         if ( $is_active ) {
    507             if ( $is_active_for_network ) {
    508                 if ( is_super_admin() )
    509                     $actions[] = '<a href="' . wp_nonce_url('plugins.php?action=deactivate&amp;networkwide=1&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page, 'deactivate-plugin_' . $plugin_file) . '" title="' . __('Deactivate this plugin') . '">' . __('Network Deactivate') . '</a>';
     509        if ( 'mustuse' == $context ) {
     510            $is_active = true;
     511        } elseif ( 'dropins' == $context ) {
     512            $dropins = _get_dropins();
     513            $plugin_name = $plugin_file;
     514            if ( $plugin_file != $plugin_data['Name'] )
     515                $plugin_name .= '<br/>' . $plugin_data['Name'];
     516            if ( true === ( $dropins[ $plugin_file ][1] ) ) { // Doesn't require a constant
     517                $is_active = true;
     518                $description = '<p><strong>' . $dropins[ $plugin_file ][0] . '</strong></p>';
     519            } elseif ( constant( $dropins[ $plugin_file ][1] ) ) { // Constant is true
     520                $is_active = true;
     521                $description = '<p><strong>' . $dropins[ $plugin_file ][0] . '</strong></p>';
    510522            } else {
    511                 $actions[] = '<a href="' . wp_nonce_url('plugins.php?action=deactivate&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page, 'deactivate-plugin_' . $plugin_file) . '" title="' . __('Deactivate this plugin') . '">' . __('Deactivate') . '</a>';
    512             }
     523                $is_active = false;
     524                $description = '<strong>' . $dropins[ $plugin_file ][0] . ' <span class="attention">' . __('Inactive:') . '</span></strong> ' . sprintf( __( 'Requires <code>%s</code> in <code>wp-config.php</code>.' ), "define('" . $dropins[ $plugin_file ][1] . "', true);" ) . '</p>';
     525            }
     526            $description .= '<p>' . $plugin_data['Description'] . '</p>';
    513527        } else {
     528            $is_active_for_network = is_plugin_active_for_network($plugin_file);
     529            $is_active = $is_active_for_network || is_plugin_active( $plugin_file );
     530            if ( $is_active_for_network && !is_super_admin() )
     531                continue;
     532
     533            if ( $is_active ) {
     534                if ( $is_active_for_network ) {
     535                    if ( is_super_admin() )
     536                        $actions[] = '<a href="' . wp_nonce_url('plugins.php?action=deactivate&amp;networkwide=1&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page, 'deactivate-plugin_' . $plugin_file) . '" title="' . __('Deactivate this plugin') . '">' . __('Network Deactivate') . '</a>';
     537                } else {
     538                    $actions[] = '<a href="' . wp_nonce_url('plugins.php?action=deactivate&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page, 'deactivate-plugin_' . $plugin_file) . '" title="' . __('Deactivate this plugin') . '">' . __('Deactivate') . '</a>';
     539                }
     540            } else {
     541                $actions[] = '<a href="' . wp_nonce_url('plugins.php?action=activate&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page, 'activate-plugin_' . $plugin_file) . '" title="' . __('Activate this plugin') . '" class="edit">' . __('Activate') . '</a>';
     542                if ( is_multisite() && is_super_admin() )
     543                    $actions[] = '<a href="' . wp_nonce_url('plugins.php?action=activate&amp;networkwide=1&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page, 'activate-plugin_' . $plugin_file) . '" title="' . __('Activate this plugin for all sites in this network') . '" class="edit">' . __('Network Activate') . '</a>';
     544            }
     545
    514546            if ( is_multisite() && is_network_only_plugin( $plugin_file ) )
    515547                $actions[] = '<span title="' . __('This plugin can only be activated for all sites in a network') . '">' . __('Network Only') . '</span>';
     
    518550            if ( is_multisite() && is_super_admin() )
    519551                $actions[] = '<a href="' . wp_nonce_url('plugins.php?action=activate&amp;networkwide=1&amp;plugin=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page, 'activate-plugin_' . $plugin_file) . '" title="' . __('Activate this plugin for all sites in this network') . '" class="edit">' . __('Network Activate') . '</a>';
     552
     553            if ( !is_multisite() && current_user_can('edit_plugins') && is_writable(WP_PLUGIN_DIR . '/' . $plugin_file) )
     554                $actions[] = '<a href="plugin-editor.php?file=' . $plugin_file . '" title="' . __('Open this file in the Plugin Editor') . '" class="edit">' . __('Edit') . '</a>';
     555
     556            if ( ! $is_active && current_user_can('delete_plugins') )
     557                $actions[] = '<a href="' . wp_nonce_url('plugins.php?action=delete-selected&amp;checked[]=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page, 'bulk-manage-plugins') . '" title="' . __('Delete this plugin') . '" class="delete">' . __('Delete') . '</a>';
     558
    520559        }
    521 
    522         if ( !is_multisite() && current_user_can('edit_plugins') && is_writable(WP_PLUGIN_DIR . '/' . $plugin_file) )
    523             $actions[] = '<a href="plugin-editor.php?file=' . $plugin_file . '" title="' . __('Open this file in the Plugin Editor') . '" class="edit">' . __('Edit') . '</a>';
    524 
    525         if ( ! $is_active && current_user_can('delete_plugins') )
    526             $actions[] = '<a href="' . wp_nonce_url('plugins.php?action=delete-selected&amp;checked[]=' . $plugin_file . '&amp;plugin_status=' . $context . '&amp;paged=' . $page, 'bulk-manage-plugins') . '" title="' . __('Delete this plugin') . '" class="delete">' . __('Delete') . '</a>';
    527560
    528561        $actions = apply_filters( 'plugin_action_links', $actions, $plugin_file, $plugin_data, $context );
    529562        $actions = apply_filters( "plugin_action_links_$plugin_file", $actions, $plugin_file, $plugin_data, $context );
    530         $action_count = count($actions);
     563
    531564        $class = $is_active ? 'active' : 'inactive';
     565        $checkbox = in_array( $context, array( 'mustuse', 'dropins' ) ) ? '' : "<input type='checkbox' name='checked[]' value='" . esc_attr($plugin_file) . "' />";
     566        if ( 'dropins' != $context ) {
     567            $description = '<p>' . $plugin_data['Description'] . '</p>';
     568            $plugin_name = $plugin_data['Name'];
     569        }
    532570        echo "
    533571    <tr class='$class'>
    534         <th scope='row' class='check-column'><input type='checkbox' name='checked[]' value='" . esc_attr($plugin_file) . "' /></th>
    535         <td class='plugin-title'><strong>{$plugin_data['Name']}</strong></td>
    536         <td class='desc'><p>{$plugin_data['Description']}</p></td>
     572        <th scope='row' class='check-column'>$checkbox</th>
     573        <td class='plugin-title'><strong>$plugin_name</strong></td>
     574        <td class='desc'>$description</td>
    537575    </tr>
    538576    <tr class='$class second'>
     
    578616 */
    579617function print_plugin_actions($context, $field_name = 'action' ) {
     618    if ( in_array( $context, array( 'mustuse', 'dropins' ) ) )
     619        return;
    580620?>
    581621    <div class="alignleft actions">
     
    643683    $status_links[] = "<li><a href='plugins.php?plugin_status=network' $class>" . sprintf( _n( 'Network <span class="count">(%s)</span>', 'Network <span class="count">(%s)</span>', $total_network_plugins ), number_format_i18n( $total_network_plugins ) ) . '</a>';
    644684}
     685if ( ! empty($mustuse_plugins) ) {
     686    $class = ( 'mustuse' == $status ) ? ' class="current"' : '';
     687    $status_links[] = "<li><a href='plugins.php?plugin_status=mustuse' $class>" . sprintf( _n( 'Must-Use <span class="count">(%s)</span>', 'Must-Use <span class="count">(%s)</span>', $total_mustuse_plugins ), number_format_i18n( $total_mustuse_plugins ) ) . '</a>';
     688}
     689if ( ! empty($dropins_plugins) ) {
     690    $class = ( 'dropins' == $status ) ? ' class="current"' : '';
     691    $status_links[] = "<li><a href='plugins.php?plugin_status=dropins' $class>" . sprintf( _n( 'Drop-ins <span class="count">(%s)</span>', 'Drop-ins <span class="count">(%s)</span>', $total_dropins_plugins ), number_format_i18n( $total_dropins_plugins ) ) . '</a>';
     692}
    645693if ( ! empty($upgrade_plugins) ) {
    646694    $class = ( 'upgrade' == $status ) ? ' class="current"' : '';
     
    657705</ul>
    658706
    659 <?php if ( ! empty( $plugins ) ) { ?>
    660 
     707<?php
     708if ( 'mustuse' == $status )
     709    echo '<div class="clear"><p>' . __( 'Files in the <code>wp-content/mu-plugins</code> directory are executed automatically.' ) . '</p>';
     710elseif ( 'dropins' == $status )
     711    echo '<div class="clear"><p>' . __( 'Drop-ins are advanced plugins in the <code>wp-content</code> directory that replace WordPress functionality when present.' ) . '</p>';
     712
     713if ( !empty( $plugins ) && ( ! in_array( $status, array( 'mustuse', 'dropins' ) ) || $page_links ) ) :
     714?>
    661715<div class="tablenav">
    662716<?php
     
    669723<div class="clear"></div>
    670724<?php
    671     if ( $total_this_page > $plugins_per_page )
    672         $plugins = array_slice($plugins, $start, $plugins_per_page);
    673 
    674     print_plugins_table($plugins, $status);
     725endif;
     726
     727if ( $total_this_page > $plugins_per_page )
     728    $plugins = array_slice($plugins, $start, $plugins_per_page);
     729
     730print_plugins_table($plugins, $status);
     731
     732if ( !empty( $plugins ) && ! in_array( $status, array( 'mustuse', 'dropins' ) ) || $page_links ) {
    675733?>
    676734<div class="tablenav">
Note: See TracChangeset for help on using the changeset viewer.