IP : 3.139.104.122Hostname : server86.web-hosting.comKernel : Linux server86.web-hosting.com 4.18.0-513.18.1.lve.el8.x86_64 #1 SMP Thu Feb 22 12:55:50 UTC 2024 x86_64Disable Function : None :) OS : Linux
PATH:
/
home/
servlmvm/
public_html/
wp-admin/
js/
updates.js/
/
/** * Functions for ajaxified updates, deletions and installs inside the WordPress admin. * * @version 4.2.0 * @output wp-admin/js/updates.js */
/* global pagenow, _wpThemeSettings */
/** * @param {jQuery} $ jQuery object. * @param {object} wp WP object. * @param {object} settings WP Updates settings. * @param {string} settings.ajax_nonce Ajax nonce. * @param {object=} settings.plugins Base names of plugins in their different states. * @param {Array} settings.plugins.all Base names of all plugins. * @param {Array} settings.plugins.active Base names of active plugins. * @param {Array} settings.plugins.inactive Base names of inactive plugins. * @param {Array} settings.plugins.upgrade Base names of plugins with updates available. * @param {Array} settings.plugins.recently_activated Base names of recently activated plugins. * @param {Array} settings.plugins['auto-update-enabled'] Base names of plugins set to auto-update. * @param {Array} settings.plugins['auto-update-disabled'] Base names of plugins set to not auto-update. * @param {object=} settings.themes Slugs of themes in their different states. * @param {Array} settings.themes.all Slugs of all themes. * @param {Array} settings.themes.upgrade Slugs of themes with updates available. * @param {Arrat} settings.themes.disabled Slugs of disabled themes. * @param {Array} settings.themes['auto-update-enabled'] Slugs of themes set to auto-update. * @param {Array} settings.themes['auto-update-disabled'] Slugs of themes set to not auto-update. * @param {object=} settings.totals Combined information for available update counts. * @param {number} settings.totals.count Holds the amount of available updates. */ (function( $, wp, settings ) { var $document = $( document ), __ = wp.i18n.__, _x = wp.i18n._x, _n = wp.i18n._n, _nx = wp.i18n._nx, sprintf = wp.i18n.sprintf;
/** * Minimum number of characters before an ajax search is fired. * * @since 6.7.0 * * @type {number} */ wp.updates.searchMinCharacters = 2;
/** * Whether filesystem credentials need to be requested from the user. * * @since 4.2.0 * * @type {bool} */ wp.updates.shouldRequestFilesystemCredentials = false;
/** * Filesystem credentials to be packaged along with the request. * * @since 4.2.0 * @since 4.6.0 Added `available` property to indicate whether credentials have been provided. * * @type {Object} * @property {Object} filesystemCredentials.ftp Holds FTP credentials. * @property {string} filesystemCredentials.ftp.host FTP host. Default empty string. * @property {string} filesystemCredentials.ftp.username FTP user name. Default empty string. * @property {string} filesystemCredentials.ftp.password FTP password. Default empty string. * @property {string} filesystemCredentials.ftp.connectionType Type of FTP connection. 'ssh', 'ftp', or 'ftps'. * Default empty string. * @property {Object} filesystemCredentials.ssh Holds SSH credentials. * @property {string} filesystemCredentials.ssh.publicKey The public key. Default empty string. * @property {string} filesystemCredentials.ssh.privateKey The private key. Default empty string. * @property {string} filesystemCredentials.fsNonce Filesystem credentials form nonce. * @property {bool} filesystemCredentials.available Whether filesystem credentials have been provided. * Default 'false'. */ wp.updates.filesystemCredentials = { ftp: { host: '', username: '', password: '', connectionType: '' }, ssh: { publicKey: '', privateKey: '' }, fsNonce: '', available: false };
/** * Whether we're waiting for an Ajax request to complete. * * @since 4.2.0 * @since 4.6.0 More accurately named `ajaxLocked`. * * @type {bool} */ wp.updates.ajaxLocked = false;
/** * Update queue. * * If the user tries to update a plugin while an update is * already happening, it can be placed in this queue to perform later. * * @since 4.2.0 * @since 4.6.0 More accurately named `queue`. * * @type {Array.object} */ wp.updates.queue = [];
/** * Holds a jQuery reference to return focus to when exiting the request credentials modal. * * @since 4.2.0 * * @type {jQuery} */ wp.updates.$elToReturnFocusToFromCredentialsModal = undefined;
/** * Adds or updates an admin notice. * * @since 4.6.0 * * @param {Object} data * @param {*=} data.selector Optional. Selector of an element to be replaced with the admin notice. * @param {string=} data.id Optional. Unique id that will be used as the notice's id attribute. * @param {string=} data.className Optional. Class names that will be used in the admin notice. * @param {string=} data.message Optional. The message displayed in the notice. * @param {number=} data.successes Optional. The amount of successful operations. * @param {number=} data.errors Optional. The amount of failed operations. * @param {Array=} data.errorMessages Optional. Error messages of failed operations. * */ wp.updates.addAdminNotice = function( data ) { var $notice = $( data.selector ), $headerEnd = $( '.wp-header-end' ), $adminNotice;
delete data.selector; $adminNotice = wp.updates.adminNotice( data );
// Check if this admin notice already exists. if ( ! $notice.length ) { $notice = $( '#' + data.id ); }
/** * Handles Ajax requests to WordPress. * * @since 4.6.0 * * @param {string} action The type of Ajax request ('update-plugin', 'install-theme', etc). * @param {Object} data Data that needs to be passed to the ajax callback. * @return {$.promise} A jQuery promise that represents the request, * decorated with an abort() method. */ wp.updates.ajax = function( action, data ) { var options = {};
if ( wp.updates.ajaxLocked ) { wp.updates.queue.push( { action: action, data: data } );
// Return a Deferred object so callbacks can always be registered. return $.Deferred(); }
$adminBarUpdates.find( '.ab-label' ).text( settings.totals.counts.total ); $adminBarUpdates.find( '.updates-available-text' ).text( sprintf( /* translators: %s: Total number of updates available. */ _n( '%s update available', '%s updates available', settings.totals.counts.total ), settings.totals.counts.total ) );
// Remove the update count from the toolbar if it's zero. if ( 0 === settings.totals.counts.total ) { $adminBarUpdates.find( '.ab-label' ).parents( 'li' ).remove(); }
// Update the "Updates" menu item. $dashboardNavMenuUpdateCount.each( function( index, element ) { element.className = element.className.replace( /count-\d+/, 'count-' + settings.totals.counts.total ); } ); if ( settings.totals.counts.total > 0 ) { $dashboardNavMenuUpdateCount.find( '.update-count' ).text( settings.totals.counts.total ); } else { $dashboardNavMenuUpdateCount.remove(); }
// Update the "Plugins" menu item. $pluginsNavMenuUpdateCount.each( function( index, element ) { element.className = element.className.replace( /count-\d+/, 'count-' + settings.totals.counts.plugins ); } ); if ( settings.totals.counts.total > 0 ) { $pluginsNavMenuUpdateCount.find( '.plugin-count' ).text( settings.totals.counts.plugins ); } else { $pluginsNavMenuUpdateCount.remove(); }
// Update the "Appearance" menu item. $appearanceNavMenuUpdateCount.each( function( index, element ) { element.className = element.className.replace( /count-\d+/, 'count-' + settings.totals.counts.themes ); } ); if ( settings.totals.counts.total > 0 ) { $appearanceNavMenuUpdateCount.find( '.theme-count' ).text( settings.totals.counts.themes ); } else { $appearanceNavMenuUpdateCount.remove(); }
/** * Sends a message from a modal to the main screen to update buttons in plugin cards. * * @since 6.5.0 * * @param {Object} data An object of data to use for the button. * @param {string} data.slug The plugin's slug. * @param {string} data.text The text to use for the button. * @param {string} data.ariaLabel The value for the button's aria-label attribute. An empty string removes the attribute. * @param {string=} data.status Optional. An identifier for the status. * @param {string=} data.removeClasses Optional. A space-separated list of classes to remove from the button. * @param {string=} data.addClasses Optional. A space-separated list of classes to add to the button. * @param {string=} data.href Optional. The button's URL. * @param {string=} data.pluginName Optional. The plugin's name. * @param {string=} data.plugin Optional. The plugin file, relative to the plugins directory. */ wp.updates.setCardButtonStatus = function( data ) { var target = window.parent === window ? null : window.parent;
/** * Decrements the update counts throughout the various menus. * * This includes the toolbar, the "Updates" menu item and the menu items * for plugins and themes. * * @since 3.9.0 * * @param {string} type The type of item that was updated or deleted. * Can be 'plugin', 'theme'. */ wp.updates.decrementCount = function( type ) { settings.totals.counts.total = Math.max( --settings.totals.counts.total, 0 );
if ( 'plugin' === type ) { settings.totals.counts.plugins = Math.max( --settings.totals.counts.plugins, 0 ); } else if ( 'theme' === type ) { settings.totals.counts.themes = Math.max( --settings.totals.counts.themes, 0 ); }
wp.updates.refreshCount( type ); };
/** * Sends an Ajax request to the server to update a plugin. * * @since 4.2.0 * @since 4.6.0 More accurately named `updatePlugin`. * * @param {Object} args Arguments. * @param {string} args.plugin Plugin basename. * @param {string} args.slug Plugin slug. * @param {updatePluginSuccess=} args.success Optional. Success callback. Default: wp.updates.updatePluginSuccess * @param {updatePluginError=} args.error Optional. Error callback. Default: wp.updates.updatePluginError * @return {$.promise} A jQuery promise that represents the request, * decorated with an abort() method. */ wp.updates.updatePlugin = function( args ) { var $updateRow, $card, $message, message, $adminBarUpdates = $( '#wp-admin-bar-updates' ), buttonText = __( 'Updating...' ), isPluginInstall = 'plugin-install' === pagenow || 'plugin-install-network' === pagenow;
/** * Updates the UI appropriately after a successful plugin update. * * @since 4.2.0 * @since 4.6.0 More accurately named `updatePluginSuccess`. * @since 5.5.0 Auto-update "time to next update" text cleared. * * @param {Object} response Response from the server. * @param {string} response.slug Slug of the plugin to be updated. * @param {string} response.plugin Basename of the plugin to be updated. * @param {string} response.pluginName Name of the plugin to be updated. * @param {string} response.oldVersion Old version of the plugin. * @param {string} response.newVersion New version of the plugin. */ wp.updates.updatePluginSuccess = function( response ) { var $pluginRow, $updateMessage, newText, $adminBarUpdates = $( '#wp-admin-bar-updates' ), buttonText = _x( 'Updated!', 'plugin' ), ariaLabel = sprintf( /* translators: %s: Plugin name and version. */ _x( '%s updated!', 'plugin' ), response.pluginName );
// Update the version number in the row. newText = $pluginRow.find( '.plugin-version-author-uri' ).html().replace( response.oldVersion, response.newVersion ); $pluginRow.find( '.plugin-version-author-uri' ).html( newText );
/** * Updates the UI appropriately after a failed plugin update. * * @since 4.2.0 * @since 4.6.0 More accurately named `updatePluginError`. * * @param {Object} response Response from the server. * @param {string} response.slug Slug of the plugin to be updated. * @param {string} response.plugin Basename of the plugin to be updated. * @param {string=} response.pluginName Optional. Name of the plugin to be updated. * @param {string} response.errorCode Error code for the error that occurred. * @param {string} response.errorMessage The error that occurred. */ wp.updates.updatePluginError = function( response ) { var $pluginRow, $card, $message, errorMessage, buttonText, ariaLabel, $adminBarUpdates = $( '#wp-admin-bar-updates' );
// Use same delay as the total duration of the notice fadeTo + slideUp animation. setTimeout( function() { $card .removeClass( 'plugin-card-update-failed' ) .find( '.column-name a' ).trigger( 'focus' );
// Use same delay as the total duration of the notice fadeTo + slideUp animation. setTimeout( function() { $card .removeClass( 'plugin-card-update-failed' ) .find( '.column-name a' ).trigger( 'focus' ); }, 200 ); } );
/** * Updates the UI appropriately after a failed importer install. * * @since 4.6.0 * * @param {Object} response Response from the server. * @param {string} response.slug Slug of the plugin to be installed. * @param {string=} response.pluginName Optional. Name of the plugin to be installed. * @param {string} response.errorCode Error code for the error that occurred. * @param {string} response.errorMessage The error that occurred. */ wp.updates.installImporterError = function( response ) { var errorMessage = sprintf( /* translators: %s: Error string for a failed installation. */ __( 'Installation failed: %s' ), response.errorMessage ), $installLink = $( '[data-slug="' + response.slug + '"]' ), pluginName = $installLink.data( 'name' );
/** * Sends an Ajax request to the server to delete a plugin. * * @since 4.6.0 * * @param {Object} args Arguments. * @param {string} args.plugin Basename of the plugin to be deleted. * @param {string} args.slug Slug of the plugin to be deleted. * @param {deletePluginSuccess=} args.success Optional. Success callback. Default: wp.updates.deletePluginSuccess * @param {deletePluginError=} args.error Optional. Error callback. Default: wp.updates.deletePluginError * @return {$.promise} A jQuery promise that represents the request, * decorated with an abort() method. */ wp.updates.deletePlugin = function( args ) { var $link = $( '[data-plugin="' + args.plugin + '"]' ).find( '.row-actions a.delete' );
/** * Updates the UI appropriately after a successful plugin deletion. * * @since 4.6.0 * * @param {Object} response Response from the server. * @param {string} response.slug Slug of the plugin that was deleted. * @param {string} response.plugin Base name of the plugin that was deleted. * @param {string} response.pluginName Name of the plugin that was deleted. */ wp.updates.deletePluginSuccess = function( response ) {
// Removes the plugin and updates rows. $( '[data-plugin="' + response.plugin + '"]' ).css( { backgroundColor: '#faafaa' } ).fadeOut( 350, function() { var $form = $( '#bulk-action-form' ), $views = $( '.subsubsub' ), $pluginRow = $( this ), $currentView = $views.find( '[aria-current="page"]' ), $itemsCount = $( '.displaying-num' ), columnCount = $form.find( 'thead th:not(.hidden), thead td' ).length, pluginDeletedRow = wp.template( 'item-deleted-row' ), /** * Plugins Base names of plugins in their different states. * * @type {Object} */ plugins = settings.plugins, remainingCount;
// Add a success message after deleting a plugin. if ( ! $pluginRow.hasClass( 'plugin-update-tr' ) ) { $pluginRow.after( pluginDeletedRow( { slug: response.slug, plugin: response.plugin, colspan: columnCount, name: response.pluginName } ) ); }
/** * Updates the UI appropriately after a failed plugin deletion. * * @since 4.6.0 * * @param {Object} response Response from the server. * @param {string} response.slug Slug of the plugin to be deleted. * @param {string} response.plugin Base name of the plugin to be deleted * @param {string=} response.pluginName Optional. Name of the plugin to be deleted. * @param {string} response.errorCode Error code for the error that occurred. * @param {string} response.errorMessage The error that occurred. */ wp.updates.deletePluginError = function( response ) { var $plugin, $pluginUpdateRow, pluginUpdateRow = wp.template( 'item-update-row' ), noticeContent = wp.updates.adminNotice( { className: 'update-message notice-error notice-alt', message: response.errorMessage } );
// Update the version number in the row. newText = $theme.find( '.theme-version-author-uri' ).html().replace( response.oldVersion, response.newVersion ); $theme.find( '.theme-version-author-uri' ).html( newText );
// Clear the "time to next auto-update" text. $theme.find( '.auto-update-time' ).empty(); } else { $notice = $( '.theme-info .notice' ).add( $theme.find( '.update-message' ) );
/** * Updates the UI appropriately after a successful theme install. * * @since 4.6.0 * * @param {Object} response Response from the server. * @param {string} response.slug Slug of the theme to be installed. * @param {string} response.customizeUrl URL to the Customizer for the just installed theme. * @param {string} response.activateUrl URL to activate the just installed theme. */ wp.updates.installThemeSuccess = function( response ) { var $card = $( '.wp-full-overlay-header, [data-slug=' + response.slug + ']' ), $message;
/** * Adds the appropriate callback based on the type of action and the current page. * * @since 4.6.0 * @private * * @param {Object} data Ajax payload. * @param {string} action The type of request to perform. * @return {Object} The Ajax payload with the appropriate callbacks. */ wp.updates._addCallbacks = function( data, action ) { if ( 'import' === pagenow && 'install-plugin' === action ) { data.success = wp.updates.installImporterSuccess; data.error = wp.updates.installImporterError; }
return data; };
/** * Pulls available jobs from the queue and runs them. * * @since 4.2.0 * @since 4.6.0 Can handle multiple job types. */ wp.updates.queueChecker = function() { var job;
if ( wp.updates.ajaxLocked || ! wp.updates.queue.length ) { return; }
job = wp.updates.queue.shift();
// Handle a queue job. switch ( job.action ) { case 'install-plugin': wp.updates.installPlugin( job.data ); break;
case 'update-plugin': wp.updates.updatePlugin( job.data ); break;
case 'delete-plugin': wp.updates.deletePlugin( job.data ); break;
case 'install-theme': wp.updates.installTheme( job.data ); break;
case 'update-theme': wp.updates.updateTheme( job.data ); break;
case 'delete-theme': wp.updates.deleteTheme( job.data ); break;
default: break; } };
/** * Requests the users filesystem credentials if they aren't already known. * * @since 4.2.0 * * @param {Event=} event Optional. Event interface. */ wp.updates.requestFilesystemCredentials = function( event ) { if ( false === wp.updates.filesystemCredentials.available ) { /* * After exiting the credentials request modal, * return the focus to the element triggering the request. */ if ( event && ! wp.updates.$elToReturnFocusToFromCredentialsModal ) { wp.updates.$elToReturnFocusToFromCredentialsModal = $( event.target ); }
/** * Requests the users filesystem credentials if needed and there is no lock. * * @since 4.6.0 * * @param {Event=} event Optional. Event interface. */ wp.updates.maybeRequestFilesystemCredentials = function( event ) { if ( wp.updates.shouldRequestFilesystemCredentials && ! wp.updates.ajaxLocked ) { wp.updates.requestFilesystemCredentials( event ); } };
/** * Keydown handler for the request for credentials modal. * * Closes the modal when the escape key is pressed and * constrains keyboard navigation to inside the modal. * * @since 4.2.0 * * @param {Event} event Event interface. */ wp.updates.keydown = function( event ) { if ( 27 === event.keyCode ) { wp.updates.requestForCredentialsModalCancel(); } else if ( 9 === event.keyCode ) {
// #upgrade button must always be the last focus-able element in the dialog. if ( 'upgrade' === event.target.id && ! event.shiftKey ) { $( '#hostname' ).trigger( 'focus' );
if ( wp.updates.$elToReturnFocusToFromCredentialsModal ) { wp.updates.$elToReturnFocusToFromCredentialsModal.trigger( 'focus' ); } };
/** * Takes care of the steps that need to happen when the modal is canceled out. * * @since 4.2.0 * @since 4.6.0 Triggers an event for callbacks to listen to and add their actions. */ wp.updates.requestForCredentialsModalCancel = function() {
// Not ajaxLocked and no queue means we already have cleared things up. if ( ! wp.updates.ajaxLocked && ! wp.updates.queue.length ) { return; }
/** * Handles credential errors and runs events that need to happen in that case. * * @since 4.2.0 * * @param {Object} response Ajax response. * @param {string} action The type of request to perform. */ wp.updates.credentialError = function( response, action ) {
/** * Handles credentials errors if it could not connect to the filesystem. * * @since 4.6.0 * * @param {Object} response Response from the server. * @param {string} response.errorCode Error code for the error that occurred. * @param {string} response.errorMessage The error that occurred. * @param {string} action The type of request to perform. * @return {boolean} Whether there is an error that needs to be handled or not. */ wp.updates.maybeHandleCredentialError = function( response, action ) { if ( wp.updates.shouldRequestFilesystemCredentials && response.errorCode && 'unable_to_connect_to_filesystem' === response.errorCode ) { wp.updates.credentialError( response, action ); return true; }
return false; };
/** * Validates an Ajax response to ensure it's a proper object. * * If the response deems to be invalid, an admin notice is being displayed. * * @param {(Object|string)} response Response from the server. * @param {function=} response.always Optional. Callback for when the Deferred is resolved or rejected. * @param {string=} response.statusText Optional. Status message corresponding to the status code. * @param {string=} response.responseText Optional. Request response as text. * @param {string} action Type of action the response is referring to. Can be 'delete', * 'update' or 'install'. */ wp.updates.isValidResponse = function( response, action ) { var error = __( 'An error occurred during the update process. Please try again.' ), errorMessage;
// Make sure the response is a valid data object and not a Promise object. if ( _.isObject( response ) && ! _.isFunction( response.always ) ) { return true; }
if ( _.isString( response ) && '-1' === response ) { error = __( 'An error has occurred. Please reload the page and try again.' ); } else if ( _.isString( response ) ) { error = response; } else if ( 'undefined' !== typeof response.readyState && 0 === response.readyState ) { error = __( 'Connection lost or the server is busy. Please try again later.' ); } else if ( _.isString( response.responseText ) && '' !== response.responseText ) { error = response.responseText; } else if ( _.isString( response.statusText ) ) { error = response.statusText; }
switch ( action ) { case 'update': /* translators: %s: Error string for a failed update. */ errorMessage = __( 'Update failed: %s' ); break;
case 'install': /* translators: %s: Error string for a failed installation. */ errorMessage = __( 'Installation failed: %s' ); break;
case 'check-dependencies': /* translators: %s: Error string for a failed dependencies check. */ errorMessage = __( 'Dependencies check failed: %s' ); break;
case 'activate': /* translators: %s: Error string for a failed activation. */ errorMessage = __( 'Activation failed: %s' ); break;
case 'delete': /* translators: %s: Error string for a failed deletion. */ errorMessage = __( 'Deletion failed: %s' ); break; }
// Messages are escaped, remove HTML tags to make them more readable. error = error.replace( /<[\/a-z][^<>]*>/gi, '' ); errorMessage = errorMessage.replace( '%s', error );
/** * Potentially adds an AYS to a user attempting to leave the page. * * If an update is on-going and a user attempts to leave the page, * opens an "Are you sure?" alert. * * @since 4.2.0 */ wp.updates.beforeunload = function() { if ( wp.updates.ajaxLocked ) { return __( 'Updates may not complete if you navigate away from this page.' ); } };
if ( settings.totals ) { wp.updates.refreshCount(); }
/* * Whether a user needs to submit filesystem credentials. * * This is based on whether the form was output on the page server-side. * * @see {wp_print_request_filesystem_credentials_modal() in PHP} */ wp.updates.shouldRequestFilesystemCredentials = $filesystemModal.length > 0;
/** * Closes the request credentials modal when clicking the 'Cancel' button or outside of the modal. * * @since 4.2.0 */ $filesystemModal.on( 'click', '[data-js-action="close"], .notification-dialog-background', wp.updates.requestForCredentialsModalCancel );
// Return the user to the input box of the plugin's table row after closing the modal. wp.updates.$elToReturnFocusToFromCredentialsModal = $pluginRow.find( '.check-column input' ); wp.updates.updatePlugin( { plugin: $pluginRow.data( 'plugin' ), slug: $pluginRow.data( 'slug' ) } ); } );
// Return the user to the input box of the theme's table row after closing the modal. wp.updates.$elToReturnFocusToFromCredentialsModal = $themeRow.find( '.check-column input' ); wp.updates.updateTheme( { slug: $themeRow.data( 'slug' ) } ); } );
// Determine which type of item we're dealing with. switch ( pagenow ) { case 'plugins': case 'plugins-network': type = 'plugin'; break;
case 'themes-network': type = 'theme'; break;
default: return; }
// Bail if there were no items selected. if ( ! itemsSelected.length ) { bulkAction = false; }
// Determine the type of request we're dealing with. switch ( bulkAction ) { case 'update-selected': action = bulkAction.replace( 'selected', type ); break;
case 'delete-selected': var confirmMessage = 'plugin' === type ? __( 'Are you sure you want to delete the selected plugins and their data?' ) : __( 'Caution: These themes may be active on other sites in the network. Are you sure you want to proceed?' );
$document.trigger( 'wp-' + type + '-bulk-' + bulkAction, itemsSelected );
// Find all the checkboxes which have been checked. itemsSelected.each( function( index, element ) { var $checkbox = $( element ), $itemRow = $checkbox.parents( 'tr' );
// Only add update-able items to the update queue. if ( 'update-selected' === bulkAction && ( ! $itemRow.hasClass( 'update' ) || $itemRow.find( 'notice-error' ).length ) ) {
// Un-check the box. $checkbox.prop( 'checked', false ); return; }
// Don't add items to the update queue again, even if the user clicks the update button several times. if ( 'update-selected' === bulkAction && $itemRow.hasClass( 'is-enqueued' ) ) { return; }
$itemRow.addClass( 'is-enqueued' );
// Add it to the queue. wp.updates.queue.push( { action: action, data: { plugin: $itemRow.data( 'plugin' ), slug: $itemRow.data( 'slug' ) } } ); } );
// Display bulk notification for updates of any kind. $document.on( 'wp-plugin-update-success wp-plugin-update-error wp-theme-update-success wp-theme-update-error', function( event, response ) { var $itemRow = $( '[data-slug="' + response.slug + '"]' ), $bulkActionNotice, itemName;
$bulkActionNotice = $( '#bulk-action-notice' ).on( 'click', 'button', function() { // $( this ) is the clicked button, no need to get it again. $( this ) .toggleClass( 'bulk-action-errors-collapsed' ) .attr( 'aria-expanded', ! $( this ).hasClass( 'bulk-action-errors-collapsed' ) ); // Show the errors list. $bulkActionNotice.find( '.bulk-action-errors' ).toggleClass( 'hidden' ); } );
// Set the autocomplete attribute, turning off autocomplete 1 character before ajax search kicks in. if ( wp.updates.shouldSearch( searchStringLength ) ) { $pluginInstallSearch.attr( 'autocomplete', 'off' ); } else { $pluginInstallSearch.attr( 'autocomplete', 'on' ); return; }
// Clear on escape. if ( 'keyup' === event.type && 27 === event.which ) { event.target.value = ''; }
if ( 0 === response.count ) { wp.a11y.speak( __( 'You do not appear to have any plugins available at this time.' ) ); } else { wp.a11y.speak( sprintf( /* translators: %s: Number of plugins. */ __( 'Number of plugins found: %d' ), response.count ) ); } } ); }, 1000 ) );
if ( $pluginSearch.length ) { $pluginSearch.attr( 'aria-describedby', 'live-search-desc' );
}
/** * Handles changes to the plugin search box on the Installed Plugins screen, * searching the plugin list dynamically. * * @since 4.6.0 */ $pluginSearch.on( 'keyup input', _.debounce( function( event ) { var data = { _ajax_nonce: wp.updates.ajaxNonce, s: encodeURIComponent( event.target.value ), pagenow: pagenow, plugin_status: 'all' }, queryArgs, searchStringLength = $pluginSearch.val().length;
// Set the autocomplete attribute, turning off autocomplete 1 character before ajax search kicks in. if ( wp.updates.shouldSearch( searchStringLength ) ) { $pluginSearch.attr( 'autocomplete', 'off' ); } else { $pluginSearch.attr( 'autocomplete', 'on' ); return; }
// Clear on escape. if ( 'keyup' === event.type && 27 === event.which ) { event.target.value = ''; }
if ( 'undefined' === typeof message.action ) { return; }
switch ( message.action ) {
// Called from `wp-admin/includes/class-wp-upgrader-skins.php`. case 'decrementUpdateCount': /** @property {string} message.upgradeType */ wp.updates.decrementCount( message.upgradeType ); break;
case 'install-plugin': case 'update-plugin': if ( 'undefined' === typeof message.data || 'undefined' === typeof message.data.slug ) { return; }
/** * Adds a callback to display a warning before leaving the page. * * @since 4.2.0 */ $( window ).on( 'beforeunload', wp.updates.beforeunload );
/** * Prevents the page form scrolling when activating auto-updates with the Spacebar key. * * @since 5.5.0 */ $document.on( 'keydown', '.column-auto-updates .toggle-auto-update, .theme-overlay .toggle-auto-update', function( event ) { if ( 32 === event.which ) { event.preventDefault(); } } );
/** * Click and keyup handler for enabling and disabling plugin and theme auto-updates. * * These controls can be either links or buttons. When JavaScript is enabled, * we want them to behave like buttons. An ARIA role `button` is added via * the JavaScript that targets elements with the CSS class `aria-button-if-js`. * * @since 5.5.0 */ $document.on( 'click keyup', '.column-auto-updates .toggle-auto-update, .theme-overlay .toggle-auto-update', function( event ) { var data, asset, type, $parent, $toggler = $( this ), action = $toggler.attr( 'data-wp-action' ), $label = $toggler.find( '.label' );
$.post( window.ajaxurl, data ) .done( function( response ) { var $enabled, $disabled, enabledNumber, disabledNumber, errorMessage, href = $toggler.attr( 'href' );
if ( ! response.success ) { // if WP returns 0 for response (which can happen in a few cases), // output the general error message since we won't have response.data.error. if ( response.data && response.data.error ) { errorMessage = response.data.error; } else { errorMessage = __( 'The request could not be completed.' ); }
if ( 'enable' === action ) { // The toggler control can be either a link or a button. if ( $toggler[ 0 ].hasAttribute( 'href' ) ) { href = href.replace( 'action=enable-auto-update', 'action=disable-auto-update' ); $toggler.attr( 'href', href ); } $toggler.attr( 'data-wp-action', 'disable' );
$label.text( __( 'Disable auto-updates' ) ); $parent.find( '.auto-update-time' ).removeClass( 'hidden' ); wp.a11y.speak( __( 'Auto-updates enabled' ) ); } else { // The toggler control can be either a link or a button. if ( $toggler[ 0 ].hasAttribute( 'href' ) ) { href = href.replace( 'action=disable-auto-update', 'action=enable-auto-update' ); $toggler.attr( 'href', href ); } $toggler.attr( 'data-wp-action', 'enable' );