' + __( 'No plugins are currently available.' ) + ' |
' );
}
}
if ( $itemsCount.length && $currentView.length ) {
remainingCount = plugins[ $currentView.parent( 'li' ).attr('class') ].length;
$itemsCount.text(
sprintf(
/* translators: %s: The remaining number of plugins. */
_nx( '%s item', '%s items', remainingCount, 'plugin/plugins' ),
remainingCount
)
);
}
} );
wp.a11y.speak( _x( 'Deleted!', 'plugin' ) );
$document.trigger( 'wp-plugin-delete-success', response );
};
/**
* 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
} );
if ( response.plugin ) {
$plugin = $( 'tr.inactive[data-plugin="' + response.plugin + '"]' );
$pluginUpdateRow = $plugin.siblings( '[data-plugin="' + response.plugin + '"]' );
} else {
$plugin = $( 'tr.inactive[data-slug="' + response.slug + '"]' );
$pluginUpdateRow = $plugin.siblings( '[data-slug="' + response.slug + '"]' );
}
if ( ! wp.updates.isValidResponse( response, 'delete' ) ) {
return;
}
if ( wp.updates.maybeHandleCredentialError( response, 'delete-plugin' ) ) {
return;
}
// Add a plugin update row if it doesn't exist yet.
if ( ! $pluginUpdateRow.length ) {
$plugin.addClass( 'update' ).after(
pluginUpdateRow( {
slug: response.slug,
plugin: response.plugin || response.slug,
colspan: $( '#bulk-action-form' ).find( 'thead th:not(.hidden), thead td' ).length,
content: noticeContent
} )
);
} else {
// Remove previous error messages, if any.
$pluginUpdateRow.find( '.notice-error' ).remove();
$pluginUpdateRow.find( '.plugin-update' ).append( noticeContent );
}
$document.trigger( 'wp-plugin-delete-error', response );
};
/**
* Sends an Ajax request to the server to update a theme.
*
* @since 4.6.0
*
* @param {Object} args Arguments.
* @param {string} args.slug Theme stylesheet.
* @param {updateThemeSuccess=} args.success Optional. Success callback. Default: wp.updates.updateThemeSuccess
* @param {updateThemeError=} args.error Optional. Error callback. Default: wp.updates.updateThemeError
* @return {$.promise} A jQuery promise that represents the request,
* decorated with an abort() method.
*/
wp.updates.updateTheme = function( args ) {
var $notice;
args = _.extend( {
success: wp.updates.updateThemeSuccess,
error: wp.updates.updateThemeError
}, args );
if ( 'themes-network' === pagenow ) {
$notice = $( '[data-slug="' + args.slug + '"]' ).find( '.update-message' ).removeClass( 'notice-error' ).addClass( 'updating-message notice-warning' ).find( 'p' );
} else if ( 'customize' === pagenow ) {
// Update the theme details UI.
$notice = $( '[data-slug="' + args.slug + '"].notice' ).removeClass( 'notice-large' );
$notice.find( 'h3' ).remove();
// Add the top-level UI, and update both.
$notice = $notice.add( $( '#customize-control-installed_theme_' + args.slug ).find( '.update-message' ) );
$notice = $notice.addClass( 'updating-message' ).find( 'p' );
} else {
$notice = $( '#update-theme' ).closest( '.notice' ).removeClass( 'notice-large' );
$notice.find( 'h3' ).remove();
$notice = $notice.add( $( '[data-slug="' + args.slug + '"]' ).find( '.update-message' ) );
$notice = $notice.addClass( 'updating-message' ).find( 'p' );
}
if ( $notice.html() !== __( 'Updating...' ) ) {
$notice.data( 'originaltext', $notice.html() );
}
wp.a11y.speak( __( 'Updating... please wait.' ) );
$notice.text( __( 'Updating...' ) );
$document.trigger( 'wp-theme-updating', args );
return wp.updates.ajax( 'update-theme', args );
};
/**
* Updates the UI appropriately after a successful theme update.
*
* @since 4.6.0
* @since 5.5.0 Auto-update "time to next update" text cleared.
*
* @param {Object} response
* @param {string} response.slug Slug of the theme to be updated.
* @param {Object} response.theme Updated theme.
* @param {string} response.oldVersion Old version of the theme.
* @param {string} response.newVersion New version of the theme.
*/
wp.updates.updateThemeSuccess = function( response ) {
var isModalOpen = $( 'body.modal-open' ).length,
$theme = $( '[data-slug="' + response.slug + '"]' ),
updatedMessage = {
className: 'updated-message notice-success notice-alt',
message: _x( 'Updated!', 'theme' )
},
$notice, newText;
if ( 'customize' === pagenow ) {
$theme = $( '.updating-message' ).siblings( '.theme-name' );
if ( $theme.length ) {
// Update the version number in the row.
newText = $theme.html().replace( response.oldVersion, response.newVersion );
$theme.html( newText );
}
$notice = $( '.theme-info .notice' ).add( wp.customize.control( 'installed_theme_' + response.slug ).container.find( '.theme' ).find( '.update-message' ) );
} else if ( 'themes-network' === pagenow ) {
$notice = $theme.find( '.update-message' );
// 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' ) );
// Focus on Customize button after updating.
if ( isModalOpen ) {
$( '.load-customize:visible' ).trigger( 'focus' );
$( '.theme-info .theme-autoupdate' ).find( '.auto-update-time' ).empty();
} else {
$theme.find( '.load-customize' ).trigger( 'focus' );
}
}
wp.updates.addAdminNotice( _.extend( { selector: $notice }, updatedMessage ) );
wp.a11y.speak( __( 'Update completed successfully.' ) );
wp.updates.decrementCount( 'theme' );
$document.trigger( 'wp-theme-update-success', response );
// Show updated message after modal re-rendered.
if ( isModalOpen && 'customize' !== pagenow ) {
$( '.theme-info .theme-author' ).after( wp.updates.adminNotice( updatedMessage ) );
}
};
/**
* Updates the UI appropriately after a failed theme update.
*
* @since 4.6.0
*
* @param {Object} response Response from the server.
* @param {string} response.slug Slug of the theme to be updated.
* @param {string} response.errorCode Error code for the error that occurred.
* @param {string} response.errorMessage The error that occurred.
*/
wp.updates.updateThemeError = function( response ) {
var $theme = $( '[data-slug="' + response.slug + '"]' ),
errorMessage = sprintf(
/* translators: %s: Error string for a failed update. */
__( 'Update failed: %s' ),
response.errorMessage
),
$notice;
if ( ! wp.updates.isValidResponse( response, 'update' ) ) {
return;
}
if ( wp.updates.maybeHandleCredentialError( response, 'update-theme' ) ) {
return;
}
if ( 'customize' === pagenow ) {
$theme = wp.customize.control( 'installed_theme_' + response.slug ).container.find( '.theme' );
}
if ( 'themes-network' === pagenow ) {
$notice = $theme.find( '.update-message ' );
} else {
$notice = $( '.theme-info .notice' ).add( $theme.find( '.notice' ) );
$( 'body.modal-open' ).length ? $( '.load-customize:visible' ).trigger( 'focus' ) : $theme.find( '.load-customize' ).trigger( 'focus');
}
wp.updates.addAdminNotice( {
selector: $notice,
className: 'update-message notice-error notice-alt is-dismissible',
message: errorMessage
} );