WordPress.org

Make WordPress Core


Ignore:
Timestamp:
03/18/2015 03:17:59 AM (6 years ago)
Author:
jorbin
Message:

Request FTP and SSH credentials when needed during shiny updates

This is a restoration of [31749] which was reverted in [31755].

It includes a number of enhancements from the original version. Namely:

  • Not doing a credential check in src/wp-includes/script-loader.php
  • Add new function wp_print_request_filesystem_credentials_modal
  • update the version number in the list table when a plugin is updated

UI still needs further work, but this basic version should enable more testing

Props ericlewis, jorbin
See #31528

File:
1 edited

Legend:

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

    r31755 r31811  
    29142914        $status['error'] = $result->get_error_message();
    29152915        wp_send_json_error( $status );
     2916    } else if ( is_null( $result ) ) {
     2917        $status['errorCode'] = 'unable_to_connect_to_filesystem';
     2918        $status['error'] = __( 'Unable to connect to the filesystem. Please confirm your credentials.' );
     2919        wp_send_json_error( $status );
    29162920    }
    29172921
     
    29342938
    29352939    $status = array(
    2936         'update' => 'plugin',
    2937         'plugin' => $plugin,
    2938         'slug'   => sanitize_key( $_POST['slug'] ),
     2940        'update'     => 'plugin',
     2941        'plugin'     => $plugin,
     2942        'slug'       => sanitize_key( $_POST['slug'] ),
     2943        'oldVersion' => '',
     2944        'newVersion' => '',
    29392945    );
     2946    $plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin );
     2947    if ( $plugin_data['Version'] ) {
     2948        $status['oldVersion'] = sprintf( __( 'Version %s' ), $plugin_data['Version'] );
     2949    }
    29402950
    29412951    if ( ! current_user_can( 'update_plugins' ) ) {
     
    29572967
    29582968    if ( is_array( $result ) ) {
    2959         $result = $result[ $plugin ];
    2960     }
    2961 
    2962     if ( is_wp_error( $result ) ) {
     2969        $plugin_update_data = current( $result );
     2970        /*
     2971         * If the `update_plugins` site transient is empty (e.g. when you update
     2972         * two plugins in quick succession before the transient repopulates),
     2973         * this may be the return.
     2974         *
     2975         * Preferably something can be done to ensure `update_plugins` isn't empty.
     2976         * For now, surface some sort of error here.
     2977         */
     2978        if ( $plugin_update_data === true ) {
     2979            wp_send_json_error( $status );
     2980        }
     2981        $plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin );
     2982        if ( $plugin_data['Version'] ) {
     2983            $status['newVersion'] = sprintf( __( 'Version %s' ), $plugin_data['Version'] );
     2984        }
     2985        wp_send_json_success( $status );
     2986    } else if ( is_wp_error( $result ) ) {
    29632987        $status['error'] = $result->get_error_message();
    29642988        wp_send_json_error( $status );
    2965     }
    2966 
    2967     wp_send_json_success( $status );
     2989    } else if ( is_bool( $result ) && ! $result ) {
     2990        $status['errorCode'] = 'unable_to_connect_to_filesystem';
     2991        $status['error'] = __( 'Unable to connect to the filesystem. Please confirm your credentials.' );
     2992        wp_send_json_error( $status );
     2993    }
    29682994}
    29692995
Note: See TracChangeset for help on using the changeset viewer.