<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[31811] trunk/src/wp-admin: Request FTP and SSH credentials when needed during shiny updates</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/31811">31811</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/31811","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>jorbin</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2015-03-18 03:17:59 +0000 (Wed, 18 Mar 2015)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Request FTP and SSH credentials when needed during shiny updates
This is a restoration of <a href="https://core.trac.wordpress.org/changeset/31749">[31749]</a> which was reverted in <a href="https://core.trac.wordpress.org/changeset/31755">[31755]</a>.
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 <a href="https://core.trac.wordpress.org/ticket/31528">#31528</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpadmincssformscss">trunk/src/wp-admin/css/forms.css</a></li>
<li><a href="#trunksrcwpadminincludesajaxactionsphp">trunk/src/wp-admin/includes/ajax-actions.php</a></li>
<li><a href="#trunksrcwpadminincludesfilephp">trunk/src/wp-admin/includes/file.php</a></li>
<li><a href="#trunksrcwpadminjsupdatesjs">trunk/src/wp-admin/js/updates.js</a></li>
<li><a href="#trunksrcwpadminplugininstallphp">trunk/src/wp-admin/plugin-install.php</a></li>
<li><a href="#trunksrcwpadminpluginsphp">trunk/src/wp-admin/plugins.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpadmincssformscss"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/css/forms.css</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/css/forms.css 2015-03-18 02:50:17 UTC (rev 31810)
+++ trunk/src/wp-admin/css/forms.css 2015-03-18 03:17:59 UTC (rev 31811)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -848,6 +848,27 @@
</span><span class="cx" style="display: block; padding: 0 10px"> margin-bottom: 5px;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+/*------------------------------------------------------------------------------
+ Credentials check dialog for Install and Updates
+------------------------------------------------------------------------------*/
+
+.request-filesystem-credentials-dialog {
+ display: none;
+}
+
+.request-filesystem-credentials-dialog .notification-dialog {
+ top: 15%;
+}
+
+.request-filesystem-credentials-dialog-content {
+ margin: 25px;
+}
+
+.request-filesystem-credentials-dialog-content input[type="text"],
+.request-filesystem-credentials-dialog-content input[type="password"] {
+ width: 85%;
+}
+
</ins><span class="cx" style="display: block; padding: 0 10px"> /* =Media Queries
</span><span class="cx" style="display: block; padding: 0 10px"> -------------------------------------------------------------- */
</span><span class="cx" style="display: block; padding: 0 10px">
</span></span></pre></div>
<a id="trunksrcwpadminincludesajaxactionsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/includes/ajax-actions.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/includes/ajax-actions.php 2015-03-18 02:50:17 UTC (rev 31810)
+++ trunk/src/wp-admin/includes/ajax-actions.php 2015-03-18 03:17:59 UTC (rev 31811)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2913,6 +2913,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> if ( is_wp_error( $result ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $status['error'] = $result->get_error_message();
</span><span class="cx" style="display: block; padding: 0 10px"> wp_send_json_error( $status );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ } 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 );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $plugin_status = install_plugin_install_status( $api );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2933,10 +2937,16 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $plugin = urldecode( $_POST['plugin'] );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $status = array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'update' => 'plugin',
- 'plugin' => $plugin,
- 'slug' => sanitize_key( $_POST['slug'] ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'update' => 'plugin',
+ 'plugin' => $plugin,
+ 'slug' => sanitize_key( $_POST['slug'] ),
+ 'oldVersion' => '',
+ 'newVersion' => '',
</ins><span class="cx" style="display: block; padding: 0 10px"> );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin );
+ if ( $plugin_data['Version'] ) {
+ $status['oldVersion'] = sprintf( __( 'Version %s' ), $plugin_data['Version'] );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! current_user_can( 'update_plugins' ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $status['error'] = __( 'You do not have sufficient permissions to update plugins on this site.' );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2956,15 +2966,31 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $result = $upgrader->bulk_upgrade( array( $plugin ) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( is_array( $result ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $result = $result[ $plugin ];
- }
-
- if ( is_wp_error( $result ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $plugin_update_data = current( $result );
+ /*
+ * If the `update_plugins` site transient is empty (e.g. when you update
+ * two plugins in quick succession before the transient repopulates),
+ * this may be the return.
+ *
+ * Preferably something can be done to ensure `update_plugins` isn't empty.
+ * For now, surface some sort of error here.
+ */
+ if ( $plugin_update_data === true ) {
+ wp_send_json_error( $status );
+ }
+ $plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin );
+ if ( $plugin_data['Version'] ) {
+ $status['newVersion'] = sprintf( __( 'Version %s' ), $plugin_data['Version'] );
+ }
+ wp_send_json_success( $status );
+ } else if ( is_wp_error( $result ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $status['error'] = $result->get_error_message();
</span><span class="cx" style="display: block; padding: 0 10px"> wp_send_json_error( $status );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ } else if ( is_bool( $result ) && ! $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 );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
- wp_send_json_success( $status );
</del><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span></span></pre></div>
<a id="trunksrcwpadminincludesfilephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/includes/file.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/includes/file.php 2015-03-18 02:50:17 UTC (rev 31810)
+++ trunk/src/wp-admin/includes/file.php 2015-03-18 03:17:59 UTC (rev 31811)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1192,3 +1192,29 @@
</span><span class="cx" style="display: block; padding: 0 10px"> <?php
</span><span class="cx" style="display: block; padding: 0 10px"> return false;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+/**
+ * Print the credentials modal when needed
+ *
+ * @since 4.2.0
+ */
+function wp_print_request_filesystem_credentials_modal() {
+ $filesystem_method = get_filesystem_method();
+ ob_start();
+ $filesystem_credentials_are_stored = request_filesystem_credentials( self_admin_url() );
+ ob_end_clean();
+ $request_filesystem_credentials = ( $filesystem_method != 'direct' && ! $filesystem_credentials_are_stored );
+ if ( ! $request_filesystem_credentials ) {
+ return;
+ }
+ ?>
+ <div id="request-filesystem-credentials-dialog" class="notification-dialog-wrap request-filesystem-credentials-dialog">
+ <div class="notification-dialog-background"></div>
+ <div class="notification-dialog">
+ <div class="request-filesystem-credentials-dialog-content">
+ <?php request_filesystem_credentials( site_url() ); ?>
+ <div>
+ </div>
+ </div>
+ <?php
+}
</ins></span></pre></div>
<a id="trunksrcwpadminjsupdatesjs"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/js/updates.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/js/updates.js 2015-03-18 02:50:17 UTC (rev 31810)
+++ trunk/src/wp-admin/js/updates.js 2015-03-18 03:17:59 UTC (rev 31811)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -22,6 +22,35 @@
</span><span class="cx" style="display: block; padding: 0 10px"> wp.updates.l10n = window._wpUpdatesSettings.l10n;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Whether filesystem credentials need to be requested from the user.
+ *
+ * @since 4.2.0
+ *
+ * @var bool
+ */
+ wp.updates.shouldRequestFilesystemCredentials = null;
+
+ /**
+ * Filesystem credentials to be packaged along with the request.
+ *
+ * @since 4.2.0
+ *
+ * @var object
+ */
+ wp.updates.filesystemCredentials = {
+ ftp: {
+ host: null,
+ username: null,
+ password: null,
+ connectionType: null
+ },
+ ssh: {
+ publicKey: null,
+ privateKey: null
+ }
+ };
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Flag if we're waiting for an install/update to complete.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 4.2.0
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -31,6 +60,15 @@
</span><span class="cx" style="display: block; padding: 0 10px"> wp.updates.updateLock = false;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * * Flag if we've done an install or update successfully.
+ *
+ * @since 4.2.0
+ *
+ * @var bool
+ */
+ wp.updates.updateDoneSuccessfully = false;
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * If the user tries to install/update a plugin while an install/update is
</span><span class="cx" style="display: block; padding: 0 10px"> * already happening, it can be placed in this queue to perform later.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -123,15 +161,20 @@
</span><span class="cx" style="display: block; padding: 0 10px"> wp.updates.updateLock = true;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> var data = {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- '_ajax_nonce': wp.updates.ajaxNonce,
- 'plugin': plugin,
- 'slug': slug
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ _ajax_nonce: wp.updates.ajaxNonce,
+ plugin: plugin,
+ 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
</ins><span class="cx" style="display: block; padding: 0 10px"> };
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> wp.ajax.post( 'update-plugin', data )
</span><span class="cx" style="display: block; padding: 0 10px"> .done( wp.updates.updateSuccess )
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- .fail( wp.updates.updateError )
- .always( wp.updates.updateAlways );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ .fail( wp.updates.updateError );
</ins><span class="cx" style="display: block; padding: 0 10px"> };
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -147,6 +190,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $message = $( '#' + response.slug ).next().find( '.update-message' );
</span><span class="cx" style="display: block; padding: 0 10px"> $( '#' + response.slug ).addClass( 'updated' ).removeClass( 'update' );
</span><span class="cx" style="display: block; padding: 0 10px"> $( '#' + response.slug + '-update' ).addClass( 'updated' ).removeClass( 'update' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Update the version number in the row.
+ var newText = $( '#' + response.slug ).find('.plugin-version-author-uri').html().replace( response.oldVersion, response.newVersion );
+ $( '#' + response.slug ).find('.plugin-version-author-uri').html( newText );
</ins><span class="cx" style="display: block; padding: 0 10px"> } else if ( 'plugin-install' === pagenow ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $message = $( '.plugin-card-' + response.slug ).find( '.update-now' );
</span><span class="cx" style="display: block; padding: 0 10px"> $message.addClass( 'button-disabled' );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -157,6 +203,15 @@
</span><span class="cx" style="display: block; padding: 0 10px"> wp.a11y.speak( wp.updates.l10n.updatedMsg );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> wp.updates.decrementCount( 'plugin' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ 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();
</ins><span class="cx" style="display: block; padding: 0 10px"> };
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -168,6 +223,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> wp.updates.updateError = function( response ) {
</span><span class="cx" style="display: block; padding: 0 10px"> var $message;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ wp.updates.updateDoneSuccessfully = false;
+ if ( response.errorCode && response.errorCode == 'unable_to_connect_to_filesystem' ) {
+ wp.updates.credentialError( response, 'update-plugin' );
+ return;
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( 'plugins' === pagenow || 'plugins-network' === pagenow ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $message = $( '#' + response.slug ).next().find( '.update-message' );
</span><span class="cx" style="display: block; padding: 0 10px"> } else if ( 'plugin-install' === pagenow ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -176,19 +236,24 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $message.removeClass( 'updating-message' );
</span><span class="cx" style="display: block; padding: 0 10px"> $message.text( wp.updates.l10n.updateFailed );
</span><span class="cx" style="display: block; padding: 0 10px"> wp.a11y.speak( wp.updates.l10n.updateFailed );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> };
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * After an update attempt has completed, check the queue.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Show an error message in the request for credentials form.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param {string} message
</ins><span class="cx" style="display: block; padding: 0 10px"> * @since 4.2.0
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- wp.updates.updateAlways = function() {
- wp.updates.updateLock = false;
- wp.updates.queueChecker();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ wp.updates.showErrorInCredentialsForm = function( message ) {
+ var $notificationDialog = $( '.notification-dialog' );
+
+ // Remove any existing error
+ $notificationDialog.find( '.error' ).remove();
+
+ $notificationDialog.find( 'h3' ).after( '<div class="error">' + message + '</div>' );
</ins><span class="cx" style="display: block; padding: 0 10px"> };
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
</del><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Send an Ajax request to the server to install a plugin.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -216,14 +281,19 @@
</span><span class="cx" style="display: block; padding: 0 10px"> wp.updates.updateLock = true;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> var data = {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- '_ajax_nonce': wp.updates.ajaxNonce,
- 'slug': slug
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ _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
</ins><span class="cx" style="display: block; padding: 0 10px"> };
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> wp.ajax.post( 'install-plugin', data )
</span><span class="cx" style="display: block; padding: 0 10px"> .done( wp.updates.installSuccess )
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- .fail( wp.updates.installError )
- .always( wp.updates.updateAlways );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ .fail( wp.updates.installError );
</ins><span class="cx" style="display: block; padding: 0 10px"> };
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -239,6 +309,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $message.removeClass( 'updating-message' ).addClass( 'updated-message button-disabled' );
</span><span class="cx" style="display: block; padding: 0 10px"> $message.text( wp.updates.l10n.installed );
</span><span class="cx" style="display: block; padding: 0 10px"> wp.a11y.speak( wp.updates.l10n.installedMsg );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 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();
</ins><span class="cx" style="display: block; padding: 0 10px"> };
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -250,11 +328,36 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> wp.updates.installError = function( response ) {
</span><span class="cx" style="display: block; padding: 0 10px"> var $message = $( '.plugin-card-' + response.slug ).find( '.install-now' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ wp.updates.updateDoneSuccessfully = false;
+ if ( response.errorCode && response.errorCode == 'unable_to_connect_to_filesystem' ) {
+ wp.updates.credentialError( response, 'install-plugin' );
+ return;
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $message.removeClass( 'updating-message' );
</span><span class="cx" style="display: block; padding: 0 10px"> $message.text( wp.updates.l10n.installNow );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ wp.updates.updateLock = false;
</ins><span class="cx" style="display: block; padding: 0 10px"> };
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Events that need to happen when there is a credential error
+ *
+ * @since 4.2.0
+ */
+ wp.updates.credentialError = function( response, type ) {
+ wp.updates.updateQueue.push( {
+ 'type': type,
+ 'data': {
+ // Not cool that we're depending on response for this data.
+ // This would feel more whole in a view all tied together.
+ plugin: response.plugin,
+ slug: response.slug
+ }
+ } );
+ wp.updates.showErrorInCredentialsForm( response.error );
+ wp.updates.requestFilesystemCredentials();
+ };
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * If an install/update job has been placed in the queue, queueChecker pulls it out and runs it.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -282,9 +385,55 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> };
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ /**
+ * Request the users filesystem credentials if we don't have them already
+ *
+ * @since 4.2.0
+ */
+ wp.updates.requestFilesystemCredentials = function() {
+ if ( wp.updates.updateDoneSuccessfully === false ) {
+ wp.updates.updateLock = true;
+ $( 'body' ).addClass( 'modal-open' );
+ $( '#request-filesystem-credentials-dialog' ).show();
+ }
+ };
+
</ins><span class="cx" style="display: block; padding: 0 10px"> $( document ).ready( function() {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /*
+ * Check whether a user needs to submit filesystem credentials based on whether
+ * the form was output on the page server-side.
+ *
+ * @see {wp_print_request_filesystem_credentials_modal() in PHP}
+ */
+ wp.updates.shouldRequestFilesystemCredentials = ( $( '#request-filesystem-credentials-dialog' ).length <= 0 ) ? false : true;
+
+ // File system credentials form submit noop-er / handler.
+ $( '#request-filesystem-credentials-dialog form' ).on( 'submit', function() {
+ // Persist the credentials input by the user for the duration of the page load.
+ wp.updates.filesystemCredentials.ftp.hostname = $('#hostname').val();
+ wp.updates.filesystemCredentials.ftp.username = $('#username').val();
+ wp.updates.filesystemCredentials.ftp.password = $('#password').val();
+ wp.updates.filesystemCredentials.ftp.connectionType = $('input[name="connection_type"]:checked').val();
+ wp.updates.filesystemCredentials.ssh.publicKey = $('#public_key').val();
+ wp.updates.filesystemCredentials.ssh.privateKey = $('#private_key').val();
+
+ $( '#request-filesystem-credentials-dialog' ).hide();
+ $( 'body' ).removeClass( 'modal-open' );
+
+ // Unlock and invoke the queue.
+ wp.updates.updateLock = false;
+ wp.updates.queueChecker();
+
+ return false;
+ });
+
+ // Click handler for plugin updates in List Table view.
</ins><span class="cx" style="display: block; padding: 0 10px"> $( '.plugin-update-tr .update-link' ).on( 'click', function( e ) {
</span><span class="cx" style="display: block; padding: 0 10px"> e.preventDefault();
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( wp.updates.shouldRequestFilesystemCredentials && ! wp.updates.updateLock ) {
+ wp.updates.requestFilesystemCredentials();
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> var $row = $( e.target ).parents( '.plugin-update-tr' );
</span><span class="cx" style="display: block; padding: 0 10px"> wp.updates.updatePlugin( $row.data( 'plugin' ), $row.data( 'slug' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> } );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -315,6 +464,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $( '.plugin-card .install-now' ).on( 'click', function( e ) {
</span><span class="cx" style="display: block; padding: 0 10px"> e.preventDefault();
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( wp.updates.shouldRequestFilesystemCredentials && ! wp.updates.updateLock ) {
+ wp.updates.requestFilesystemCredentials();
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> var $button = $( e.target );
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $button.hasClass( 'button-disabled' ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return;
</span></span></pre></div>
<a id="trunksrcwpadminplugininstallphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/plugin-install.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/plugin-install.php 2015-03-18 02:50:17 UTC (rev 31810)
+++ trunk/src/wp-admin/plugin-install.php 2015-03-18 03:17:59 UTC (rev 31811)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -128,7 +128,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> do_action( "install_plugins_$tab", $paged ); ?>
</span><span class="cx" style="display: block; padding: 0 10px"> </div>
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-<?php
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+<?php
+wp_print_request_filesystem_credentials_modal();
+
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * WordPress Administration Template Footer.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span></span></pre></div>
<a id="trunksrcwpadminpluginsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/plugins.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/plugins.php 2015-03-18 02:50:17 UTC (rev 31810)
+++ trunk/src/wp-admin/plugins.php 2015-03-18 03:17:59 UTC (rev 31811)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -476,4 +476,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> </div>
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> <?php
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+wp_print_request_filesystem_credentials_modal();
+
</ins><span class="cx" style="display: block; padding: 0 10px"> include(ABSPATH . 'wp-admin/admin-footer.php');
</span></span></pre>
</div>
</div>
</body>
</html>