Remove Shiny Plugin Installs

See #31773, #29820


Built from https://develop.svn.wordpress.org/trunk@31897


git-svn-id: http://core.svn.wordpress.org/trunk@31876 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Aaron Jorbin 2015-03-26 02:30:28 +00:00
parent 60c26865f9
commit 9b23faef07
4 changed files with 9 additions and 157 deletions

View File

@ -2876,57 +2876,6 @@ function wp_ajax_destroy_sessions() {
wp_send_json_success( array( 'message' => $message ) );
}
/**
* AJAX handler for installing a plugin.
*
* @since 4.2.0
*/
function wp_ajax_install_plugin() {
$status = array(
'install' => 'plugin',
'slug' => sanitize_key( $_POST['slug'] ),
);
if ( ! current_user_can( 'install_plugins' ) ) {
$status['error'] = __( 'You do not have sufficient permissions to install plugins on this site.' );
wp_send_json_error( $status );
}
check_ajax_referer( 'updates' );
include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' );
$api = plugins_api( 'plugin_information', array(
'slug' => sanitize_key( $_POST['slug'] ),
'fields' => array( 'sections' => false )
) );
if ( is_wp_error( $api ) ) {
$status['error'] = $api->get_error_message();
wp_send_json_error( $status );
}
$upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() );
$result = $upgrader->install( $api->download_link );
if ( is_wp_error( $result ) ) {
$status['error'] = $result->get_error_message();
wp_send_json_error( $status );
} else if ( is_null( $result ) ) {
$status['errorCode'] = 'unable_to_connect_to_filesystem';
$status['error'] = __( 'Unable to connect to the filesystem. Please confirm your credentials.' );
wp_send_json_error( $status );
}
$plugin_status = install_plugin_install_status( $api );
if ( ! is_multisite() ) {
activate_plugin( $plugin_status['file'] );
}
wp_send_json_success( $status );
}
/**
* AJAX handler for updating a plugin.

View File

@ -51,7 +51,7 @@ window.wp = window.wp || {};
};
/**
* Flag if we're waiting for an install/update to complete.
* Flag if we're waiting for an update to complete.
*
* @since 4.2.0
*
@ -60,7 +60,7 @@ window.wp = window.wp || {};
wp.updates.updateLock = false;
/**
* * Flag if we've done an install or update successfully.
* * Flag if we've done an update successfully.
*
* @since 4.2.0
*
@ -69,7 +69,7 @@ window.wp = window.wp || {};
wp.updates.updateDoneSuccessfully = false;
/**
* If the user tries to install/update a plugin while an install/update is
* If the user tries to update a plugin while an update is
* already happening, it can be placed in this queue to perform later.
*
* @since 4.2.0
@ -255,92 +255,6 @@ window.wp = window.wp || {};
$notificationDialog.find( 'h3' ).after( '<div class="error">' + message + '</div>' );
};
/**
* Send an Ajax request to the server to install a plugin.
*
* @since 4.2.0
*
* @param {string} slug
*/
wp.updates.installPlugin = function( slug ) {
var $message = $( '.plugin-card-' + slug ).find( '.install-now' );
$message.addClass( 'updating-message' );
$message.text( wp.updates.l10n.installing );
wp.a11y.speak( wp.updates.l10n.installingMsg );
if ( wp.updates.updateLock ) {
wp.updates.updateQueue.push( {
type: 'install-plugin',
data: {
slug: slug
}
} );
return;
}
wp.updates.updateLock = true;
var data = {
_ajax_nonce: wp.updates.ajaxNonce,
slug: slug,
username: wp.updates.filesystemCredentials.ftp.username,
password: wp.updates.filesystemCredentials.ftp.password,
hostname: wp.updates.filesystemCredentials.ftp.hostname,
connection_type: wp.updates.filesystemCredentials.ftp.connectionType,
public_key: wp.updates.filesystemCredentials.ssh.publicKey,
private_key: wp.updates.filesystemCredentials.ssh.privateKey
};
wp.ajax.post( 'install-plugin', data )
.done( wp.updates.installSuccess )
.fail( wp.updates.installError );
};
/**
* On plugin install success, update the UI with the result.
*
* @since 4.2.0
*
* @param {object} response
*/
wp.updates.installSuccess = function( response ) {
var $message = $( '.plugin-card-' + response.slug ).find( '.install-now' );
$message.removeClass( 'updating-message' ).addClass( 'updated-message button-disabled' );
$message.text( wp.updates.l10n.installed );
wp.a11y.speak( wp.updates.l10n.installedMsg );
wp.updates.updateDoneSuccessfully = true;
/*
* The lock can be released since the update was successful,
* and any other updates can commence.
*/
wp.updates.updateLock = false;
wp.updates.queueChecker();
};
/**
* On plugin install failure, update the UI appropriately.
*
* @since 4.2.0
*
* @param {object} response
*/
wp.updates.installError = function( response ) {
var $message = $( '.plugin-card-' + response.slug ).find( '.install-now' );
wp.updates.updateDoneSuccessfully = false;
if ( response.errorCode && response.errorCode == 'unable_to_connect_to_filesystem' ) {
wp.updates.credentialError( response, 'install-plugin' );
return;
}
$message.removeClass( 'updating-message' );
$message.text( wp.updates.l10n.installNow );
wp.updates.updateLock = false;
};
/**
* Events that need to happen when there is a credential error
*
@ -361,7 +275,7 @@ window.wp = window.wp || {};
};
/**
* If an install/update job has been placed in the queue, queueChecker pulls it out and runs it.
* If an update job has been placed in the queue, queueChecker pulls it out and runs it.
*
* @since 4.2.0
*/
@ -372,13 +286,13 @@ window.wp = window.wp || {};
var job = wp.updates.updateQueue.shift();
/* This normally wouldn't be a switch, but is there since updates and installs
originally were developed together. Kept as a switch to help with bringing
installs back in and to preserve commit history. */
switch ( job.type ) {
case 'update-plugin':
wp.updates.updatePlugin( job.data.plugin, job.data.slug );
break;
case 'install-plugin':
wp.updates.installPlugin( job.data.slug );
break;
default:
window.console.log( 'Failed to exect queued update job.' );
window.console.log( job );
@ -463,17 +377,6 @@ window.wp = window.wp || {};
wp.updates.updatePlugin( $button.data( 'plugin' ), $button.data( 'slug' ) );
} );
$( '.plugin-card .install-now' ).on( 'click', function( e ) {
e.preventDefault();
if ( wp.updates.shouldRequestFilesystemCredentials && ! wp.updates.updateLock ) {
wp.updates.requestFilesystemCredentials();
}
var $button = $( e.target );
if ( $button.hasClass( 'button-disabled' ) ) {
return;
}
wp.updates.installPlugin( $button.data( 'slug' ) );
} );
} );
$( window ).on( 'message', function( e ) {

File diff suppressed because one or more lines are too long

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.2-beta2-31896';
$wp_version = '4.2-beta2-31897';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.