First scratch at Bulk plugin upgrade from Plugins page. Props nacin for cleanups. See #11542
git-svn-id: http://svn.automattic.com/wordpress/trunk@12832 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
927472de19
commit
01f0afcd21
|
@ -83,6 +83,48 @@ if ( !empty($action) ) {
|
|||
wp_redirect("plugins.php?activate-multi=true&plugin_status=$status&paged=$page");
|
||||
exit;
|
||||
break;
|
||||
case 'update-selected' :
|
||||
if ( ! current_user_can( 'update_plugins' ) )
|
||||
wp_die( __( 'You do not have sufficient permissions to update plugins for this blog.' ) );
|
||||
|
||||
check_admin_referer( 'bulk-manage-plugins' );
|
||||
|
||||
if ( isset( $_GET['plugins'] ) )
|
||||
$plugins = explode( ',', $_GET['plugins'] );
|
||||
elseif ( isset( $_POST['checked'] ) )
|
||||
$plugins = (array) $_POST['checked'];
|
||||
else
|
||||
break;
|
||||
|
||||
if ( empty( $plugins ) )
|
||||
break;
|
||||
|
||||
// We'll be passing all checked plugins as long as at least one is out of date.
|
||||
$_plugins = $plugins;
|
||||
$current = get_site_transient( 'update_plugins' );
|
||||
foreach ( $_plugins as $k => $v ) {
|
||||
if ( ! isset( $current->response[ $v ] ) )
|
||||
unset( $_plugins[ $k ] );
|
||||
}
|
||||
unset( $current );
|
||||
// If all checked plugins are up to date
|
||||
if ( empty( $_plugins ) )
|
||||
break;
|
||||
|
||||
require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
|
||||
require_once( 'admin-header.php' );
|
||||
|
||||
$url = 'plugins.php?action=upgrade-selected&plugins=' . urlencode( join( ',', $plugins ) );
|
||||
$title = __( 'Upgrade Plugins' );
|
||||
$nonce = 'bulk-manage-plugins';
|
||||
$parent_file = 'plugins.php';
|
||||
|
||||
$upgrader = new Plugin_Upgrader( new Plugin_Upgrader_Skin( compact( 'title', 'nonce', 'url' ) ) );
|
||||
$upgrader->bulk_upgrade( $plugins );
|
||||
|
||||
require_once( 'admin-footer.php' );
|
||||
exit;
|
||||
break;
|
||||
case 'error_scrape':
|
||||
if ( ! current_user_can('activate_plugins') )
|
||||
wp_die(__('You do not have sufficient permissions to activate plugins for this blog.'));
|
||||
|
@ -281,6 +323,8 @@ if ( !empty($invalid) )
|
|||
<div id="message" class="updated"><p><?php _e('Plugin <strong>deactivated</strong>.') ?></p></div>
|
||||
<?php elseif (isset($_GET['deactivate-multi'])) : ?>
|
||||
<div id="message" class="updated"><p><?php _e('Selected plugins <strong>deactivated</strong>.'); ?></p></div>
|
||||
<?php elseif ( 'update-selected' == $action ) : ?>
|
||||
<div id="message" class="updated"><p><?php _e('No out of date plugins were selected.'); ?></p></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="wrap">
|
||||
|
@ -500,6 +544,9 @@ function print_plugin_actions($context, $field_name = 'action' ) {
|
|||
<?php if ( 'inactive' != $context && 'recent' != $context ) : ?>
|
||||
<option value="deactivate-selected"><?php _e('Deactivate'); ?></option>
|
||||
<?php endif; ?>
|
||||
<?php if ( current_user_can( 'update_plugins' ) ) : ?>
|
||||
<option value="update-selected"><?php _e( 'Upgrade' ); ?></option>
|
||||
<?php endif; ?>
|
||||
<?php if ( current_user_can('delete_plugins') && ( 'active' != $context ) ) : ?>
|
||||
<option value="delete-selected"><?php _e('Delete'); ?></option>
|
||||
<?php endif; ?>
|
||||
|
|
|
@ -351,21 +351,21 @@ function no_update_actions($actions) {
|
|||
}
|
||||
|
||||
function do_plugin_upgrade() {
|
||||
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
|
||||
|
||||
if ( isset($_GET['plugins']) ) {
|
||||
$plugins = explode(',', $_GET['plugins']);
|
||||
} elseif ( isset($_POST['checked']) ) {
|
||||
if ( isset( $_GET['plugins'] ) ) {
|
||||
$plugins = explode( ',', $_GET['plugins'] );
|
||||
} elseif ( isset( $_POST['checked'] ) ) {
|
||||
$plugins = (array) $_POST['checked'];
|
||||
} else {
|
||||
// Nothing to do.
|
||||
return;
|
||||
}
|
||||
$url = 'update-core.php?action=do-plugin-upgrade&plugins=' . urlencode(join(',', $plugins));
|
||||
$title = __('Upgrade Plugins');
|
||||
|
||||
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
|
||||
$url = 'update-core.php?action=do-plugin-upgrade&plugins=' . urlencode( implode( ',', $plugins ) );
|
||||
$title = __( 'Upgrade Plugins' );
|
||||
$nonce = 'upgrade-core';
|
||||
$upgrader = new Plugin_Upgrader( new Plugin_Upgrader_Skin( compact('title', 'nonce', 'url', 'plugin') ) );
|
||||
$upgrader->bulk_upgrade($plugins);
|
||||
$upgrader = new Plugin_Upgrader( new Plugin_Upgrader_Skin( compact( 'title', 'nonce', 'url' ) ) );
|
||||
$upgrader->bulk_upgrade( $plugins );
|
||||
}
|
||||
|
||||
$action = isset($_GET['action']) ? $_GET['action'] : 'upgrade-core';
|
||||
|
|
Loading…
Reference in New Issue