[wp-hackers] register_setting firing callback when widget is added?!

Otto otto at ottodestruct.com
Thu Jul 29 15:35:29 UTC 2010


On Thu, Jul 29, 2010 at 9:59 AM, Matt Jacob <matt at mattjacob.com> wrote:
> On 7/29/10 7:49 AM, Andrew Nacin wrote:
>>
>> you might be missing.. But it may help to understand how
>> register_setting()'s sanitization callbacks work. It simply hooks the
>> callback to the sanitize_option_$option filter, thus if you are calling
>> update_option( 'my_name', ... ) on your own, you're also triggering your
>> callback.
>
> Actually, that is helpful to know. My callback for
> wp_register_widget_control does an update_option when the widget is
> submitted, so that explains it. I can check whether the argument to the
> validation callback is an array or an object and work around the problem
> that way.
>
> But now I'm wondering why the widget is submitted immediately after adding
> it. That seems... unnecessary?
>

Adding a widget triggers an AJAX to set the widget up in the tables
and to set up the default options. So a submit has to occur to do
these things.


More information about the wp-hackers mailing list