Make WordPress Core

Ticket #9838: 9838.3.diff

File 9838.3.diff, 7.7 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');
    5568                        foreach( (array)$_POST['checked'] as $plugin => $time) {
    5669                                if ( isset($recent[ $plugin ]) )
    5770                                        unset($recent[ $plugin ]);
    5871                        }
     72
    5973                        if( $recent != get_option('recently_activated') ) //If array changed, update it.
    6074                                update_option('recently_activated', $recent);
    6175
     
    6478                        break;
    6579                case 'error_scrape':
    6680                        check_admin_referer('plugin-activation-error_' . $plugin);
     81
    6782                        $valid = validate_plugin($plugin);
    6883                        if ( is_wp_error($valid) )
    6984                                wp_die($valid);
     85
    7086                        error_reporting( E_ALL ^ E_NOTICE );
    7187                        @ini_set('display_errors', true); //Ensure that Fatal errors are displayed.
    7288                        include(WP_PLUGIN_DIR . '/' . $plugin);
     
    8298                        break;
    8399                case 'deactivate-selected':
    84100                        check_admin_referer('bulk-manage-plugins');
    85                         deactivate_plugins($_POST['checked']);
     101
     102                        $plugins = (array)$_POST['checked'];
     103                        $plugins = array_filter($plugins, 'is_plugin_active'); //Do not deactivate plugins which are already deactivated.
     104                        if ( empty($plugins) ) {
     105                                wp_redirect("plugins.php?plugin_status=$status&paged=$page");
     106                                exit;
     107                        }
     108
     109                        deactivate_plugins($plugins);
     110
    86111                        $deactivated = array();
    87                         foreach ( (array)$_POST['checked'] as $plugin )
     112                        foreach ( $plugins as $plugin )
    88113                                $deactivated[ $plugin ] = time();
     114
    89115                        update_option('recently_activated', $deactivated + (array)get_option('recently_activated'));
    90116                        wp_redirect("plugins.php?deactivate-multi=true&plugin_status=$status&paged=$page");
    91117                        exit;
     
    96122
    97123                        check_admin_referer('bulk-manage-plugins');
    98124
    99                         $plugins = $_REQUEST['checked']; //$_POST = from the plugin form; $_GET = from the FTP details screen.
     125                        $plugins = (array)$_REQUEST['checked']; //$_POST = from the plugin form; $_GET = from the FTP details screen.
     126                        $plugins = array_filter($plugins, create_function('$plugin', 'return !is_plugin_active($plugin);') ); //Do not allow to delete Activated plugins.
     127                        if ( empty($plugins) ) {
     128                                wp_redirect("plugins.php?plugin_status=$status&paged=$page");
     129                                exit;
     130                        }
     131                               
    100132                        include(ABSPATH . 'wp-admin/update.php');
    101133
    102134                        $parent_file = 'plugins.php';
     
    363395
    364396                if ( $is_active )
    365397                        $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
     398                else
    367399                        $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>';
    368400
    369401                if ( current_user_can('edit_plugins') && is_writable(WP_PLUGIN_DIR . '/' . $plugin_file) )
    370402                        $actions[] = '<a href="plugin-editor.php?file=' . $plugin_file . '" title="' . __('Open this file in the Plugin Editor') . '" class="edit">' . __('Edit') . '</a>';
    371403
    372                 if ( ! empty($plugin_data['PluginURI']) ) {
    373                         $actions[] = '<a href="' . $plugin_data['PluginURI'] . '" title="' . __( 'Visit plugin homepage' ) . '">' . __('View Site') . '</a>';
    374                 }
    375 
    376404                if ( ! $is_active && current_user_can('delete_plugins') )
    377405                        $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>';
    378406
     407                if ( ! empty($plugin_data['PluginURI']) )
     408                        $actions[] = '<a href="' . $plugin_data['PluginURI'] . '" title="' . __( 'Visit plugin homepage' ) . '">' . __('View Site') . '</a>';
     409
    379410                $actions = apply_filters( 'plugin_action_links', $actions, $plugin_file, $plugin_data, $context );
    380411                $actions = apply_filters( "plugin_action_links_$plugin_file", $actions, $plugin_file, $plugin_data, $context );
    381412                $action_count = count($actions);
     
    384415        <tr class='$class'>
    385416                <th scope='row' class='check-column'><input type='checkbox' name='checked[]' value='" . esc_attr($plugin_file) . "' /></th>
    386417                <td class='plugin-title'><strong>{$plugin_data['Name']}</strong>";
    387                 $i = 0;
    388418                echo '<div class="row-actions-visible">';
    389419                foreach ( $actions as $action => $link ) {
    390                         ++$i;
    391                         ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
     420                        $sep = end($actions) == $link ? '' : ' | ';
    392421                        echo "<span class='$action'>$link$sep</span>";
    393422                }
    394                 echo '</div>';
    395                 echo "</td>
    396                 <td class='desc'><p>{$plugin_data['Description']}</p>";
     423                echo "</div>
     424                </td>
     425                <td class='desc'><p>{$plugin_data['Description']}</p><p>";
    397426                if ( !empty($plugin_data['Version']) ) {
    398427                        printf(__('Version: %s'), $plugin_data['Version']);
    399428                        echo ' ';
     
    402431                        $author = $plugin_data['Author'];
    403432                        if ( !empty($plugin_data['AuthorURI']) )
    404433                                $author = '<a href="' . $plugin_data['AuthorURI'] . '" title="' . __( 'Visit author homepage' ) . '">' . $plugin_data['Author'] . '</a>';
    405                         echo ' <cite>' . sprintf( __('By: %s'), $author ) . '</cite>';
     434                        echo '<cite>' . sprintf( __('By: %s'), $author ) . '</cite>';
    406435                }
    407                 echo "</p>";
    408                 echo '</td>
     436                echo '</p>
     437                </td>
    409438        </tr>';
    410439                do_action( 'after_plugin_row', $plugin_file, $plugin_data, $context );
    411440                do_action( "after_plugin_row_$plugin_file", $plugin_file, $plugin_data, $context );
     
    421450 *
    422451 * @param string $context
    423452 */
    424 function print_plugin_actions($context) {
     453function print_plugin_actions($context, $field_name = 'action' ) {
     454       
    425455?>
    426456        <div class="alignleft actions">
    427                 <select name="action">
     457                <select name="<?php echo $field_name ?>">
    428458                        <option value="" selected="selected"><?php _e('Bulk Actions'); ?></option>
    429459        <?php if ( 'active' != $context ) : ?>
    430460                        <option value="activate-selected"><?php _e('Activate'); ?></option>
     
    508538<?php
    509539if ( $page_links )
    510540        echo "<div class='tablenav-pages'>$page_links_text</div>";
     541
     542print_plugin_actions($status, "action2");
    511543?>
    512 <div class="alignleft actions">
    513 <!-- TODO lower bulk actions. -->
    514544</div>
    515 </div>
    516545</form>
    517546
    518547<?php if ( empty($all_plugins) ) : ?>