Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialLuke Travis
2,887 Points$instance variable never declared
In the "how to create a widget" video, I don't understand what the initial value of $instance is. What is the value of $instance that is being referenced as an array?
Also it seems to me like the child class of Wp_Widget is constructed but not declared anywhere.
1 Answer
Andrew McCormick
17,730 Pointsaccording to the codex "register_widget() is located in wp-includes/widgets.php."
and if we look at widgets.php we see on line 42 @param array $instance The settings for the particular instance of the widget
and then on line 190 we see $instance assigned a value: $instance = $this->get_settings();
Follow the trail anymore to line 377 and find the get_settings() function.
In other words, $instance holds the settings for a particular widget you are defining or extending.