[wp-hackers] admin-ajax.php widget settings form issue
David Morris
dvmorris at gmail.com
Tue Aug 3 20:32:02 UTC 2010
I'm not sure this is technically a bug or not, but I had a huge issue with
some custom widgets causing all widget settings dialogs to disappear today.
Basically, I wrote three custom widgets, and any time two of them were
activated at the same time, and I dropped any widget onto a sidebar, the
settings form would show up and then immediately disappear. If I deactivated
one of the two custom widgets, the widget settings dialogs would work just
fine.
After a bunch of digging, I found some code in widgets.dev.js, in the save()
function, where it does a $.post request to admin-ajax.php that was causing
the div contents to be cleared out. The callback function for the post
request to admin-ajax.php was receiving some extra whitespace in the
response, and it caused the widget settings form to get cleared out:
$.post( ajaxurl, data, function(r){
...
$('.ajax-feedback').css('visibility', 'hidden');
if ( r && r.length > 2 ) {
$('div.widget-content', widget).html(r);
wpWidgets.appendTitle(widget);
wpWidgets.fixLabels(widget);
}
...
});
It turned out that I just had a few line breaks after my closing php tags in
each of my three custom widgets, and removing them fixed the issue. That
explained why it worked fine when only one of the widgets was activated.
Each widget didn't have enough extra line breaks to break that javascript
callback function, but two of them together did.
It seems that rather than depending on the length of the admin-ajax.php
response, it ought to depend on some kind of message or code. Just my two
cents...
Thanks,
Dave Morris
More information about the wp-hackers
mailing list