Edit File by line
/home/barbar84/public_h.../wp-admin/js
File: updates.js
/**
[0] Fix | Delete
* Functions for ajaxified updates, deletions and installs inside the WordPress admin.
[1] Fix | Delete
*
[2] Fix | Delete
* @version 4.2.0
[3] Fix | Delete
* @output wp-admin/js/updates.js
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
/* global pagenow */
[7] Fix | Delete
[8] Fix | Delete
/**
[9] Fix | Delete
* @param {jQuery} $ jQuery object.
[10] Fix | Delete
* @param {object} wp WP object.
[11] Fix | Delete
* @param {object} settings WP Updates settings.
[12] Fix | Delete
* @param {string} settings.ajax_nonce Ajax nonce.
[13] Fix | Delete
* @param {object=} settings.plugins Base names of plugins in their different states.
[14] Fix | Delete
* @param {Array} settings.plugins.all Base names of all plugins.
[15] Fix | Delete
* @param {Array} settings.plugins.active Base names of active plugins.
[16] Fix | Delete
* @param {Array} settings.plugins.inactive Base names of inactive plugins.
[17] Fix | Delete
* @param {Array} settings.plugins.upgrade Base names of plugins with updates available.
[18] Fix | Delete
* @param {Array} settings.plugins.recently_activated Base names of recently activated plugins.
[19] Fix | Delete
* @param {Array} settings.plugins['auto-update-enabled'] Base names of plugins set to auto-update.
[20] Fix | Delete
* @param {Array} settings.plugins['auto-update-disabled'] Base names of plugins set to not auto-update.
[21] Fix | Delete
* @param {object=} settings.themes Slugs of themes in their different states.
[22] Fix | Delete
* @param {Array} settings.themes.all Slugs of all themes.
[23] Fix | Delete
* @param {Array} settings.themes.upgrade Slugs of themes with updates available.
[24] Fix | Delete
* @param {Arrat} settings.themes.disabled Slugs of disabled themes.
[25] Fix | Delete
* @param {Array} settings.themes['auto-update-enabled'] Slugs of themes set to auto-update.
[26] Fix | Delete
* @param {Array} settings.themes['auto-update-disabled'] Slugs of themes set to not auto-update.
[27] Fix | Delete
* @param {object=} settings.totals Combined information for available update counts.
[28] Fix | Delete
* @param {number} settings.totals.count Holds the amount of available updates.
[29] Fix | Delete
*/
[30] Fix | Delete
(function( $, wp, settings ) {
[31] Fix | Delete
var $document = $( document ),
[32] Fix | Delete
__ = wp.i18n.__,
[33] Fix | Delete
_x = wp.i18n._x,
[34] Fix | Delete
sprintf = wp.i18n.sprintf;
[35] Fix | Delete
[36] Fix | Delete
wp = wp || {};
[37] Fix | Delete
[38] Fix | Delete
/**
[39] Fix | Delete
* The WP Updates object.
[40] Fix | Delete
*
[41] Fix | Delete
* @since 4.2.0
[42] Fix | Delete
*
[43] Fix | Delete
* @namespace wp.updates
[44] Fix | Delete
*/
[45] Fix | Delete
wp.updates = {};
[46] Fix | Delete
[47] Fix | Delete
/**
[48] Fix | Delete
* Removed in 5.5.0, needed for back-compatibility.
[49] Fix | Delete
*
[50] Fix | Delete
* @since 4.2.0
[51] Fix | Delete
* @deprecated 5.5.0
[52] Fix | Delete
*
[53] Fix | Delete
* @type {object}
[54] Fix | Delete
*/
[55] Fix | Delete
wp.updates.l10n = {
[56] Fix | Delete
searchResults: '',
[57] Fix | Delete
searchResultsLabel: '',
[58] Fix | Delete
noPlugins: '',
[59] Fix | Delete
noItemsSelected: '',
[60] Fix | Delete
updating: '',
[61] Fix | Delete
pluginUpdated: '',
[62] Fix | Delete
themeUpdated: '',
[63] Fix | Delete
update: '',
[64] Fix | Delete
updateNow: '',
[65] Fix | Delete
pluginUpdateNowLabel: '',
[66] Fix | Delete
updateFailedShort: '',
[67] Fix | Delete
updateFailed: '',
[68] Fix | Delete
pluginUpdatingLabel: '',
[69] Fix | Delete
pluginUpdatedLabel: '',
[70] Fix | Delete
pluginUpdateFailedLabel: '',
[71] Fix | Delete
updatingMsg: '',
[72] Fix | Delete
updatedMsg: '',
[73] Fix | Delete
updateCancel: '',
[74] Fix | Delete
beforeunload: '',
[75] Fix | Delete
installNow: '',
[76] Fix | Delete
pluginInstallNowLabel: '',
[77] Fix | Delete
installing: '',
[78] Fix | Delete
pluginInstalled: '',
[79] Fix | Delete
themeInstalled: '',
[80] Fix | Delete
installFailedShort: '',
[81] Fix | Delete
installFailed: '',
[82] Fix | Delete
pluginInstallingLabel: '',
[83] Fix | Delete
themeInstallingLabel: '',
[84] Fix | Delete
pluginInstalledLabel: '',
[85] Fix | Delete
themeInstalledLabel: '',
[86] Fix | Delete
pluginInstallFailedLabel: '',
[87] Fix | Delete
themeInstallFailedLabel: '',
[88] Fix | Delete
installingMsg: '',
[89] Fix | Delete
installedMsg: '',
[90] Fix | Delete
importerInstalledMsg: '',
[91] Fix | Delete
aysDelete: '',
[92] Fix | Delete
aysDeleteUninstall: '',
[93] Fix | Delete
aysBulkDelete: '',
[94] Fix | Delete
aysBulkDeleteThemes: '',
[95] Fix | Delete
deleting: '',
[96] Fix | Delete
deleteFailed: '',
[97] Fix | Delete
pluginDeleted: '',
[98] Fix | Delete
themeDeleted: '',
[99] Fix | Delete
livePreview: '',
[100] Fix | Delete
activatePlugin: '',
[101] Fix | Delete
activateTheme: '',
[102] Fix | Delete
activatePluginLabel: '',
[103] Fix | Delete
activateThemeLabel: '',
[104] Fix | Delete
activateImporter: '',
[105] Fix | Delete
activateImporterLabel: '',
[106] Fix | Delete
unknownError: '',
[107] Fix | Delete
connectionError: '',
[108] Fix | Delete
nonceError: '',
[109] Fix | Delete
pluginsFound: '',
[110] Fix | Delete
noPluginsFound: '',
[111] Fix | Delete
autoUpdatesEnable: '',
[112] Fix | Delete
autoUpdatesEnabling: '',
[113] Fix | Delete
autoUpdatesEnabled: '',
[114] Fix | Delete
autoUpdatesDisable: '',
[115] Fix | Delete
autoUpdatesDisabling: '',
[116] Fix | Delete
autoUpdatesDisabled: '',
[117] Fix | Delete
autoUpdatesError: ''
[118] Fix | Delete
};
[119] Fix | Delete
[120] Fix | Delete
wp.updates.l10n = window.wp.deprecateL10nObject( 'wp.updates.l10n', wp.updates.l10n, '5.5.0' );
[121] Fix | Delete
[122] Fix | Delete
/**
[123] Fix | Delete
* User nonce for ajax calls.
[124] Fix | Delete
*
[125] Fix | Delete
* @since 4.2.0
[126] Fix | Delete
*
[127] Fix | Delete
* @type {string}
[128] Fix | Delete
*/
[129] Fix | Delete
wp.updates.ajaxNonce = settings.ajax_nonce;
[130] Fix | Delete
[131] Fix | Delete
/**
[132] Fix | Delete
* Current search term.
[133] Fix | Delete
*
[134] Fix | Delete
* @since 4.6.0
[135] Fix | Delete
*
[136] Fix | Delete
* @type {string}
[137] Fix | Delete
*/
[138] Fix | Delete
wp.updates.searchTerm = '';
[139] Fix | Delete
[140] Fix | Delete
/**
[141] Fix | Delete
* Whether filesystem credentials need to be requested from the user.
[142] Fix | Delete
*
[143] Fix | Delete
* @since 4.2.0
[144] Fix | Delete
*
[145] Fix | Delete
* @type {bool}
[146] Fix | Delete
*/
[147] Fix | Delete
wp.updates.shouldRequestFilesystemCredentials = false;
[148] Fix | Delete
[149] Fix | Delete
/**
[150] Fix | Delete
* Filesystem credentials to be packaged along with the request.
[151] Fix | Delete
*
[152] Fix | Delete
* @since 4.2.0
[153] Fix | Delete
* @since 4.6.0 Added `available` property to indicate whether credentials have been provided.
[154] Fix | Delete
*
[155] Fix | Delete
* @type {Object}
[156] Fix | Delete
* @property {Object} filesystemCredentials.ftp Holds FTP credentials.
[157] Fix | Delete
* @property {string} filesystemCredentials.ftp.host FTP host. Default empty string.
[158] Fix | Delete
* @property {string} filesystemCredentials.ftp.username FTP user name. Default empty string.
[159] Fix | Delete
* @property {string} filesystemCredentials.ftp.password FTP password. Default empty string.
[160] Fix | Delete
* @property {string} filesystemCredentials.ftp.connectionType Type of FTP connection. 'ssh', 'ftp', or 'ftps'.
[161] Fix | Delete
* Default empty string.
[162] Fix | Delete
* @property {Object} filesystemCredentials.ssh Holds SSH credentials.
[163] Fix | Delete
* @property {string} filesystemCredentials.ssh.publicKey The public key. Default empty string.
[164] Fix | Delete
* @property {string} filesystemCredentials.ssh.privateKey The private key. Default empty string.
[165] Fix | Delete
* @property {string} filesystemCredentials.fsNonce Filesystem credentials form nonce.
[166] Fix | Delete
* @property {bool} filesystemCredentials.available Whether filesystem credentials have been provided.
[167] Fix | Delete
* Default 'false'.
[168] Fix | Delete
*/
[169] Fix | Delete
wp.updates.filesystemCredentials = {
[170] Fix | Delete
ftp: {
[171] Fix | Delete
host: '',
[172] Fix | Delete
username: '',
[173] Fix | Delete
password: '',
[174] Fix | Delete
connectionType: ''
[175] Fix | Delete
},
[176] Fix | Delete
ssh: {
[177] Fix | Delete
publicKey: '',
[178] Fix | Delete
privateKey: ''
[179] Fix | Delete
},
[180] Fix | Delete
fsNonce: '',
[181] Fix | Delete
available: false
[182] Fix | Delete
};
[183] Fix | Delete
[184] Fix | Delete
/**
[185] Fix | Delete
* Whether we're waiting for an Ajax request to complete.
[186] Fix | Delete
*
[187] Fix | Delete
* @since 4.2.0
[188] Fix | Delete
* @since 4.6.0 More accurately named `ajaxLocked`.
[189] Fix | Delete
*
[190] Fix | Delete
* @type {bool}
[191] Fix | Delete
*/
[192] Fix | Delete
wp.updates.ajaxLocked = false;
[193] Fix | Delete
[194] Fix | Delete
/**
[195] Fix | Delete
* Admin notice template.
[196] Fix | Delete
*
[197] Fix | Delete
* @since 4.6.0
[198] Fix | Delete
*
[199] Fix | Delete
* @type {function}
[200] Fix | Delete
*/
[201] Fix | Delete
wp.updates.adminNotice = wp.template( 'wp-updates-admin-notice' );
[202] Fix | Delete
[203] Fix | Delete
/**
[204] Fix | Delete
* Update queue.
[205] Fix | Delete
*
[206] Fix | Delete
* If the user tries to update a plugin while an update is
[207] Fix | Delete
* already happening, it can be placed in this queue to perform later.
[208] Fix | Delete
*
[209] Fix | Delete
* @since 4.2.0
[210] Fix | Delete
* @since 4.6.0 More accurately named `queue`.
[211] Fix | Delete
*
[212] Fix | Delete
* @type {Array.object}
[213] Fix | Delete
*/
[214] Fix | Delete
wp.updates.queue = [];
[215] Fix | Delete
[216] Fix | Delete
/**
[217] Fix | Delete
* Holds a jQuery reference to return focus to when exiting the request credentials modal.
[218] Fix | Delete
*
[219] Fix | Delete
* @since 4.2.0
[220] Fix | Delete
*
[221] Fix | Delete
* @type {jQuery}
[222] Fix | Delete
*/
[223] Fix | Delete
wp.updates.$elToReturnFocusToFromCredentialsModal = undefined;
[224] Fix | Delete
[225] Fix | Delete
/**
[226] Fix | Delete
* Adds or updates an admin notice.
[227] Fix | Delete
*
[228] Fix | Delete
* @since 4.6.0
[229] Fix | Delete
*
[230] Fix | Delete
* @param {Object} data
[231] Fix | Delete
* @param {*=} data.selector Optional. Selector of an element to be replaced with the admin notice.
[232] Fix | Delete
* @param {string=} data.id Optional. Unique id that will be used as the notice's id attribute.
[233] Fix | Delete
* @param {string=} data.className Optional. Class names that will be used in the admin notice.
[234] Fix | Delete
* @param {string=} data.message Optional. The message displayed in the notice.
[235] Fix | Delete
* @param {number=} data.successes Optional. The amount of successful operations.
[236] Fix | Delete
* @param {number=} data.errors Optional. The amount of failed operations.
[237] Fix | Delete
* @param {Array=} data.errorMessages Optional. Error messages of failed operations.
[238] Fix | Delete
*
[239] Fix | Delete
*/
[240] Fix | Delete
wp.updates.addAdminNotice = function( data ) {
[241] Fix | Delete
var $notice = $( data.selector ),
[242] Fix | Delete
$headerEnd = $( '.wp-header-end' ),
[243] Fix | Delete
$adminNotice;
[244] Fix | Delete
[245] Fix | Delete
delete data.selector;
[246] Fix | Delete
$adminNotice = wp.updates.adminNotice( data );
[247] Fix | Delete
[248] Fix | Delete
// Check if this admin notice already exists.
[249] Fix | Delete
if ( ! $notice.length ) {
[250] Fix | Delete
$notice = $( '#' + data.id );
[251] Fix | Delete
}
[252] Fix | Delete
[253] Fix | Delete
if ( $notice.length ) {
[254] Fix | Delete
$notice.replaceWith( $adminNotice );
[255] Fix | Delete
} else if ( $headerEnd.length ) {
[256] Fix | Delete
$headerEnd.after( $adminNotice );
[257] Fix | Delete
} else {
[258] Fix | Delete
if ( 'customize' === pagenow ) {
[259] Fix | Delete
$( '.customize-themes-notifications' ).append( $adminNotice );
[260] Fix | Delete
} else {
[261] Fix | Delete
$( '.wrap' ).find( '> h1' ).after( $adminNotice );
[262] Fix | Delete
}
[263] Fix | Delete
}
[264] Fix | Delete
[265] Fix | Delete
$document.trigger( 'wp-updates-notice-added' );
[266] Fix | Delete
};
[267] Fix | Delete
[268] Fix | Delete
/**
[269] Fix | Delete
* Handles Ajax requests to WordPress.
[270] Fix | Delete
*
[271] Fix | Delete
* @since 4.6.0
[272] Fix | Delete
*
[273] Fix | Delete
* @param {string} action The type of Ajax request ('update-plugin', 'install-theme', etc).
[274] Fix | Delete
* @param {Object} data Data that needs to be passed to the ajax callback.
[275] Fix | Delete
* @return {$.promise} A jQuery promise that represents the request,
[276] Fix | Delete
* decorated with an abort() method.
[277] Fix | Delete
*/
[278] Fix | Delete
wp.updates.ajax = function( action, data ) {
[279] Fix | Delete
var options = {};
[280] Fix | Delete
[281] Fix | Delete
if ( wp.updates.ajaxLocked ) {
[282] Fix | Delete
wp.updates.queue.push( {
[283] Fix | Delete
action: action,
[284] Fix | Delete
data: data
[285] Fix | Delete
} );
[286] Fix | Delete
[287] Fix | Delete
// Return a Deferred object so callbacks can always be registered.
[288] Fix | Delete
return $.Deferred();
[289] Fix | Delete
}
[290] Fix | Delete
[291] Fix | Delete
wp.updates.ajaxLocked = true;
[292] Fix | Delete
[293] Fix | Delete
if ( data.success ) {
[294] Fix | Delete
options.success = data.success;
[295] Fix | Delete
delete data.success;
[296] Fix | Delete
}
[297] Fix | Delete
[298] Fix | Delete
if ( data.error ) {
[299] Fix | Delete
options.error = data.error;
[300] Fix | Delete
delete data.error;
[301] Fix | Delete
}
[302] Fix | Delete
[303] Fix | Delete
options.data = _.extend( data, {
[304] Fix | Delete
action: action,
[305] Fix | Delete
_ajax_nonce: wp.updates.ajaxNonce,
[306] Fix | Delete
_fs_nonce: wp.updates.filesystemCredentials.fsNonce,
[307] Fix | Delete
username: wp.updates.filesystemCredentials.ftp.username,
[308] Fix | Delete
password: wp.updates.filesystemCredentials.ftp.password,
[309] Fix | Delete
hostname: wp.updates.filesystemCredentials.ftp.hostname,
[310] Fix | Delete
connection_type: wp.updates.filesystemCredentials.ftp.connectionType,
[311] Fix | Delete
public_key: wp.updates.filesystemCredentials.ssh.publicKey,
[312] Fix | Delete
private_key: wp.updates.filesystemCredentials.ssh.privateKey
[313] Fix | Delete
} );
[314] Fix | Delete
[315] Fix | Delete
return wp.ajax.send( options ).always( wp.updates.ajaxAlways );
[316] Fix | Delete
};
[317] Fix | Delete
[318] Fix | Delete
/**
[319] Fix | Delete
* Actions performed after every Ajax request.
[320] Fix | Delete
*
[321] Fix | Delete
* @since 4.6.0
[322] Fix | Delete
*
[323] Fix | Delete
* @param {Object} response
[324] Fix | Delete
* @param {Array=} response.debug Optional. Debug information.
[325] Fix | Delete
* @param {string=} response.errorCode Optional. Error code for an error that occurred.
[326] Fix | Delete
*/
[327] Fix | Delete
wp.updates.ajaxAlways = function( response ) {
[328] Fix | Delete
if ( ! response.errorCode || 'unable_to_connect_to_filesystem' !== response.errorCode ) {
[329] Fix | Delete
wp.updates.ajaxLocked = false;
[330] Fix | Delete
wp.updates.queueChecker();
[331] Fix | Delete
}
[332] Fix | Delete
[333] Fix | Delete
if ( 'undefined' !== typeof response.debug && window.console && window.console.log ) {
[334] Fix | Delete
_.map( response.debug, function( message ) {
[335] Fix | Delete
// Remove all HTML tags and write a message to the console.
[336] Fix | Delete
window.console.log( wp.sanitize.stripTagsAndEncodeText( message ) );
[337] Fix | Delete
} );
[338] Fix | Delete
}
[339] Fix | Delete
};
[340] Fix | Delete
[341] Fix | Delete
/**
[342] Fix | Delete
* Refreshes update counts everywhere on the screen.
[343] Fix | Delete
*
[344] Fix | Delete
* @since 4.7.0
[345] Fix | Delete
*/
[346] Fix | Delete
wp.updates.refreshCount = function() {
[347] Fix | Delete
var $adminBarUpdates = $( '#wp-admin-bar-updates' ),
[348] Fix | Delete
$dashboardNavMenuUpdateCount = $( 'a[href="update-core.php"] .update-plugins' ),
[349] Fix | Delete
$pluginsNavMenuUpdateCount = $( 'a[href="plugins.php"] .update-plugins' ),
[350] Fix | Delete
$appearanceNavMenuUpdateCount = $( 'a[href="themes.php"] .update-plugins' ),
[351] Fix | Delete
itemCount;
[352] Fix | Delete
[353] Fix | Delete
$adminBarUpdates.find( '.ab-item' ).removeAttr( 'title' );
[354] Fix | Delete
$adminBarUpdates.find( '.ab-label' ).text( settings.totals.counts.total );
[355] Fix | Delete
[356] Fix | Delete
// Remove the update count from the toolbar if it's zero.
[357] Fix | Delete
if ( 0 === settings.totals.counts.total ) {
[358] Fix | Delete
$adminBarUpdates.find( '.ab-label' ).parents( 'li' ).remove();
[359] Fix | Delete
}
[360] Fix | Delete
[361] Fix | Delete
// Update the "Updates" menu item.
[362] Fix | Delete
$dashboardNavMenuUpdateCount.each( function( index, element ) {
[363] Fix | Delete
element.className = element.className.replace( /count-\d+/, 'count-' + settings.totals.counts.total );
[364] Fix | Delete
} );
[365] Fix | Delete
if ( settings.totals.counts.total > 0 ) {
[366] Fix | Delete
$dashboardNavMenuUpdateCount.find( '.update-count' ).text( settings.totals.counts.total );
[367] Fix | Delete
} else {
[368] Fix | Delete
$dashboardNavMenuUpdateCount.remove();
[369] Fix | Delete
}
[370] Fix | Delete
[371] Fix | Delete
// Update the "Plugins" menu item.
[372] Fix | Delete
$pluginsNavMenuUpdateCount.each( function( index, element ) {
[373] Fix | Delete
element.className = element.className.replace( /count-\d+/, 'count-' + settings.totals.counts.plugins );
[374] Fix | Delete
} );
[375] Fix | Delete
if ( settings.totals.counts.total > 0 ) {
[376] Fix | Delete
$pluginsNavMenuUpdateCount.find( '.plugin-count' ).text( settings.totals.counts.plugins );
[377] Fix | Delete
} else {
[378] Fix | Delete
$pluginsNavMenuUpdateCount.remove();
[379] Fix | Delete
}
[380] Fix | Delete
[381] Fix | Delete
// Update the "Appearance" menu item.
[382] Fix | Delete
$appearanceNavMenuUpdateCount.each( function( index, element ) {
[383] Fix | Delete
element.className = element.className.replace( /count-\d+/, 'count-' + settings.totals.counts.themes );
[384] Fix | Delete
} );
[385] Fix | Delete
if ( settings.totals.counts.total > 0 ) {
[386] Fix | Delete
$appearanceNavMenuUpdateCount.find( '.theme-count' ).text( settings.totals.counts.themes );
[387] Fix | Delete
} else {
[388] Fix | Delete
$appearanceNavMenuUpdateCount.remove();
[389] Fix | Delete
}
[390] Fix | Delete
[391] Fix | Delete
// Update list table filter navigation.
[392] Fix | Delete
if ( 'plugins' === pagenow || 'plugins-network' === pagenow ) {
[393] Fix | Delete
itemCount = settings.totals.counts.plugins;
[394] Fix | Delete
} else if ( 'themes' === pagenow || 'themes-network' === pagenow ) {
[395] Fix | Delete
itemCount = settings.totals.counts.themes;
[396] Fix | Delete
}
[397] Fix | Delete
[398] Fix | Delete
if ( itemCount > 0 ) {
[399] Fix | Delete
$( '.subsubsub .upgrade .count' ).text( '(' + itemCount + ')' );
[400] Fix | Delete
} else {
[401] Fix | Delete
$( '.subsubsub .upgrade' ).remove();
[402] Fix | Delete
$( '.subsubsub li:last' ).html( function() { return $( this ).children(); } );
[403] Fix | Delete
}
[404] Fix | Delete
};
[405] Fix | Delete
[406] Fix | Delete
/**
[407] Fix | Delete
* Decrements the update counts throughout the various menus.
[408] Fix | Delete
*
[409] Fix | Delete
* This includes the toolbar, the "Updates" menu item and the menu items
[410] Fix | Delete
* for plugins and themes.
[411] Fix | Delete
*
[412] Fix | Delete
* @since 3.9.0
[413] Fix | Delete
*
[414] Fix | Delete
* @param {string} type The type of item that was updated or deleted.
[415] Fix | Delete
* Can be 'plugin', 'theme'.
[416] Fix | Delete
*/
[417] Fix | Delete
wp.updates.decrementCount = function( type ) {
[418] Fix | Delete
settings.totals.counts.total = Math.max( --settings.totals.counts.total, 0 );
[419] Fix | Delete
[420] Fix | Delete
if ( 'plugin' === type ) {
[421] Fix | Delete
settings.totals.counts.plugins = Math.max( --settings.totals.counts.plugins, 0 );
[422] Fix | Delete
} else if ( 'theme' === type ) {
[423] Fix | Delete
settings.totals.counts.themes = Math.max( --settings.totals.counts.themes, 0 );
[424] Fix | Delete
}
[425] Fix | Delete
[426] Fix | Delete
wp.updates.refreshCount( type );
[427] Fix | Delete
};
[428] Fix | Delete
[429] Fix | Delete
/**
[430] Fix | Delete
* Sends an Ajax request to the server to update a plugin.
[431] Fix | Delete
*
[432] Fix | Delete
* @since 4.2.0
[433] Fix | Delete
* @since 4.6.0 More accurately named `updatePlugin`.
[434] Fix | Delete
*
[435] Fix | Delete
* @param {Object} args Arguments.
[436] Fix | Delete
* @param {string} args.plugin Plugin basename.
[437] Fix | Delete
* @param {string} args.slug Plugin slug.
[438] Fix | Delete
* @param {updatePluginSuccess=} args.success Optional. Success callback. Default: wp.updates.updatePluginSuccess
[439] Fix | Delete
* @param {updatePluginError=} args.error Optional. Error callback. Default: wp.updates.updatePluginError
[440] Fix | Delete
* @return {$.promise} A jQuery promise that represents the request,
[441] Fix | Delete
* decorated with an abort() method.
[442] Fix | Delete
*/
[443] Fix | Delete
wp.updates.updatePlugin = function( args ) {
[444] Fix | Delete
var $updateRow, $card, $message, message,
[445] Fix | Delete
$adminBarUpdates = $( '#wp-admin-bar-updates' );
[446] Fix | Delete
[447] Fix | Delete
args = _.extend( {
[448] Fix | Delete
success: wp.updates.updatePluginSuccess,
[449] Fix | Delete
error: wp.updates.updatePluginError
[450] Fix | Delete
}, args );
[451] Fix | Delete
[452] Fix | Delete
if ( 'plugins' === pagenow || 'plugins-network' === pagenow ) {
[453] Fix | Delete
$updateRow = $( 'tr[data-plugin="' + args.plugin + '"]' );
[454] Fix | Delete
$message = $updateRow.find( '.update-message' ).removeClass( 'notice-error' ).addClass( 'updating-message notice-warning' ).find( 'p' );
[455] Fix | Delete
message = sprintf(
[456] Fix | Delete
/* translators: %s: Plugin name and version. */
[457] Fix | Delete
_x( 'Updating %s...', 'plugin' ),
[458] Fix | Delete
$updateRow.find( '.plugin-title strong' ).text()
[459] Fix | Delete
);
[460] Fix | Delete
} else if ( 'plugin-install' === pagenow || 'plugin-install-network' === pagenow ) {
[461] Fix | Delete
$card = $( '.plugin-card-' + args.slug );
[462] Fix | Delete
$message = $card.find( '.update-now' ).addClass( 'updating-message' );
[463] Fix | Delete
message = sprintf(
[464] Fix | Delete
/* translators: %s: Plugin name and version. */
[465] Fix | Delete
_x( 'Updating %s...', 'plugin' ),
[466] Fix | Delete
$message.data( 'name' )
[467] Fix | Delete
);
[468] Fix | Delete
[469] Fix | Delete
// Remove previous error messages, if any.
[470] Fix | Delete
$card.removeClass( 'plugin-card-update-failed' ).find( '.notice.notice-error' ).remove();
[471] Fix | Delete
}
[472] Fix | Delete
[473] Fix | Delete
$adminBarUpdates.addClass( 'spin' );
[474] Fix | Delete
[475] Fix | Delete
if ( $message.html() !== __( 'Updating...' ) ) {
[476] Fix | Delete
$message.data( 'originaltext', $message.html() );
[477] Fix | Delete
}
[478] Fix | Delete
[479] Fix | Delete
$message
[480] Fix | Delete
.attr( 'aria-label', message )
[481] Fix | Delete
.text( __( 'Updating...' ) );
[482] Fix | Delete
[483] Fix | Delete
$document.trigger( 'wp-plugin-updating', args );
[484] Fix | Delete
[485] Fix | Delete
return wp.updates.ajax( 'update-plugin', args );
[486] Fix | Delete
};
[487] Fix | Delete
[488] Fix | Delete
/**
[489] Fix | Delete
* Updates the UI appropriately after a successful plugin update.
[490] Fix | Delete
*
[491] Fix | Delete
* @since 4.2.0
[492] Fix | Delete
* @since 4.6.0 More accurately named `updatePluginSuccess`.
[493] Fix | Delete
* @since 5.5.0 Auto-update "time to next update" text cleared.
[494] Fix | Delete
*
[495] Fix | Delete
* @param {Object} response Response from the server.
[496] Fix | Delete
* @param {string} response.slug Slug of the plugin to be updated.
[497] Fix | Delete
* @param {string} response.plugin Basename of the plugin to be updated.
[498] Fix | Delete
* @param {string} response.pluginName Name of the plugin to be updated.
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function