WordPress.org

Make WordPress Core

Ticket #11861: 11861.1.mu.diff

File 11861.1.mu.diff, 10.2 KB (added by nacin, 8 years ago)

Exposes mu-plugins in admin area

  • wp-admin/plugins.php

     
    2727if ( empty($default_status) )
    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', 'search')) )
     30if ( !in_array($status, array('all', 'active', 'inactive', 'recent', 'upgrade', 'search', 'advanced')) )
    3131        $status = 'all';
    3232if ( $status != $default_status && 'search' != $status )
    3333        update_usermeta($current_user->ID, 'plugins_last_view', $status);
     
    287287<?php
    288288
    289289$all_plugins = get_plugins();
     290$advanced_plugins = get_mu_plugins();
    290291$search_plugins = array();
    291292$active_plugins = array();
    292293$inactive_plugins = array();
     
    323324        $upgrade_plugins[ $plugin_file ] = $plugin_data;
    324325}
    325326
     327foreach ( (array)$advanced_plugins as $plugin_file => $plugin_data) {
     328        //Translate, Apply Markup, Sanitize HTML
     329        $plugin_data = _get_plugin_data_markup_translate($plugin_file, $plugin_data, false, true);
     330        $advanced_plugins[ $plugin_file ] = $plugin_data;
     331}
     332
    326333$total_all_plugins = count($all_plugins);
     334$total_advanced_plugins = count($advanced_plugins);
    327335$total_inactive_plugins = count($inactive_plugins);
    328336$total_active_plugins = count($active_plugins);
    329337$total_recent_plugins = count($recent_plugins);
     
    391399 */
    392400function print_plugins_table($plugins, $context = '') {
    393401        global $page;
     402        if ( empty( $plugins ) ) {
     403                echo '<p>' . __('No plugins to show') . '</p>';
     404                return;
     405        }               
    394406?>
    395407<table class="widefat" cellspacing="0" id="<?php echo $context ?>-plugins-table">
    396408        <thead>
    397409        <tr>
    398                 <th scope="col" class="manage-column check-column"><input type="checkbox" /></th>
     410                <th scope="col" class="manage-column check-column"><?php if ( 'advanced' != $context ) { ?><input type="checkbox" /><?php } ?></th>
    399411                <th scope="col" class="manage-column"><?php _e('Plugin'); ?></th>
    400412                <th scope="col" class="manage-column"><?php _e('Description'); ?></th>
    401413        </tr>
     
    403415
    404416        <tfoot>
    405417        <tr>
    406                 <th scope="col" class="manage-column check-column"><input type="checkbox" /></th>
     418                <th scope="col" class="manage-column check-column"><?php if ( 'advanced' != $context ) { ?><input type="checkbox" /><?php } ?></th>
    407419                <th scope="col" class="manage-column"><?php _e('Plugin'); ?></th>
    408420                <th scope="col" class="manage-column"><?php _e('Description'); ?></th>
    409421        </tr>
     
    411423
    412424        <tbody class="plugins">
    413425<?php
    414 
    415         if ( empty($plugins) ) {
    416                 echo '<tr>
    417                         <td colspan="3">' . __('No plugins to show') . '</td>
    418                 </tr>';
    419         }
    420426        foreach ( (array)$plugins as $plugin_file => $plugin_data) {
    421427                $actions = array();
    422                 $is_active = is_plugin_active($plugin_file);
     428                if ( 'advanced' == $context ) {
     429                        $is_active = true;
     430                } else {
     431                        $is_active = is_plugin_active($plugin_file);
    423432
    424                 if ( $is_active )
    425                         $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>';
    426                 else
    427                         $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>';
     433                        if ( $is_active )
     434                                $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>';
     435                        else
     436                                $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>';
    428437
    429                 if ( current_user_can('edit_plugins') && is_writable(WP_PLUGIN_DIR . '/' . $plugin_file) )
    430                         $actions[] = '<a href="plugin-editor.php?file=' . $plugin_file . '" title="' . __('Open this file in the Plugin Editor') . '" class="edit">' . __('Edit') . '</a>';
     438                        if ( current_user_can('edit_plugins') && is_writable(WP_PLUGIN_DIR . '/' . $plugin_file) )
     439                                $actions[] = '<a href="plugin-editor.php?file=' . $plugin_file . '" title="' . __('Open this file in the Plugin Editor') . '" class="edit">' . __('Edit') . '</a>';
    431440
    432                 if ( ! $is_active && current_user_can('delete_plugins') )
    433                         $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>';
     441                        if ( ! $is_active && current_user_can('delete_plugins') )
     442                                $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>';
    434443
    435                 $actions = apply_filters( 'plugin_action_links', $actions, $plugin_file, $plugin_data, $context );
    436                 $actions = apply_filters( "plugin_action_links_$plugin_file", $actions, $plugin_file, $plugin_data, $context );
     444                        $actions = apply_filters( 'plugin_action_links', $actions, $plugin_file, $plugin_data, $context );
     445                        $actions = apply_filters( "plugin_action_links_$plugin_file", $actions, $plugin_file, $plugin_data, $context );
     446                }
    437447                $action_count = count($actions);
    438448                $class = $is_active ? 'active' : 'inactive';
    439449                echo "
    440450        <tr class='$class'>
    441                 <th scope='row' class='check-column'><input type='checkbox' name='checked[]' value='" . esc_attr($plugin_file) . "' /></th>
     451                <th scope='row' class='check-column'>" . ( 'advanced' != $context ? "<input type='checkbox' name='checked[]' value='" . esc_attr($plugin_file) . "' />" : '' ) . "</th>
    442452                <td class='plugin-title'><strong>{$plugin_data['Name']}</strong></td>
    443453                <td class='desc'><p>{$plugin_data['Description']}</p></td>
    444454        </tr>
     
    546556        $term = isset($_REQUEST['s']) ? urlencode(stripslashes($_REQUEST['s'])) : '';
    547557        $status_links[] = "<li><a href='plugins.php?s=$term' $class>" . sprintf( _n( 'Search Results <span class="count">(%s)</span>', 'Search Results <span class="count">(%s)</span>', $total_search_plugins ), number_format_i18n( $total_search_plugins ) ) . '</a>';
    548558}
     559if ( ! empty($advanced_plugins) ) {
     560        $class = ( 'advanced' == $status ) ? ' class="current"' : '';
     561        $status_links[] = "<li><a href='plugins.php?plugin_status=advanced' $class>" . sprintf( _n( 'Advanced Plugins <span class="count">(%s)</span>', 'Advanced Plugins <span class="count">(%s)</span>', $total_advanced_plugins ), number_format_i18n( $total_advanced_plugins ) ) . '</a>';
     562}
    549563echo implode( " |</li>\n", $status_links ) . '</li>';
    550564unset( $status_links );
    551565?>
    552566</ul>
    553 
     567<div class="clear"></div>
     568<?php
     569if ( 'advanced' == $status ) {
     570        echo '<h3>' . __('Must-Use Plugins') . '</h3>';
     571        echo '<p>' . __('Files in the <code>wp-content/mu-plugins</code> directory are executed automatically.') . '</p>';
     572}
     573if ( $page_links && 'advanced' != $status ) : ?>
    554574<div class="tablenav">
    555 <?php
    556 if ( $page_links )
    557         echo '<div class="tablenav-pages">', $page_links_text, '</div>';
    558 
    559 print_plugin_actions($status);
    560 ?>
     575        <div class="tablenav-pages"><?php $page_links_text; ?></div>
     576<?php print_plugin_actions($status, "action2"); ?>
    561577</div>
    562578<div class="clear"></div>
    563 <?php
     579<?php endif;
     580
    564581        if ( $total_this_page > $plugins_per_page )
    565582                $plugins = array_slice($plugins, $start, $plugins_per_page);
    566583
    567584        print_plugins_table($plugins, $status);
    568 ?>
     585
     586if ( $page_links && 'advanced' != $status ) : ?>
    569587<div class="tablenav">
    570 <?php
    571 if ( $page_links )
    572         echo "<div class='tablenav-pages'>$page_links_text</div>";
    573 
    574 print_plugin_actions($status, "action2");
    575 ?>
     588        <div class="tablenav-pages"><?php $page_links_text; ?></div>
     589<?php print_plugin_actions($status, "action2"); ?>
    576590</div>
     591<?php endif; ?>
    577592</form>
    578593
    579 <?php if ( empty($all_plugins) ) : ?>
     594<?php if ( empty($all_plugins) && empty($advanced_plugins) ) : ?>
    580595<p><?php _e('You do not appear to have any plugins available at this time.') ?></p>
    581596<?php endif; ?>
    582597
  • wp-admin/includes/plugin.php

     Index: wp-admin/includes/plugin.php
     
    251251}
    252252
    253253/**
     254 * Check the mu-plugins directory and retrieve all mu-plugin files with any plugin data.
     255 *
     256 * WordPress only includes mu-plugin files in the base mu-plugins directory (wp-content/mu-plugins).
     257 *
     258 * @since 3.0.0
     259 * @return array Key is the mu-plugin file path and the value is an array of the mu-plugin data.
     260 */
     261function get_mu_plugins() {
     262
     263        $wp_plugins = array ();
     264        // Files in wp-content/mu-plugins directory
     265        $plugin_files = array();
     266
     267        if ( ! is_dir( WPMU_PLUGIN_DIR ) )
     268                return $wp_plugins;
     269        if ( $plugins_dir = @ opendir( WPMU_PLUGIN_DIR ) ) {
     270                while ( ( $file = readdir( $plugins_dir ) ) !== false ) {
     271                        if ( substr( $file, -4 ) == '.php' )
     272                                $plugin_files[] = $file;
     273                }
     274        }
     275
     276        @closedir( $plugins_dir );
     277
     278        if ( !$plugins_dir || empty($plugin_files) )
     279                return $wp_plugins;
     280
     281        foreach ( $plugin_files as $plugin_file ) {
     282                if ( !is_readable( WPMU_PLUGIN_DIR . "/$plugin_file" ) )
     283                        continue;
     284
     285                $plugin_data = get_plugin_data( WPMU_PLUGIN_DIR . "/$plugin_file", false, false ); //Do not apply markup/translate as it'll be cached.
     286
     287                if ( empty ( $plugin_data['Name'] ) )
     288                        $plugin_data['Name'] = $plugin_file;
     289
     290                $wp_plugins[ $plugin_file ] = $plugin_data;
     291        }
     292
     293        if ( isset( $wp_plugins['index.php'] ) && filesize( WPMU_PLUGIN_DIR . '/index.php') <= 30 ) // silence is golden
     294                unset( $wp_plugins['index.php'] );
     295
     296        uasort( $wp_plugins, create_function( '$a, $b', 'return strnatcasecmp( $a["Name"], $b["Name"] );' ));
     297
     298        return $wp_plugins;
     299}
     300
     301/**
    254302 * Check whether the plugin is active by checking the active_plugins list.
    255303 *
    256304 * @since 2.5.0