[wp-hackers] Does a widget save hook exist or do I need to create a ticket in Trac?

Eric Mann eric at eam.me
Thu Nov 3 15:46:26 UTC 2011


If this widget is your own widget, you can add your own hook to the
`update()` method of the widget class.

Your other option is to hook into the 'update_option' action directly.

When you save a widget's options it does the following:

   1. Processing for the actual widget
   2. Calling apply_filters<http://phpxref.ftwr.co.uk/wordpress/_functions/apply_filters.html>('widget_update_callback',
   $instance <http://phpxref.ftwr.co.uk/wordpress/_variables/instance.html>,
   $new_instance<http://phpxref.ftwr.co.uk/wordpress/_variables/new_instance.html>,
   $old_instance<http://phpxref.ftwr.co.uk/wordpress/_variables/old_instance.html>,
   $this <http://phpxref.ftwr.co.uk/wordpress/_variables/this.html>);
   3. Calling $this<http://phpxref.ftwr.co.uk/wordpress/_variables/this.html>
   ->save_settings<http://phpxref.ftwr.co.uk/wordpress/_functions/save_settings.html>
   ($all_instances<http://phpxref.ftwr.co.uk/wordpress/_variables/all_instances.html>);
   To save the settings of all instances of that widget.
   4. save_settings() calls update_option() ... code below:

function save_settings
<http://phpxref.ftwr.co.uk/wordpress/_functions/save_settings.html>($settings
<http://phpxref.ftwr.co.uk/wordpress/_variables/settings.html>) {
$settings <http://phpxref.ftwr.co.uk/wordpress/_variables/settings.html>['_multiwidget']
= 1;  update_option
<http://phpxref.ftwr.co.uk/wordpress/_functions/update_option.html>(
$this <http://phpxref.ftwr.co.uk/wordpress/_variables/this.html>->option_name
<http://phpxref.ftwr.co.uk/wordpress/_variables/option_name.html>,
$settings <http://phpxref.ftwr.co.uk/wordpress/_variables/settings.html>
);
}

So you *should* be able to hook into the regular update hooks just fine ...

On Thu, Nov 3, 2011 at 7:45 AM, Bjorn Wijers <burobjorn at gmail.com> wrote:

> Hi,
>
> I'm looking for a hook to use just after a widget has saved it's options.
>
> For example:
> I have a widget W whose options I have changed in the Appearance->Widgets
> screen. I press save and after the save a hook H is being called. My code
> hooks into the hook and does its thing.
>
> Usage:
> Clearing a site transient which is set in site X and also being used in
> all the other sites of my WordPress Multisite installation. Basically it
> saves me from (ab)using switch_to_blog()
>
> I've used the 'widget_update_callback' which in fact is called before the
> update (is this a bug or feature?) as well as the 'widget_form_callback',
> which gets called repeatedly something I would like to prevent. Any ideas
> for a better hook to use?
>
> Afaik there is not (yet?) a hook directly after saving a widget's options.
> Or is there? If not shall I create a ticket for this?
>
> Thanks in advance,
>
> grtz
> BjornW
> ______________________________**_________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.**com <wp-hackers at lists.automattic.com>
> http://lists.automattic.com/**mailman/listinfo/wp-hackers<http://lists.automattic.com/mailman/listinfo/wp-hackers>
>


More information about the wp-hackers mailing list