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

Andrew Nacin wp at andrewnacin.com
Thu Jul 29 14:49:45 UTC 2010


On Thu, Jul 29, 2010 at 10:43 AM, Matt Jacob <matt at mattjacob.com> wrote:

> This is probably the most bizarre WP issue I've come across in a long time,
> so I apologize if it's difficult to make sense of what I'm talking about.
> I'll do my best to describe the problem clearly, though.
>
> I have a method that gets hooked into admin_init, like so:
>
>  add_action('admin_init', array($this, 'initialize_admin'));
>>
>
>  public function initialize_admin() {
>>    register_setting('my_group', 'my_name', array($this,
>> 'validate_options_page'));
>> }
>>
>
> Group and option names were changed to make the code shorter.
>
> I also have a widget that my plugin provides. When I drag that widget into
> an available widget area, I get a PHP fatal error about trying to use an
> object as an array. (I store my plugin's settings in an object and save it
> as a single option in the DB.)
>
> I've tracked the error down to inside my validate_options_page method. The
> question, then, is: why the heck is my validation callback firing when
> activating my widget?
>
> I'm thoroughly and legitimately stumped here. I'm hoping someone else has
> some good insights into this problem.
>

I think we'd have to see the code to know what's really going on, something
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.


More information about the wp-hackers mailing list