Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

This solution, Update widget form after drag-and-drop, works correctly but I want to adapt this function to affect only a specific plugin and not every plugin. How could I do it?

share|improve this question
    
Please clarify your question. When you say "specific plugin," do you mean "one particular widget?" –  mrwweb May 14 '13 at 14:22
    
Yes, any instance of one particular widget, for example Twitter Widget Pro –  PoseLab May 14 '13 at 14:26
    
If this answers your question, please accept it with the checkmark next to the answer rather than up-voting. Then other people know that the question has been answered satisfactorily. –  mrwweb May 14 '13 at 17:07
add comment

1 Answer

up vote 2 down vote accepted

I ran into this problem with one of my plugins, and am deeply indebted to this article for pointing me in the right direction.

The key is that the third parameter you get in the callback includes the widget's basename (derived from its class). I used a slightly different AJAX function than the example you linked to, but here's what I came up with:

$(document).ajaxSuccess(function(e, xhr, settings) {

    // test to see if any instance of a particular widget is saved
    if(settings.data.search('action=save-widget') != -1 && settings.data.search('id_base={YOUR BASENAME GOES HERE}') != -1) {
        // do something
    }

    // test to see if any widget was added or re-ordered
    if(settings.data.search('action=widgets-order') != -1) {
        // do something
    }

}); 

A couple notes:

  1. Make sure to fill in "{YOUR BASENAME GOES HERE}" above.
  2. Note that you can't see which particular widget was added or re-ordered. That's not passed.
  3. If you're unsure of your basename, just add console.log(settings); to the first line of the function and look at it in a JS browser console. You'll see your basename buried in there.
share|improve this answer
    
This is what I was looking for and your plugin code "Feature A Page Widget" shows very well how to use it. Thank you very much –  PoseLab May 15 '13 at 13:49
    
Glad I could help! –  mrwweb May 15 '13 at 15:05
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.