Make WordPress Core

Ticket #9838: 9838.5.diff

File 9838.5.diff, 6.3 KB (added by dd32, 17 years ago)
  • wp-admin/plugins.php

     
    1111
    1212if ( isset($_POST['clear-recent-list']) )
    1313        $action = 'clear-recent-list';
    14 elseif ( isset($_REQUEST['action']) )
     14elseif ( !empty($_REQUEST['action']) )
    1515        $action = $_REQUEST['action'];
     16elseif ( !empty($_REQUEST['action2']) )
     17        $action = $_REQUEST['action2'];
    1618else
    1719        $action = false;
    1820
     
    3638        switch ( $action ) {
    3739                case 'activate':
    3840                        check_admin_referer('activate-plugin_' . $plugin);
     41
    3942                        $result = activate_plugin($plugin, 'plugins.php?error=true&plugin=' . $plugin);
    4043                        if ( is_wp_error( $result ) )
    4144                                wp_die($result);
     45
    4246                        $recent = (array)get_option('recently_activated');
    4347                        if ( isset($recent[ $plugin ]) ) {
    4448                                unset($recent[ $plugin ]);
    4549                                update_option('recently_activated', $recent);
    4650                        }
     51
    4752                        wp_redirect("plugins.php?activate=true&plugin_status=$status&paged=$page"); // overrides the ?error=true one above
    4853                        exit;
    4954                        break;
    5055                case 'activate-selected':
    5156                        check_admin_referer('bulk-manage-plugins');
    52                         activate_plugins($_POST['checked'], 'plugins.php?error=true');
    5357
     58                        $plugins = $_POST['checked'];
     59                        $plugins = array_filter($plugins, create_function('$plugin', 'return !is_plugin_active($plugin);') ); //Only activate plugins which are not already active.
     60                        if ( empty($plugins) ) {
     61                                wp_redirect("plugins.php?plugin_status=$status&paged=$page");
     62                                exit;
     63                        }
     64
     65                        activate_plugins($plugins, 'plugins.php?error=true');
     66
    5467                        $recent = (array)get_option('recently_activated');
    55                         foreach( (array)$_POST['checked'] as $plugin => $time) {
     68                        foreach ( $plugins as $plugin => $time)
    5669                                if ( isset($recent[ $plugin ]) )
    5770                                        unset($recent[ $plugin ]);
    58                         }
    59                         if( $recent != get_option('recently_activated') ) //If array changed, update it.
    60                                 update_option('recently_activated', $recent);
    6171
     72                        update_option('recently_activated', $recent);
     73
    6274                        wp_redirect("plugins.php?activate-multi=true&plugin_status=$status&paged=$page");
    6375                        exit;
    6476                        break;
    6577                case 'error_scrape':
    6678                        check_admin_referer('plugin-activation-error_' . $plugin);
     79
    6780                        $valid = validate_plugin($plugin);
    6881                        if ( is_wp_error($valid) )
    6982                                wp_die($valid);
     83
    7084                        error_reporting( E_ALL ^ E_NOTICE );
    7185                        @ini_set('display_errors', true); //Ensure that Fatal errors are displayed.
    7286                        include(WP_PLUGIN_DIR . '/' . $plugin);
     
    8296                        break;
    8397                case 'deactivate-selected':
    8498                        check_admin_referer('bulk-manage-plugins');
    85                         deactivate_plugins($_POST['checked']);
     99
     100                        $plugins = (array)$_POST['checked'];
     101                        $plugins = array_filter($plugins, 'is_plugin_active'); //Do not deactivate plugins which are already deactivated.
     102                        if ( empty($plugins) ) {
     103                                wp_redirect("plugins.php?plugin_status=$status&paged=$page");
     104                                exit;
     105                        }
     106
     107                        deactivate_plugins($plugins);
     108
    86109                        $deactivated = array();
    87                         foreach ( (array)$_POST['checked'] as $plugin )
     110                        foreach ( $plugins as $plugin )
    88111                                $deactivated[ $plugin ] = time();
     112
    89113                        update_option('recently_activated', $deactivated + (array)get_option('recently_activated'));
    90114                        wp_redirect("plugins.php?deactivate-multi=true&plugin_status=$status&paged=$page");
    91115                        exit;
     
    96120
    97121                        check_admin_referer('bulk-manage-plugins');
    98122
    99                         $plugins = $_REQUEST['checked']; //$_POST = from the plugin form; $_GET = from the FTP details screen.
     123                        $plugins = (array)$_REQUEST['checked']; //$_POST = from the plugin form; $_GET = from the FTP details screen.
     124                        $plugins = array_filter($plugins, create_function('$plugin', 'return !is_plugin_active($plugin);') ); //Do not allow to delete Activated plugins.
     125                        if ( empty($plugins) ) {
     126                                wp_redirect("plugins.php?plugin_status=$status&paged=$page");
     127                                exit;
     128                        }
     129                               
    100130                        include(ABSPATH . 'wp-admin/update.php');
    101131
    102132                        $parent_file = 'plugins.php';
     
    363393
    364394                if ( $is_active )
    365395                        $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>';
    366                 else //Inactive or Recently deactivated
     396                else
    367397                        $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>';
    368398
    369399                if ( current_user_can('edit_plugins') && is_writable(WP_PLUGIN_DIR . '/' . $plugin_file) )
     
    385415        <tr class='$class second'>
    386416                <td></td>
    387417                <td class='plugin-title'>";
    388                 $i = 0;
    389418                echo '<div class="row-actions-visible">';
    390419                foreach ( $actions as $action => $link ) {
    391                         ++$i;
    392                         ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
     420                        $sep = end($actions) == $link ? '' : ' | ';
    393421                        echo "<span class='$action'>$link$sep</span>";
    394422                }
    395423                echo "</div></td>
     
    403431                                $author = '<a href="' . $plugin_data['AuthorURI'] . '" title="' . __( 'Visit author homepage' ) . '">' . $plugin_data['Author'] . '</a>';
    404432                        $plugin_meta[] = sprintf( __('By %s'), $author );
    405433                }
    406                 if ( ! empty($plugin_data['PluginURI']) ) {
     434                if ( ! empty($plugin_data['PluginURI']) )
    407435                        $plugin_meta[] = '<a href="' . $plugin_data['PluginURI'] . '" title="' . __( 'Visit plugin site' ) . '">' . __('Visit plugin site') . '</a>';
    408                 }
     436
    409437                $plugin_meta = apply_filters('plugin_row_meta', $plugin_meta, $plugin_file, $plugin_data, $context);
    410438                echo implode(' | ', $plugin_meta);
    411439                echo "</p></td>
     
    425453 *
    426454 * @param string $context
    427455 */
    428 function print_plugin_actions($context) {
     456function print_plugin_actions($context, $field_name = 'action' ) {
     457       
    429458?>
    430459        <div class="alignleft actions">
    431                 <select name="action">
     460                <select name="<?php echo $field_name ?>">
    432461                        <option value="" selected="selected"><?php _e('Bulk Actions'); ?></option>
    433462        <?php if ( 'active' != $context ) : ?>
    434463                        <option value="activate-selected"><?php _e('Activate'); ?></option>
     
    512541<?php
    513542if ( $page_links )
    514543        echo "<div class='tablenav-pages'>$page_links_text</div>";
     544
     545print_plugin_actions($status, "action2");
    515546?>
    516 <div class="alignleft actions">
    517 <!-- TODO lower bulk actions. -->
    518547</div>
    519 </div>
    520548</form>
    521549
    522550<?php if ( empty($all_plugins) ) : ?>