diff --git a/wp-admin/js/updates.js b/wp-admin/js/updates.js index e76b51025d..9af24327ce 100644 --- a/wp-admin/js/updates.js +++ b/wp-admin/js/updates.js @@ -1,6 +1,6 @@ window.wp = window.wp || {}; -(function( $, wp, pagenow, ajaxurl ) { +(function( $, wp, pagenow ) { wp.updates = {}; /** @@ -122,45 +122,15 @@ window.wp = window.wp || {}; wp.updates.updateLock = true; var data = { - 'action': 'update-plugin', '_ajax_nonce': wp.updates.ajaxNonce, 'plugin': plugin, 'slug': slug }; - $.ajax( { - type: 'post', - url: ajaxurl, - data: data, - complete: wp.updates.updateRequestComplete - } ); - }; - - /** - * After an update attempt has completed, deal with the response. - * - * @since 4.2.0 - * - * @param {jqXHR} jqxhr The jQuery XMLHttpRequest for the request. - */ - wp.updates.updateRequestComplete = function( jqxhr ) { - wp.updates.updateLock = false; - if ( jqxhr.responseJSON && jqxhr.responseJSON.success ) { - wp.updates.updateSuccess( jqxhr.responseJSON ); - } else { - var alertText = wp.updates.l10n.updateFailed; - if ( jqxhr.responseJSON && jqxhr.responseJSON.data && jqxhr.responseJSON.data.error ) { - alertText += ': ' + jqxhr.responseJSON.data.error; - } - window.alert( alertText ); - if ( jqxhr.responseJSON && jqxhr.responseJSON.data && jqxhr.responseJSON.data.slug ) { - wp.updates.updateError( jqxhr.responseJSON ); - } - } - /** - * Check the queue. - */ - wp.updates.queueChecker(); + wp.ajax.post( 'update-plugin', data ) + .done( wp.updates.updateSuccess ) + .fail( wp.updates.updateError ) + .always( wp.updates.updateAlways ); }; /** @@ -173,11 +143,11 @@ window.wp = window.wp || {}; wp.updates.updateSuccess = function( response ) { var $message; if ( 'plugins' === pagenow || 'plugins-network' === pagenow ) { - $message = $( '#' + response.data.slug ).next().find( '.update-message' ); - $( '#' + response.data.slug ).addClass( 'updated' ).removeClass( 'update' ); - $( '#' + response.data.slug + '-update' ).addClass( 'updated' ).removeClass( 'update' ); + $message = $( '#' + response.slug ).next().find( '.update-message' ); + $( '#' + response.slug ).addClass( 'updated' ).removeClass( 'update' ); + $( '#' + response.slug + '-update' ).addClass( 'updated' ).removeClass( 'update' ); } else if ( 'plugin-install' === pagenow ) { - $message = $( '.plugin-card-' + response.data.slug ).find( '.update-now' ); + $message = $( '.plugin-card-' + response.slug ).find( '.update-now' ); $message.addClass( 'button-disabled' ); } @@ -197,14 +167,25 @@ window.wp = window.wp || {}; wp.updates.updateError = function( response ) { var $message; if ( 'plugins' === pagenow || 'plugins-network' === pagenow ) { - $message = $( '#' + response.data.slug ).next().find( '.update-message' ); + $message = $( '#' + response.slug ).next().find( '.update-message' ); } else if ( 'plugin-install' === pagenow ) { - $message = $( '.plugin-card-' + response.data.slug ).find( '.update-now' ); + $message = $( '.plugin-card-' + response.slug ).find( '.update-now' ); } $message.removeClass( 'updating-message' ); $message.text( wp.updates.l10n.updateFailed ); }; + /** + * After an update attempt has completed, check the queue. + * + * @since 4.2.0 + */ + wp.updates.updateAlways = function() { + wp.updates.updateLock = false; + wp.updates.queueChecker(); + }; + + /** * Send an Ajax request to the server to install a plugin. * @@ -231,45 +212,14 @@ window.wp = window.wp || {}; wp.updates.updateLock = true; var data = { - 'action': 'install-plugin', '_ajax_nonce': wp.updates.ajaxNonce, 'slug': slug }; - $.ajax( { - type: 'post', - url: ajaxurl, - data: data, - complete: wp.updates.installRequestComplete - } ); - }; - - - /** - * After an installation attempt has completed, deal with the response. - * - * @since 4.2.0 - * - * @param {jqXHR} jqxhr The jQuery XMLHttpRequest for the request. - */ - wp.updates.installRequestComplete = function( jqxhr ) { - wp.updates.updateLock = false; - if ( jqxhr.responseJSON && jqxhr.responseJSON.success ) { - wp.updates.installSuccess( jqxhr.responseJSON ); - } else { - var alertText = wp.updates.l10n.installFailed; - if ( jqxhr.responseJSON && jqxhr.responseJSON.data && jqxhr.responseJSON.data.error ) { - alertText += ': ' + jqxhr.responseJSON.data.error; - } - window.alert( alertText ); - if ( jqxhr.responseJSON && jqxhr.responseJSON.data && jqxhr.responseJSON.data.slug ) { - wp.updates.installError( jqxhr.responseJSON ); - } - } - /** - * Check the queue. - */ - wp.updates.queueChecker(); + wp.ajax.post( 'install-plugin', data ) + .done( wp.updates.installSuccess ) + .fail( wp.updates.installError ) + .always( wp.updates.updateAlways ); }; /** @@ -280,7 +230,7 @@ window.wp = window.wp || {}; * @param {object} response */ wp.updates.installSuccess = function( response ) { - var $message = $( '.plugin-card-' + response.data.slug ).find( '.install-now' ); + var $message = $( '.plugin-card-' + response.slug ).find( '.install-now' ); $message.removeClass( 'updating-message' ).addClass( 'updated-message button-disabled' ); $message.text( wp.updates.l10n.installed ); @@ -294,7 +244,7 @@ window.wp = window.wp || {}; * @param {object} response */ wp.updates.installError = function( response ) { - var $message = $( '.plugin-card-' + response.data.slug ).find( '.install-now' ); + var $message = $( '.plugin-card-' + response.slug ).find( '.install-now' ); $message.removeClass( 'updating-message' ); $message.text( wp.updates.l10n.installNow ); diff --git a/wp-admin/js/updates.min.js b/wp-admin/js/updates.min.js index ea26260ee1..9635a80036 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,d){b.updates={},b.updates.ajaxNonce=window._wpUpdatesSettings.ajax_nonce,b.updates.l10n=window._wpUpdatesSettings.l10n,b.updates.updateLock=!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(e,f){var g;if("plugins"===c||"plugins-network"===c?g=a("#"+f).next().find(".update-message"):"plugin-install"===c&&(g=a(".plugin-card-"+f).find(".update-now")),g.addClass("updating-message"),g.text(b.updates.l10n.updating),b.updates.updateLock)return void b.updates.updateQueue.push({type:"update-plugin",data:{plugin:e,slug:f}});b.updates.updateLock=!0;var h={action:"update-plugin",_ajax_nonce:b.updates.ajaxNonce,plugin:e,slug:f};a.ajax({type:"post",url:d,data:h,complete:b.updates.updateRequestComplete})},b.updates.updateRequestComplete=function(a){if(b.updates.updateLock=!1,a.responseJSON&&a.responseJSON.success)b.updates.updateSuccess(a.responseJSON);else{var c=b.updates.l10n.updateFailed;a.responseJSON&&a.responseJSON.data&&a.responseJSON.data.error&&(c+=": "+a.responseJSON.data.error),window.alert(c),a.responseJSON&&a.responseJSON.data&&a.responseJSON.data.slug&&b.updates.updateError(a.responseJSON)}b.updates.queueChecker()},b.updates.updateSuccess=function(d){var e;"plugins"===c||"plugins-network"===c?(e=a("#"+d.data.slug).next().find(".update-message"),a("#"+d.data.slug).addClass("updated").removeClass("update"),a("#"+d.data.slug+"-update").addClass("updated").removeClass("update")):"plugin-install"===c&&(e=a(".plugin-card-"+d.data.slug).find(".update-now"),e.addClass("button-disabled")),e.removeClass("updating-message").addClass("updated-message"),e.text(b.updates.l10n.updated),b.updates.decrementCount("plugin")},b.updates.updateError=function(d){var e;"plugins"===c||"plugins-network"===c?e=a("#"+d.data.slug).next().find(".update-message"):"plugin-install"===c&&(e=a(".plugin-card-"+d.data.slug).find(".update-now")),e.removeClass("updating-message"),e.text(b.updates.l10n.updateFailed)},b.updates.installPlugin=function(c){var e=a(".plugin-card-"+c).find(".install-now");if(e.addClass("updating-message"),e.text(b.updates.l10n.installing),b.updates.updateLock)return void b.updates.updateQueue.push({type:"install-plugin",data:{slug:c}});b.updates.updateLock=!0;var f={action:"install-plugin",_ajax_nonce:b.updates.ajaxNonce,slug:c};a.ajax({type:"post",url:d,data:f,complete:b.updates.installRequestComplete})},b.updates.installRequestComplete=function(a){if(b.updates.updateLock=!1,a.responseJSON&&a.responseJSON.success)b.updates.installSuccess(a.responseJSON);else{var c=b.updates.l10n.installFailed;a.responseJSON&&a.responseJSON.data&&a.responseJSON.data.error&&(c+=": "+a.responseJSON.data.error),window.alert(c),a.responseJSON&&a.responseJSON.data&&a.responseJSON.data.slug&&b.updates.installError(a.responseJSON)}b.updates.queueChecker()},b.updates.installSuccess=function(c){var d=a(".plugin-card-"+c.data.slug).find(".install-now");d.removeClass("updating-message").addClass("updated-message button-disabled"),d.text(b.updates.l10n.installed)},b.updates.installError=function(c){var d=a(".plugin-card-"+c.data.slug).find(".install-now");d.removeClass("updating-message"),d.text(b.updates.l10n.installNow)},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)}}},a(document).ready(function(){a(".plugin-update-tr .update-link").on("click",function(c){c.preventDefault();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();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.updateLock=!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.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};b.ajax.post("update-plugin",g).done(b.updates.updateSuccess).fail(b.updates.updateError).always(b.updates.updateAlways)},b.updates.updateSuccess=function(d){var e;"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")):"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.updates.decrementCount("plugin")},b.updates.updateError=function(d){var e;"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)},b.updates.updateAlways=function(){b.updates.updateLock=!1,b.updates.queueChecker()},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.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};b.ajax.post("install-plugin",e).done(b.updates.installSuccess).fail(b.updates.installError).always(b.updates.updateAlways)},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.updates.installError=function(c){var d=a(".plugin-card-"+c.slug).find(".install-now");d.removeClass("updating-message"),d.text(b.updates.l10n.installNow)},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)}}},a(document).ready(function(){a(".plugin-update-tr .update-link").on("click",function(c){c.preventDefault();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();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/script-loader.php b/wp-includes/script-loader.php index 8fb0b4c15a..88f1c41536 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -500,7 +500,7 @@ function wp_default_scripts( &$scripts ) { 'ays' => __('Are you sure you want to install this plugin?') ) ); - $scripts->add( 'updates', "/wp-admin/js/updates$suffix.js", array( 'jquery' ) ); + $scripts->add( 'updates', "/wp-admin/js/updates$suffix.js", array( 'jquery', 'wp-util' ) ); did_action( 'init' ) && $scripts->localize( 'updates', '_wpUpdatesSettings', array( 'ajax_nonce' => wp_create_nonce( 'updates' ), 'l10n' => array( diff --git a/wp-includes/version.php b/wp-includes/version.php index 61a3736518..1db36202ed 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.2-alpha-31408'; +$wp_version = '4.2-alpha-31409'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.