Make WordPress Core


Ignore:
Timestamp:
02/19/2010 09:16:14 PM (12 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/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.