Ticket #31528: 31528.4.diff
File 31528.4.diff, 11.5 KB (added by , 10 years ago) |
---|
-
src/wp-admin/css/forms.css
850 850 margin-bottom: 5px; 851 851 } 852 852 853 /*------------------------------------------------------------------------------ 854 Credentials check dialog for Install and Updates 855 ------------------------------------------------------------------------------*/ 856 857 .request-filesystem-credentials-dialog { 858 display: none; 859 } 860 861 .request-filesystem-credentials-dialog .notification-dialog{ 862 top: 15% 863 } 864 865 .request-filesystem-credentials-dialog-content{ 866 margin: 25px; 867 } 868 853 869 /* =Media Queries 854 870 -------------------------------------------------------------- */ 855 871 -
src/wp-admin/includes/ajax-actions.php
2913 2913 if ( is_wp_error( $result ) ) { 2914 2914 $status['error'] = $result->get_error_message(); 2915 2915 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 ); 2916 2920 } 2917 2921 2918 2922 $plugin_status = install_plugin_install_status( $api ); … … 2954 2958 2955 2959 $upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() ); 2956 2960 $result = $upgrader->bulk_upgrade( array( $plugin ) ); 2957 2958 2961 if ( is_array( $result ) ) { 2959 $result = $result[ $plugin ]; 2960 } 2961 2962 if ( is_wp_error( $result ) ) { 2962 wp_send_json_success( $status ); 2963 } else if ( is_wp_error( $result ) ) { 2963 2964 $status['error'] = $result->get_error_message(); 2964 2965 wp_send_json_error( $status ); 2966 } else if ( is_bool( $result ) && ! $result ) { 2967 $status['errorCode'] = __( 'unable_to_connect_to_filesystem' ); 2968 $status['error'] = __( 'Unable to connect to the filesystem. Please confirm your credentials.' ); 2969 wp_send_json_error( $status ); 2965 2970 } 2966 2967 wp_send_json_success( $status );2968 2971 } 2969 2972 2970 2973 /** -
src/wp-admin/js/updates.js
22 22 wp.updates.l10n = window._wpUpdatesSettings.l10n; 23 23 24 24 /** 25 * Whether filesystem credentials need to be requested from the user. 26 * 27 * @since 4.2.0 28 * 29 * @var bool 30 */ 31 wp.updates.shouldRequestFilesystemCredentials = window._wpUpdatesSettings.requestFilesystemCredentials; 32 33 /** 34 * Filesystem credentials to be packaged along with the request. 35 * 36 * @since 4.2.0 37 * 38 * @var object 39 */ 40 wp.updates.filesystemCredentials = { 41 ftp: { 42 host: null, 43 username: null, 44 password: null, 45 connectionType: null 46 }, 47 ssh: { 48 publicKey: null, 49 privateKey: null 50 } 51 }; 52 53 /** 25 54 * Flag if we're waiting for an install/update to complete. 26 55 * 27 56 * @since 4.2.0 … … 31 60 wp.updates.updateLock = false; 32 61 33 62 /** 63 * Flag if we've done an install or update successfully. 64 * 65 * @since 4.2.0 66 * 67 * @var bool 68 */ 69 wp.updates.updateDoneSuccessfully = false; 70 71 /** 34 72 * If the user tries to install/update a plugin while an install/update is 35 73 * already happening, it can be placed in this queue to perform later. 36 74 * … … 124 162 125 163 var data = { 126 164 '_ajax_nonce': wp.updates.ajaxNonce, 127 'plugin': plugin, 128 'slug': slug 165 'plugin': plugin, 166 'slug': slug, 167 username: wp.updates.filesystemCredentials.ftp.username, 168 password: wp.updates.filesystemCredentials.ftp.password, 169 hostname: wp.updates.filesystemCredentials.ftp.hostname, 170 connection_type: wp.updates.filesystemCredentials.ftp.connectionType, 171 public_key: wp.updates.filesystemCredentials.ssh.publicKey, 172 private_key: wp.updates.filesystemCredentials.ssh.privateKey 129 173 }; 130 174 131 175 wp.ajax.post( 'update-plugin', data ) … … 157 201 wp.a11y.speak( wp.updates.l10n.updatedMsg ); 158 202 159 203 wp.updates.decrementCount( 'plugin' ); 204 205 wp.updates.updateDoneSuccessfully = true; 160 206 }; 161 207 162 208 /** … … 168 214 */ 169 215 wp.updates.updateError = function( response ) { 170 216 var $message; 217 wp.updates.updateDoneSuccessfully = false; 218 if ( response.errorCode && response.errorCode == 'unable_to_connect_to_filesystem' ) { 219 wp.updates.credentialError( response, 'update-plugin' ); 220 return; 221 } 171 222 if ( 'plugins' === pagenow || 'plugins-network' === pagenow ) { 172 223 $message = $( '#' + response.slug ).next().find( '.update-message' ); 173 224 } else if ( 'plugin-install' === pagenow ) { … … 179 230 }; 180 231 181 232 /** 233 * Show an 234 * 235 * @param {string} message 236 * @since 4.2.0 237 */ 238 wp.updates.showErrorInCredentialsForm = function( message ) { 239 var $notificationDialog = $( '.notification-dialog' ); 240 241 // Remove any existing error 242 $notificationDialog.find( '.error' ).remove(); 243 244 $notificationDialog.find( 'h3' ).after( '<div class="error">' + message + '</div>' ); 245 }; 246 247 /** 182 248 * After an update attempt has completed, check the queue. 183 249 * 184 250 * @since 4.2.0 … … 216 282 wp.updates.updateLock = true; 217 283 218 284 var data = { 219 '_ajax_nonce': wp.updates.ajaxNonce, 220 'slug': slug 285 '_ajax_nonce': wp.updates.ajaxNonce, 286 'slug': slug, 287 'username': wp.updates.filesystemCredentials.ftp.username, 288 'password': wp.updates.filesystemCredentials.ftp.password, 289 'hostname': wp.updates.filesystemCredentials.ftp.hostname, 290 'connection_type': wp.updates.filesystemCredentials.ftp.connectionType, 291 'public_key': wp.updates.filesystemCredentials.ssh.publicKey, 292 'private_key': wp.updates.filesystemCredentials.ssh.privateKey 221 293 }; 222 294 223 295 wp.ajax.post( 'install-plugin', data ) … … 239 311 $message.removeClass( 'updating-message' ).addClass( 'updated-message button-disabled' ); 240 312 $message.text( wp.updates.l10n.installed ); 241 313 wp.a11y.speak( wp.updates.l10n.installedMsg ); 314 wp.updates.updateDoneSuccessfully = true; 242 315 }; 243 316 244 317 /** … … 250 323 */ 251 324 wp.updates.installError = function( response ) { 252 325 var $message = $( '.plugin-card-' + response.slug ).find( '.install-now' ); 326 wp.updates.updateDoneSuccessfully = false; 327 if ( response.errorCode && response.errorCode == 'unable_to_connect_to_filesystem' ) { 328 wp.updates.credentialError( response, 'update-plugin' ); 329 return; 330 } 253 331 254 332 $message.removeClass( 'updating-message' ); 255 333 $message.text( wp.updates.l10n.installNow ); 256 334 }; 257 335 336 wp.updates.credentialError = function( response, type ) { 337 wp.updates.updateQueue.push( { 338 'type': type, 339 'data': { 340 // Not cool that we're depending on response for this data. 341 // This would feel more whole in a view all tied together. 342 plugin: response.plugin, 343 slug: response.slug 344 } 345 } ); 346 wp.updates.showErrorInCredentialsForm( response.error ); 347 wp.updates.requestFilesystemCredentials(); 348 }; 258 349 350 259 351 /** 260 352 * If an install/update job has been placed in the queue, queueChecker pulls it out and runs it. 261 353 * … … 281 373 break; 282 374 } 283 375 }; 376 /** 377 * Request the users filesystem credentials if we don't have them already 378 * 379 * @since 4.2.0 380 */ 381 wp.updates.requestFilesystemCredentials = function() { 382 if ( wp.updates.updateDoneSuccessfully === false ) { 383 wp.updates.updateLock = true; 384 $('#request-filesystem-credentials-dialog').show(); 385 } 386 }; 284 387 388 // Bind various click handlers. 285 389 $( document ).ready( function() { 390 // File system credentials form submit noop-er / handler. 391 $('#request-filesystem-credentials-dialog form').on( 'submit', function() { 392 // Persist the credentials input by the user for the duration of the page load. 393 wp.updates.filesystemCredentials.ftp.hostname = $('#hostname').val(); 394 wp.updates.filesystemCredentials.ftp.username = $('#username').val(); 395 wp.updates.filesystemCredentials.ftp.password = $('#password').val(); 396 wp.updates.filesystemCredentials.ftp.connectionType = $('input[name="connection_type"]:checked').val(); 397 wp.updates.filesystemCredentials.ssh.publicKey = $('#public_key').val(); 398 wp.updates.filesystemCredentials.ssh.privateKey = $('#private_key').val(); 399 400 $('#request-filesystem-credentials-dialog').hide(); 401 402 // Unlock and invoke the queue. 403 wp.updates.updateLock = false; 404 wp.updates.queueChecker(); 405 406 return false; 407 }); 408 409 // Click handler for plugin updates in List Table view. 286 410 $( '.plugin-update-tr .update-link' ).on( 'click', function( e ) { 287 411 e.preventDefault(); 412 if ( wp.updates.shouldRequestFilesystemCredentials ) { 413 wp.updates.requestFilesystemCredentials(); 414 } 288 415 var $row = $( e.target ).parents( '.plugin-update-tr' ); 289 416 wp.updates.updatePlugin( $row.data( 'plugin' ), $row.data( 'slug' ) ); 290 417 } ); … … 315 442 316 443 $( '.plugin-card .install-now' ).on( 'click', function( e ) { 317 444 e.preventDefault(); 445 if ( wp.updates.shouldRequestFilesystemCredentials ) { 446 wp.updates.requestFilesystemCredentials(); 447 } 448 318 449 var $button = $( e.target ); 319 450 if ( $button.hasClass( 'button-disabled' ) ) { 320 451 return; -
src/wp-admin/plugin-install.php
128 128 */ 129 129 do_action( "install_plugins_$tab", $paged ); ?> 130 130 </div> 131 132 <div id="request-filesystem-credentials-dialog" class="notification-dialog-wrap request-filesystem-credentials-dialog"> 133 <div class="notification-dialog-background"></div> 134 <div class="notification-dialog"> 135 <div class="request-filesystem-credentials-dialog-content"> 136 <?php request_filesystem_credentials( site_url() ); ?> 137 <div> 138 </div> 139 </div> 140 131 141 <?php 132 142 /** 133 143 * WordPress Administration Template Footer. -
src/wp-admin/plugins.php
475 475 476 476 </div> 477 477 478 <div id="request-filesystem-credentials-dialog" class="notification-dialog-wrap request-filesystem-credentials-dialog"> 479 <div class="notification-dialog-background"></div> 480 <div class="notification-dialog"> 481 <div class="request-filesystem-credentials-dialog-content"> 482 <?php request_filesystem_credentials( site_url() ); ?> 483 <div> 484 </div> 485 </div> 478 486 <?php 479 487 include(ABSPATH . 'wp-admin/admin-footer.php'); -
src/wp-includes/script-loader.php
542 542 ) ); 543 543 544 544 $scripts->add( 'updates', "/wp-admin/js/updates$suffix.js", array( 'jquery', 'wp-util', 'wp-a11y' ) ); 545 546 /* 547 * Determine whether the user will need to enter filesystem credentials 548 * on the front-end. 549 */ 550 $filesystem_method = get_filesystem_method(); 551 ob_start(); 552 $filesystem_credentials_are_stored = request_filesystem_credentials( self_admin_url() ); 553 ob_end_clean(); 554 $request_filesystem_credentials = ( $filesystem_method != 'direct' && ! $filesystem_credentials_are_stored ) ? 1 : 0; 555 545 556 did_action( 'init' ) && $scripts->localize( 'updates', '_wpUpdatesSettings', array( 546 557 'ajax_nonce' => wp_create_nonce( 'updates' ), 558 'requestFilesystemCredentials' => $request_filesystem_credentials, 547 559 'l10n' => array( 548 560 'updating' => __( 'Updating...' ), 549 561 'updated' => __( 'Updated!' ),