Shiny Updates: If the current user is not allowed to install/update plugins, we should return a JSON error, so it can be used by the JS handlers.
See #29820 git-svn-id: https://develop.svn.wordpress.org/trunk@31335 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
d0379f4fb7
commit
4c49dd62e3
@ -2835,8 +2835,14 @@ function wp_ajax_destroy_sessions() {
|
||||
* @since 4.2.0
|
||||
*/
|
||||
function wp_ajax_install_plugin() {
|
||||
$status = array(
|
||||
'install' => 'plugin',
|
||||
'slug' => sanitize_key( $_POST['slug'] ),
|
||||
);
|
||||
|
||||
if ( ! current_user_can( 'install_plugins' ) ) {
|
||||
wp_die( __('You do not have sufficient permissions to install plugins on this site.') );
|
||||
$status['error'] = __( 'You do not have sufficient permissions to install plugins on this site.' );
|
||||
wp_send_json_error( $status );
|
||||
}
|
||||
|
||||
check_ajax_referer( 'updates' );
|
||||
@ -2844,11 +2850,6 @@ function wp_ajax_install_plugin() {
|
||||
include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
|
||||
include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' );
|
||||
|
||||
$status = array(
|
||||
'install' => 'plugin',
|
||||
'slug' => sanitize_key( $_POST['slug'] ),
|
||||
);
|
||||
|
||||
$api = plugins_api( 'plugin_information', array(
|
||||
'slug' => sanitize_key( $_POST['slug'] ),
|
||||
'fields' => array( 'sections' => false )
|
||||
@ -2879,14 +2880,6 @@ function wp_ajax_install_plugin() {
|
||||
* @since 4.2.0
|
||||
*/
|
||||
function wp_ajax_update_plugin() {
|
||||
if ( ! current_user_can( 'update_plugins' ) ) {
|
||||
wp_die( __('You do not have sufficient permissions to install plugins on this site.') );
|
||||
}
|
||||
|
||||
check_ajax_referer( 'updates' );
|
||||
|
||||
include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
|
||||
|
||||
$plugin = urldecode( $_POST['plugin'] );
|
||||
|
||||
$status = array(
|
||||
@ -2895,6 +2888,15 @@ function wp_ajax_update_plugin() {
|
||||
'slug' => sanitize_key( $_POST['slug'] ),
|
||||
);
|
||||
|
||||
if ( ! current_user_can( 'update_plugins' ) ) {
|
||||
$status['error'] = __( 'You do not have sufficient permissions to update plugins on this site.' );
|
||||
wp_send_json_error( $status );
|
||||
}
|
||||
|
||||
check_ajax_referer( 'updates' );
|
||||
|
||||
include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
|
||||
|
||||
$current = get_site_transient( 'update_plugins' );
|
||||
if ( empty( $current ) ) {
|
||||
wp_update_plugins();
|
||||
|
Loading…
Reference in New Issue
Block a user