Opened 9 years ago
Last modified 3 years ago
#39364 new enhancement
Introduce a trigger to handle a custom queue job and run them
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Awaiting Review | Priority: | normal |
| Severity: | normal | Version: | 4.7 |
| Component: | Upgrade/Install | Keywords: | has-patch dev-feedback 2nd-opinion |
| Focuses: | javascript, administration | Cc: |
Description
While I was creating a plugin which imports theme demos. I have to utilize the wp.updates for AJAX way to import and delete the demo packs but unfortunately there are no any trigger which I can utilize to update the queue job for demo by using its action and data in wp.updates.queueChecker. As a fix I have introduced a trigger in a patch file :)
Any procedure to the extend self-executing anynonmous function wp.updates.queueChecker below with only trigger $document.trigger( 'wp-updates-queue-job', job ); is much appreciated :)
( function( $, wp ) {
var $document = $( document );
wp = wp || {};
/**
* The WP Updates object.
*
* @type {object}
*/
wp.updates = wp.updates || {};
/**
* Sends an Ajax request to the server to delete a demo.
*
* @param {object} args
* @param {string} args.slug Demo Pack.
* @param {deleteDemoSuccess=} args.success Optional. Success callback. Default: wp.updates.deleteDemoSuccess
* @param {deleteDemoError=} args.error Optional. Error callback. Default: wp.updates.deleteDemoError
* @return {$.promise} A jQuery promise that represents the request,
* decorated with an abort() method.
*/
wp.updates.deleteDemo = function( args ) {
var $button = $( '.theme-actions .delete-demo' );
args = _.extend( {
success: wp.updates.deleteDemoSuccess,
error: wp.updates.deleteDemoError
}, args );
if ( $button && $button.html() !== wp.updates.l10n.deleting ) {
$button
.data( 'originaltext', $button.html() )
.text( wp.updates.l10n.deleting );
}
wp.a11y.speak( wp.updates.l10n.deleting, 'polite' );
// Remove previous error messages, if any.
$( '.theme-info .update-message' ).remove();
$document.trigger( 'wp-demo-deleting', args );
return wp.updates.ajax( 'delete-demo', args );
};
/**
* Updates the UI appropriately after a successful demo deletion.
*
* @typedef {object} deleteDemoSuccess
* @param {object} response Response from the server.
* @param {string} response.slug Slug of the demo that was deleted.
*/
wp.updates.deleteDemoSuccess = function( response ) {
wp.a11y.speak( wp.updates.l10n.deleted, 'polite' );
$document.trigger( 'wp-demo-delete-success', response );
};
/**
* Updates the UI appropriately after a failed demo deletion.
*
* @typedef {object} deleteDemoError
* @param {object} response Response from the server.
* @param {string} response.slug Slug of the demo to be deleted.
* @param {string} response.errorCode Error code for the error that occurred.
* @param {string} response.errorMessage The error that occurred.
*/
wp.updates.deleteDemoError = function( response ) {
var $button = $( '.theme-actions .delete-demo' ),
errorMessage = wp.updates.l10n.deleteFailed.replace( '%s', response.errorMessage ),
$message = wp.updates.adminNotice( {
className: 'update-message notice-error notice-alt',
message: errorMessage
} );
if ( wp.updates.maybeHandleCredentialError( response, 'delete-demo' ) ) {
return;
}
$( '.theme-info .theme-description' ).before( $message );
$button.html( $button.data( 'originaltext' ) );
wp.a11y.speak( errorMessage, 'assertive' );
$document.trigger( 'wp-demo-delete-error', response );
};
/**
* Pulls available jobs from the queue and runs them.
*/
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;
}
$document.trigger( 'wp-updates-queue-job', job );
};
})( jQuery, window.wp );
Attachments (1)
Change History (6)
#2
@
8 years ago
@swissspidy @dd32 Can you introduce a trigger for custom queue job by plugins :)
$document.trigger( 'wp-updates-queue-job', job );
Its been about 11 months (nearly a year) I have using code to resolve this issue :)
This ticket was mentioned in Slack in #core-upgrade-install by costdev. View the logs.
3 years ago
#4
@
3 years ago
I've pinged a Security team member to see if they have time to take a look at this one and potential implications.
Additional props: @afragen @pbiron
Introduce trigger to handle a custom queue job :)