WordPress.org

Make WordPress Core

Changeset 31335


Ignore:
Timestamp:
02/05/2015 06:15:59 AM (7 years ago)
Author:
pento
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/ajax-actions.php

    r31334 r31335  
    28362836 */
    28372837function wp_ajax_install_plugin() {
    2838     if ( ! current_user_can( 'install_plugins' ) ) {
    2839         wp_die( __('You do not have sufficient permissions to install plugins on this site.') );
    2840     }
    2841 
    2842     check_ajax_referer( 'updates' );
    2843 
    2844     include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
    2845     include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' );
    2846 
    28472838    $status = array(
    28482839        'install' => 'plugin',
     
    28502841    );
    28512842
     2843    if ( ! current_user_can( 'install_plugins' ) ) {
     2844        $status['error'] = __( 'You do not have sufficient permissions to install plugins on this site.' );
     2845        wp_send_json_error( $status );
     2846    }
     2847
     2848    check_ajax_referer( 'updates' );
     2849
     2850    include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
     2851    include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' );
     2852
    28522853    $api = plugins_api( 'plugin_information', array(
    28532854        'slug'   => sanitize_key( $_POST['slug'] ),
     
    28802881 */
    28812882function wp_ajax_update_plugin() {
    2882     if ( ! current_user_can( 'update_plugins' ) ) {
    2883         wp_die( __('You do not have sufficient permissions to install plugins on this site.') );
    2884     }
    2885 
    2886     check_ajax_referer( 'updates' );
    2887 
    2888     include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
    2889 
    28902883    $plugin = urldecode( $_POST['plugin'] );
    28912884
     
    28962889    );
    28972890
     2891    if ( ! current_user_can( 'update_plugins' ) ) {
     2892        $status['error'] = __( 'You do not have sufficient permissions to update plugins on this site.' );
     2893        wp_send_json_error( $status );
     2894    }
     2895
     2896    check_ajax_referer( 'updates' );
     2897
     2898    include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
     2899
    28982900    $current = get_site_transient( 'update_plugins' );
    28992901    if ( empty( $current ) ) {
Note: See TracChangeset for help on using the changeset viewer.