• Does anyone know if it’s possible to access a widget instance settings from a different function than widget(), update() or form() ?

    For example, in the widget below I want to get the $args and $instance variables from within my_custom_function().

    class test extends WP_Widget{
      ...
      function test(){
        ...
      }
    
      function my_custom_function(){
        // how to access $args and $instance here?
      }
    
      function widget($args, $instance) {
        ...
      }
    
      function update($new_instance, $old_instance){
        ...
        return $instance;
       }
    
      function form($instance){
        ...
      }
    }

    ps: can a mod move this to the wp-advanced forum?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter digitalnature

    (@digitalnature)

    ok, I found out how to get the widget options, using get_option():
    get_option($this->option_name)

    I get a array with all instances options.
    The problem is that I don’t know the current instance ID so I can’t retrieve only the options for the instance I want.

    Is there any way I can get the instance ID in my custom function?

    Thread Starter digitalnature

    (@digitalnature)

    ok, i managed to resolve this.
    it seems that $this gets the ID variable set after the widget are initialized, so I hooked a action with my function to “widgets_init”…

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Getting widget instance settings’ is closed to new replies.