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 trialBartosz Kubisz
26,277 PointsHow to Build a Wordpress Plugin. Challenge Task 4 of 6
Question: Inside of the widget function, below the extract function, apply the widget_title filter to get the title of the instance. Assign it to a variable named title.
My code
<?php
class My_Plugin_Widget extends WP_Widget {
function my_plugin_widget() {
parent::__construct( false, 'My Plugin Widget' );
}
function widget( $args, $instance ) {
// Widget output
extract( $args );
$title = apply_filters( 'widget_title', $instance['title'] );
}
function update( $new_instance, $old_instance ) {
// Save widget options
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
return $instance;
}
function form( $instance ) {
// Output admin widget options form
$title = esc_attr( $instance['title'] );
require( 'inc/widget-fields.php' );
}
}
?>
Prompt Bummer! The first thing inside the widget method, use the extract function to make $args into local variables.
What Iām doing wrong?
<?php
class My_Plugin_Widget extends WP_Widget {
function my_plugin_widget() {
parent::__construct( false, 'My Plugin Widget' );
}
function widget( $args, $instance ) {
// Widget output
extract( $args );
$title = apply_filters( 'widget_title', $instance['title'] );
}
function update( $new_instance, $old_instance ) {
// Save widget options
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
return $instance;
}
function form( $instance ) {
// Output admin widget options form
$title = esc_attr( $instance['title'] );
require( 'inc/widget-fields.php' );
}
}
?>
Michelle Martinez
4,263 Pointshow did you solved this?
Michelle Martinez
4,263 Pointsremoving the comment... great
Henrik Hansen
23,176 PointsOmg, that was just so annoying! Thank you Michelle! You should add that as an answer.
Bartosz Kubisz
26,277 PointsBartosz Kubisz
26,277 PointsProblem solved....