From a836a32fb4237cf032acc9d8deeba0eb1c855d2f Mon Sep 17 00:00:00 2001 From: Aaron Jorbin Date: Thu, 19 Mar 2015 05:26:28 +0000 Subject: [PATCH] Ensure that we target the correct plugin row for update updates The DOM traversal of the plugins list table was less than ideal. By switching to data attributes, we can better target the DOM elements we want to update. Props ericlewis Fixes #31621 Built from https://develop.svn.wordpress.org/trunk@31831 git-svn-id: http://core.svn.wordpress.org/trunk@31813 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../includes/class-wp-plugins-list-table.php | 6 ++++- wp-admin/js/updates.js | 25 ++++++++++--------- wp-admin/js/updates.min.js | 2 +- wp-includes/version.php | 2 +- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/wp-admin/includes/class-wp-plugins-list-table.php b/wp-admin/includes/class-wp-plugins-list-table.php index 1ade73caac..5d0c78fd8e 100644 --- a/wp-admin/includes/class-wp-plugins-list-table.php +++ b/wp-admin/includes/class-wp-plugins-list-table.php @@ -515,7 +515,11 @@ class WP_Plugins_List_Table extends WP_List_Table { if ( ! empty( $totals['upgrade'] ) && ! empty( $plugin_data['update'] ) ) $class .= ' update'; - echo ""; + printf( "", + $id, + $class, + $plugin_data['slug'] + ); list( $columns, $hidden ) = $this->get_column_info(); diff --git a/wp-admin/js/updates.js b/wp-admin/js/updates.js index d9d7afa53b..77f0399486 100644 --- a/wp-admin/js/updates.js +++ b/wp-admin/js/updates.js @@ -138,7 +138,7 @@ window.wp = window.wp || {}; wp.updates.updatePlugin = function( plugin, slug ) { var $message; if ( 'plugins' === pagenow || 'plugins-network' === pagenow ) { - $message = $( '#' + slug ).next().find( '.update-message' ); + $message = $( '[data-slug="' + slug + '"]' ).next().find( '.update-message' ); } else if ( 'plugin-install' === pagenow ) { $message = $( '.plugin-card-' + slug ).find( '.update-now' ); } @@ -185,21 +185,22 @@ window.wp = window.wp || {}; * @param {object} response */ wp.updates.updateSuccess = function( response ) { - var $message; + var $updateMessage; if ( 'plugins' === pagenow || 'plugins-network' === pagenow ) { - $message = $( '#' + response.slug ).next().find( '.update-message' ); - $( '#' + response.slug ).addClass( 'updated' ).removeClass( 'update' ); - $( '#' + response.slug + '-update' ).addClass( 'updated' ).removeClass( 'update' ); + var $pluginRow = $( '[data-slug="' + response.slug + '"]' ).first(); + $updateMessage = $pluginRow.next().find( '.update-message' ); + $pluginRow.addClass( 'updated' ).removeClass( 'update' ); + // 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 ); + var newText = $pluginRow.find('.plugin-version-author-uri').html().replace( response.oldVersion, response.newVersion ); + $pluginRow.find('.plugin-version-author-uri').html( newText ); } else if ( 'plugin-install' === pagenow ) { - $message = $( '.plugin-card-' + response.slug ).find( '.update-now' ); - $message.addClass( 'button-disabled' ); + $updateMessage = $( '.plugin-card-' + response.slug ).find( '.update-now' ); + $updateMessage.addClass( 'button-disabled' ); } - $message.removeClass( 'updating-message' ).addClass( 'updated-message' ); - $message.text( wp.updates.l10n.updated ); + $updateMessage.removeClass( 'updating-message' ).addClass( 'updated-message' ); + $updateMessage.text( wp.updates.l10n.updated ); wp.a11y.speak( wp.updates.l10n.updatedMsg ); wp.updates.decrementCount( 'plugin' ); @@ -229,7 +230,7 @@ window.wp = window.wp || {}; return; } if ( 'plugins' === pagenow || 'plugins-network' === pagenow ) { - $message = $( '#' + response.slug ).next().find( '.update-message' ); + $message = $( '[data-slug="' + response.slug + '"]' ).next().find( '.update-message' ); } else if ( 'plugin-install' === pagenow ) { $message = $( '.plugin-card-' + response.slug ).find( '.update-now' ); } diff --git a/wp-admin/js/updates.min.js b/wp-admin/js/updates.min.js index 6c55f40836..e39fca120f 100644 --- a/wp-admin/js/updates.min.js +++ b/wp-admin/js/updates.min.js @@ -1 +1 @@ -window.wp=window.wp||{},function(a,b,c){b.updates={},b.updates.ajaxNonce=window._wpUpdatesSettings.ajax_nonce,b.updates.l10n=window._wpUpdatesSettings.l10n,b.updates.shouldRequestFilesystemCredentials=null,b.updates.filesystemCredentials={ftp:{host:null,username:null,password:null,connectionType:null},ssh:{publicKey:null,privateKey:null}},b.updates.updateLock=!1,b.updates.updateDoneSuccessfully=!1,b.updates.updateQueue=[],b.updates.decrementCount=function(b){var c,d,e=a("#wp-admin-bar-updates .ab-label"),f=a('a[href="update-core.php"] .update-plugins'),g=a("#menu-plugins");if(c=e.text(),c=parseInt(c,10)-1,!(0>c||isNaN(c))&&(a("#wp-admin-bar-updates .ab-item").removeAttr("title"),e.text(c),f.each(function(a,b){b.className=b.className.replace(/count-\d+/,"count-"+c)}),f.removeAttr("title"),f.find(".update-count").text(c),"plugin"===b)){if(d=g.find(".plugin-count").eq(0).text(),d=parseInt(d,10)-1,0>d||isNaN(d))return;g.find(".plugin-count").text(d),g.find(".update-plugins").each(function(a,b){b.className=b.className.replace(/count-\d+/,"count-"+d)}),d>0?a(".subsubsub .upgrade .count").text("("+d+")"):a(".subsubsub .upgrade").remove()}},b.updates.updatePlugin=function(d,e){var f;if("plugins"===c||"plugins-network"===c?f=a("#"+e).next().find(".update-message"):"plugin-install"===c&&(f=a(".plugin-card-"+e).find(".update-now")),f.addClass("updating-message"),f.text(b.updates.l10n.updating),b.a11y.speak(b.updates.l10n.updatingMsg),b.updates.updateLock)return void b.updates.updateQueue.push({type:"update-plugin",data:{plugin:d,slug:e}});b.updates.updateLock=!0;var g={_ajax_nonce:b.updates.ajaxNonce,plugin:d,slug:e,username:b.updates.filesystemCredentials.ftp.username,password:b.updates.filesystemCredentials.ftp.password,hostname:b.updates.filesystemCredentials.ftp.hostname,connection_type:b.updates.filesystemCredentials.ftp.connectionType,public_key:b.updates.filesystemCredentials.ssh.publicKey,private_key:b.updates.filesystemCredentials.ssh.privateKey};b.ajax.post("update-plugin",g).done(b.updates.updateSuccess).fail(b.updates.updateError)},b.updates.updateSuccess=function(d){var e;if("plugins"===c||"plugins-network"===c){e=a("#"+d.slug).next().find(".update-message"),a("#"+d.slug).addClass("updated").removeClass("update"),a("#"+d.slug+"-update").addClass("updated").removeClass("update");var f=a("#"+d.slug).find(".plugin-version-author-uri").html().replace(d.oldVersion,d.newVersion);a("#"+d.slug).find(".plugin-version-author-uri").html(f)}else"plugin-install"===c&&(e=a(".plugin-card-"+d.slug).find(".update-now"),e.addClass("button-disabled"));e.removeClass("updating-message").addClass("updated-message"),e.text(b.updates.l10n.updated),b.a11y.speak(b.updates.l10n.updatedMsg),b.updates.decrementCount("plugin"),b.updates.updateDoneSuccessfully=!0,b.updates.updateLock=!1,b.updates.queueChecker()},b.updates.updateError=function(d){var e;return b.updates.updateDoneSuccessfully=!1,d.errorCode&&"unable_to_connect_to_filesystem"==d.errorCode?void b.updates.credentialError(d,"update-plugin"):("plugins"===c||"plugins-network"===c?e=a("#"+d.slug).next().find(".update-message"):"plugin-install"===c&&(e=a(".plugin-card-"+d.slug).find(".update-now")),e.removeClass("updating-message"),e.text(b.updates.l10n.updateFailed),void b.a11y.speak(b.updates.l10n.updateFailed))},b.updates.showErrorInCredentialsForm=function(b){var c=a(".notification-dialog");c.find(".error").remove(),c.find("h3").after('
'+b+"
")},b.updates.installPlugin=function(c){var d=a(".plugin-card-"+c).find(".install-now");if(d.addClass("updating-message"),d.text(b.updates.l10n.installing),b.a11y.speak(b.updates.l10n.installingMsg),b.updates.updateLock)return void b.updates.updateQueue.push({type:"install-plugin",data:{slug:c}});b.updates.updateLock=!0;var e={_ajax_nonce:b.updates.ajaxNonce,slug:c,username:b.updates.filesystemCredentials.ftp.username,password:b.updates.filesystemCredentials.ftp.password,hostname:b.updates.filesystemCredentials.ftp.hostname,connection_type:b.updates.filesystemCredentials.ftp.connectionType,public_key:b.updates.filesystemCredentials.ssh.publicKey,private_key:b.updates.filesystemCredentials.ssh.privateKey};b.ajax.post("install-plugin",e).done(b.updates.installSuccess).fail(b.updates.installError)},b.updates.installSuccess=function(c){var d=a(".plugin-card-"+c.slug).find(".install-now");d.removeClass("updating-message").addClass("updated-message button-disabled"),d.text(b.updates.l10n.installed),b.a11y.speak(b.updates.l10n.installedMsg),b.updates.updateDoneSuccessfully=!0,b.updates.updateLock=!1,b.updates.queueChecker()},b.updates.installError=function(c){var d=a(".plugin-card-"+c.slug).find(".install-now");return b.updates.updateDoneSuccessfully=!1,c.errorCode&&"unable_to_connect_to_filesystem"==c.errorCode?void b.updates.credentialError(c,"install-plugin"):(d.removeClass("updating-message"),d.text(b.updates.l10n.installNow),void(b.updates.updateLock=!1))},b.updates.credentialError=function(a,c){b.updates.updateQueue.push({type:c,data:{plugin:a.plugin,slug:a.slug}}),b.updates.showErrorInCredentialsForm(a.error),b.updates.requestFilesystemCredentials()},b.updates.queueChecker=function(){if(!(b.updates.updateLock||b.updates.updateQueue.length<=0)){var a=b.updates.updateQueue.shift();switch(a.type){case"update-plugin":b.updates.updatePlugin(a.data.plugin,a.data.slug);break;case"install-plugin":b.updates.installPlugin(a.data.slug);break;default:window.console.log("Failed to exect queued update job."),window.console.log(a)}}},b.updates.requestFilesystemCredentials=function(){b.updates.updateDoneSuccessfully===!1&&(b.updates.updateLock=!0,a("body").addClass("modal-open"),a("#request-filesystem-credentials-dialog").show())},a(document).ready(function(){b.updates.shouldRequestFilesystemCredentials=a("#request-filesystem-credentials-dialog").length<=0?!1:!0,a("#request-filesystem-credentials-dialog form").on("submit",function(){return b.updates.filesystemCredentials.ftp.hostname=a("#hostname").val(),b.updates.filesystemCredentials.ftp.username=a("#username").val(),b.updates.filesystemCredentials.ftp.password=a("#password").val(),b.updates.filesystemCredentials.ftp.connectionType=a('input[name="connection_type"]:checked').val(),b.updates.filesystemCredentials.ssh.publicKey=a("#public_key").val(),b.updates.filesystemCredentials.ssh.privateKey=a("#private_key").val(),a("#request-filesystem-credentials-dialog").hide(),a("body").removeClass("modal-open"),b.updates.updateLock=!1,b.updates.queueChecker(),!1}),a(".plugin-update-tr .update-link").on("click",function(c){c.preventDefault(),b.updates.shouldRequestFilesystemCredentials&&!b.updates.updateLock&&b.updates.requestFilesystemCredentials();var d=a(c.target).parents(".plugin-update-tr");b.updates.updatePlugin(d.data("plugin"),d.data("slug"))}),a("#bulk-action-form").on("submit",function(c){var d,e,f;"update-selected"==a("#bulk-action-selector-top").val()&&(c.preventDefault(),a('input[name="checked[]"]:checked').each(function(c,g){d=a(g),e=d.val(),f=d.parents("tr").prop("id"),b.updates.updatePlugin(e,f),d.attr("checked",!1)}))}),a(".plugin-card .update-now").on("click",function(c){c.preventDefault();var d=a(c.target);b.updates.updatePlugin(d.data("plugin"),d.data("slug"))}),a(".plugin-card .install-now").on("click",function(c){c.preventDefault(),b.updates.shouldRequestFilesystemCredentials&&!b.updates.updateLock&&b.updates.requestFilesystemCredentials();var d=a(c.target);d.hasClass("button-disabled")||b.updates.installPlugin(d.data("slug"))})}),a(window).on("message",function(c){var d,e=c.originalEvent,f=document.location,g=f.protocol+"//"+f.hostname;e.origin===g&&(d=a.parseJSON(e.data),"undefined"!=typeof d.action&&"decrementUpdateCount"===d.action&&b.updates.decrementCount(d.upgradeType))})}(jQuery,window.wp,window.pagenow,window.ajaxurl); \ No newline at end of file +window.wp=window.wp||{},function(a,b,c){b.updates={},b.updates.ajaxNonce=window._wpUpdatesSettings.ajax_nonce,b.updates.l10n=window._wpUpdatesSettings.l10n,b.updates.shouldRequestFilesystemCredentials=null,b.updates.filesystemCredentials={ftp:{host:null,username:null,password:null,connectionType:null},ssh:{publicKey:null,privateKey:null}},b.updates.updateLock=!1,b.updates.updateDoneSuccessfully=!1,b.updates.updateQueue=[],b.updates.decrementCount=function(b){var c,d,e=a("#wp-admin-bar-updates .ab-label"),f=a('a[href="update-core.php"] .update-plugins'),g=a("#menu-plugins");if(c=e.text(),c=parseInt(c,10)-1,!(0>c||isNaN(c))&&(a("#wp-admin-bar-updates .ab-item").removeAttr("title"),e.text(c),f.each(function(a,b){b.className=b.className.replace(/count-\d+/,"count-"+c)}),f.removeAttr("title"),f.find(".update-count").text(c),"plugin"===b)){if(d=g.find(".plugin-count").eq(0).text(),d=parseInt(d,10)-1,0>d||isNaN(d))return;g.find(".plugin-count").text(d),g.find(".update-plugins").each(function(a,b){b.className=b.className.replace(/count-\d+/,"count-"+d)}),d>0?a(".subsubsub .upgrade .count").text("("+d+")"):a(".subsubsub .upgrade").remove()}},b.updates.updatePlugin=function(d,e){var f;if("plugins"===c||"plugins-network"===c?f=a('[data-slug="'+e+'"]').next().find(".update-message"):"plugin-install"===c&&(f=a(".plugin-card-"+e).find(".update-now")),f.addClass("updating-message"),f.text(b.updates.l10n.updating),b.a11y.speak(b.updates.l10n.updatingMsg),b.updates.updateLock)return void b.updates.updateQueue.push({type:"update-plugin",data:{plugin:d,slug:e}});b.updates.updateLock=!0;var g={_ajax_nonce:b.updates.ajaxNonce,plugin:d,slug:e,username:b.updates.filesystemCredentials.ftp.username,password:b.updates.filesystemCredentials.ftp.password,hostname:b.updates.filesystemCredentials.ftp.hostname,connection_type:b.updates.filesystemCredentials.ftp.connectionType,public_key:b.updates.filesystemCredentials.ssh.publicKey,private_key:b.updates.filesystemCredentials.ssh.privateKey};b.ajax.post("update-plugin",g).done(b.updates.updateSuccess).fail(b.updates.updateError)},b.updates.updateSuccess=function(d){var e;if("plugins"===c||"plugins-network"===c){var f=a('[data-slug="'+d.slug+'"]').first();e=f.next().find(".update-message"),f.addClass("updated").removeClass("update");var g=f.find(".plugin-version-author-uri").html().replace(d.oldVersion,d.newVersion);f.find(".plugin-version-author-uri").html(g)}else"plugin-install"===c&&(e=a(".plugin-card-"+d.slug).find(".update-now"),e.addClass("button-disabled"));e.removeClass("updating-message").addClass("updated-message"),e.text(b.updates.l10n.updated),b.a11y.speak(b.updates.l10n.updatedMsg),b.updates.decrementCount("plugin"),b.updates.updateDoneSuccessfully=!0,b.updates.updateLock=!1,b.updates.queueChecker()},b.updates.updateError=function(d){var e;return b.updates.updateDoneSuccessfully=!1,d.errorCode&&"unable_to_connect_to_filesystem"==d.errorCode?void b.updates.credentialError(d,"update-plugin"):("plugins"===c||"plugins-network"===c?e=a('[data-slug="'+d.slug+'"]').next().find(".update-message"):"plugin-install"===c&&(e=a(".plugin-card-"+d.slug).find(".update-now")),e.removeClass("updating-message"),e.text(b.updates.l10n.updateFailed),void b.a11y.speak(b.updates.l10n.updateFailed))},b.updates.showErrorInCredentialsForm=function(b){var c=a(".notification-dialog");c.find(".error").remove(),c.find("h3").after('
'+b+"
")},b.updates.installPlugin=function(c){var d=a(".plugin-card-"+c).find(".install-now");if(d.addClass("updating-message"),d.text(b.updates.l10n.installing),b.a11y.speak(b.updates.l10n.installingMsg),b.updates.updateLock)return void b.updates.updateQueue.push({type:"install-plugin",data:{slug:c}});b.updates.updateLock=!0;var e={_ajax_nonce:b.updates.ajaxNonce,slug:c,username:b.updates.filesystemCredentials.ftp.username,password:b.updates.filesystemCredentials.ftp.password,hostname:b.updates.filesystemCredentials.ftp.hostname,connection_type:b.updates.filesystemCredentials.ftp.connectionType,public_key:b.updates.filesystemCredentials.ssh.publicKey,private_key:b.updates.filesystemCredentials.ssh.privateKey};b.ajax.post("install-plugin",e).done(b.updates.installSuccess).fail(b.updates.installError)},b.updates.installSuccess=function(c){var d=a(".plugin-card-"+c.slug).find(".install-now");d.removeClass("updating-message").addClass("updated-message button-disabled"),d.text(b.updates.l10n.installed),b.a11y.speak(b.updates.l10n.installedMsg),b.updates.updateDoneSuccessfully=!0,b.updates.updateLock=!1,b.updates.queueChecker()},b.updates.installError=function(c){var d=a(".plugin-card-"+c.slug).find(".install-now");return b.updates.updateDoneSuccessfully=!1,c.errorCode&&"unable_to_connect_to_filesystem"==c.errorCode?void b.updates.credentialError(c,"install-plugin"):(d.removeClass("updating-message"),d.text(b.updates.l10n.installNow),void(b.updates.updateLock=!1))},b.updates.credentialError=function(a,c){b.updates.updateQueue.push({type:c,data:{plugin:a.plugin,slug:a.slug}}),b.updates.showErrorInCredentialsForm(a.error),b.updates.requestFilesystemCredentials()},b.updates.queueChecker=function(){if(!(b.updates.updateLock||b.updates.updateQueue.length<=0)){var a=b.updates.updateQueue.shift();switch(a.type){case"update-plugin":b.updates.updatePlugin(a.data.plugin,a.data.slug);break;case"install-plugin":b.updates.installPlugin(a.data.slug);break;default:window.console.log("Failed to exect queued update job."),window.console.log(a)}}},b.updates.requestFilesystemCredentials=function(){b.updates.updateDoneSuccessfully===!1&&(b.updates.updateLock=!0,a("body").addClass("modal-open"),a("#request-filesystem-credentials-dialog").show())},a(document).ready(function(){b.updates.shouldRequestFilesystemCredentials=a("#request-filesystem-credentials-dialog").length<=0?!1:!0,a("#request-filesystem-credentials-dialog form").on("submit",function(){return b.updates.filesystemCredentials.ftp.hostname=a("#hostname").val(),b.updates.filesystemCredentials.ftp.username=a("#username").val(),b.updates.filesystemCredentials.ftp.password=a("#password").val(),b.updates.filesystemCredentials.ftp.connectionType=a('input[name="connection_type"]:checked').val(),b.updates.filesystemCredentials.ssh.publicKey=a("#public_key").val(),b.updates.filesystemCredentials.ssh.privateKey=a("#private_key").val(),a("#request-filesystem-credentials-dialog").hide(),a("body").removeClass("modal-open"),b.updates.updateLock=!1,b.updates.queueChecker(),!1}),a(".plugin-update-tr .update-link").on("click",function(c){c.preventDefault(),b.updates.shouldRequestFilesystemCredentials&&!b.updates.updateLock&&b.updates.requestFilesystemCredentials();var d=a(c.target).parents(".plugin-update-tr");b.updates.updatePlugin(d.data("plugin"),d.data("slug"))}),a("#bulk-action-form").on("submit",function(c){var d,e,f;"update-selected"==a("#bulk-action-selector-top").val()&&(c.preventDefault(),a('input[name="checked[]"]:checked').each(function(c,g){d=a(g),e=d.val(),f=d.parents("tr").prop("id"),b.updates.updatePlugin(e,f),d.attr("checked",!1)}))}),a(".plugin-card .update-now").on("click",function(c){c.preventDefault();var d=a(c.target);b.updates.updatePlugin(d.data("plugin"),d.data("slug"))}),a(".plugin-card .install-now").on("click",function(c){c.preventDefault(),b.updates.shouldRequestFilesystemCredentials&&!b.updates.updateLock&&b.updates.requestFilesystemCredentials();var d=a(c.target);d.hasClass("button-disabled")||b.updates.installPlugin(d.data("slug"))})}),a(window).on("message",function(c){var d,e=c.originalEvent,f=document.location,g=f.protocol+"//"+f.hostname;e.origin===g&&(d=a.parseJSON(e.data),"undefined"!=typeof d.action&&"decrementUpdateCount"===d.action&&b.updates.decrementCount(d.upgradeType))})}(jQuery,window.wp,window.pagenow,window.ajaxurl); \ No newline at end of file diff --git a/wp-includes/version.php b/wp-includes/version.php index cb814c7e67..033fc5b860 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.2-beta1-31830'; +$wp_version = '4.2-beta1-31831'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.