[wp-hackers] Javascript callback upon Widget save

Mohammad Jangda batmoo at gmail.com
Thu Sep 9 20:26:52 UTC 2010

> Is there a Javascript callback that I can hook into when saving a widget in
> the admin screen?  Since the widget Save button reloads the contents of the
> widget panel, I'm losing some event handlers that I'd like to set back up.

You can hook into the jQuery's ajaxSuccess event (
http://api.jquery.com/ajaxSuccess/). It's not the nicest solution but it
works (I actually use the same approach to hook into post autosaves).

Below is a crude example that triggers anytime a "mywidget" instance is
added or saved. Just change the value of widget_id_base to the id of your
widget and you're set.

(If you want it nicely formatted, find it on gisthub:

jQuery(document).ajaxSuccess(function(e, xhr, settings) {
	var widget_id_base = 'mywidget';

	if(settings.data.search('action=save-widget') != -1 &&
settings.data.search('id_base=' + widget_id_base) != -1) {
		// do other stuff


More information about the wp-hackers mailing list