WordPress.org

Ready to get started?Download WordPress

Forums

Getting widget instance settings (3 posts)

  1. digitalnature
    Member
    Posted 3 years ago #

    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?

  2. digitalnature
    Member
    Posted 3 years ago #

    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?

  3. digitalnature
    Member
    Posted 3 years ago #

    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"...

Topic Closed

This topic has been closed to new replies.

About this Topic