WordPress.org

Make WordPress Core

Changeset 12832


Ignore:
Timestamp:
01/26/2010 06:53:47 AM (10 years ago)
Author:
dd32
Message:

First scratch at Bulk plugin upgrade from Plugins page. Props nacin for cleanups. See #11542

Location:
trunk/wp-admin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/plugins.php

    r12789 r12832  
    8282
    8383            wp_redirect("plugins.php?activate-multi=true&plugin_status=$status&paged=$page");
     84            exit;
     85            break;
     86        case 'update-selected' :
     87            if ( ! current_user_can( 'update_plugins' ) )
     88                wp_die( __( 'You do not have sufficient permissions to update plugins for this blog.' ) );
     89
     90            check_admin_referer( 'bulk-manage-plugins' );
     91
     92            if ( isset( $_GET['plugins'] ) )
     93                $plugins = explode( ',', $_GET['plugins'] );
     94            elseif ( isset( $_POST['checked'] ) )
     95                $plugins = (array) $_POST['checked'];
     96            else
     97                break;
     98
     99            if ( empty( $plugins ) )
     100                break;
     101
     102            // We'll be passing all checked plugins as long as at least one is out of date.
     103            $_plugins = $plugins;
     104            $current = get_site_transient( 'update_plugins' );
     105            foreach ( $_plugins as $k => $v ) {
     106                if ( ! isset( $current->response[ $v ] ) )
     107                    unset( $_plugins[ $k ] );
     108            }
     109            unset( $current );
     110            // If all checked plugins are up to date
     111            if ( empty( $_plugins ) )
     112                break;
     113
     114            require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
     115            require_once( 'admin-header.php' );
     116           
     117            $url = 'plugins.php?action=upgrade-selected&plugins=' . urlencode( join( ',', $plugins ) );
     118            $title = __( 'Upgrade Plugins' );
     119            $nonce = 'bulk-manage-plugins';
     120            $parent_file = 'plugins.php';
     121
     122            $upgrader = new Plugin_Upgrader( new Plugin_Upgrader_Skin( compact( 'title', 'nonce', 'url' ) ) );
     123            $upgrader->bulk_upgrade( $plugins );
     124
     125            require_once( 'admin-footer.php' );
    84126            exit;
    85127            break;
     
    282324<?php elseif (isset($_GET['deactivate-multi'])) : ?>
    283325    <div id="message" class="updated"><p><?php _e('Selected plugins <strong>deactivated</strong>.'); ?></p></div>
     326<?php elseif ( 'update-selected' == $action ) : ?>
     327    <div id="message" class="updated"><p><?php _e('No out of date plugins were selected.'); ?></p></div>
    284328<?php endif; ?>
    285329
     
    501545            <option value="deactivate-selected"><?php _e('Deactivate'); ?></option>
    502546    <?php endif; ?>
     547    <?php if ( current_user_can( 'update_plugins' ) ) : ?>
     548            <option value="update-selected"><?php _e( 'Upgrade' ); ?></option>
     549    <?php endif; ?>
    503550    <?php if ( current_user_can('delete_plugins') && ( 'active' != $context ) ) : ?>
    504551            <option value="delete-selected"><?php _e('Delete'); ?></option>
  • trunk/wp-admin/update-core.php

    r12546 r12832  
    352352
    353353function do_plugin_upgrade() {
    354     include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
    355 
    356     if ( isset($_GET['plugins']) ) {
    357         $plugins = explode(',', $_GET['plugins']);
    358     } elseif ( isset($_POST['checked']) ) {
     354    if ( isset( $_GET['plugins'] ) ) {
     355        $plugins = explode( ',', $_GET['plugins'] );
     356    } elseif ( isset( $_POST['checked'] ) ) {
    359357        $plugins = (array) $_POST['checked'];
    360358    } else {
     
    362360        return;
    363361    }
    364     $url = 'update-core.php?action=do-plugin-upgrade&amp;plugins=' . urlencode(join(',', $plugins));
    365     $title = __('Upgrade Plugins');
     362
     363    include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
     364    $url = 'update-core.php?action=do-plugin-upgrade&amp;plugins=' . urlencode( implode( ',', $plugins ) );
     365    $title = __( 'Upgrade Plugins' );
    366366    $nonce = 'upgrade-core';
    367     $upgrader = new Plugin_Upgrader( new Plugin_Upgrader_Skin( compact('title', 'nonce', 'url', 'plugin') ) );
    368     $upgrader->bulk_upgrade($plugins);
     367    $upgrader = new Plugin_Upgrader( new Plugin_Upgrader_Skin( compact( 'title', 'nonce', 'url' ) ) );
     368    $upgrader->bulk_upgrade( $plugins );
    369369}
    370370
Note: See TracChangeset for help on using the changeset viewer.