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 trialfarhanasalman
Front End Web Development Techdegree Student 2,830 PointsWhat my answer is missing
Question about "Update the widget function to work with the new num_courses settings field. Assign the 'num_courses' of the instance to a variable named num_courses. Then require a file named widget-front-end.php in the inc folder."
Here is my code:
<?php
class My_Plugin_Widget extends WP_Widget {
function my_plugin_widget() {
parent::__construct( false, 'My Plugin Widget' );
}
function widget( $args, $instance ) {
extract( $args );
$title = apply_filters( 'widget_title' , $instance['title'] );
$num_courses = $instance['num_courses'];
require('inc/widget-front-end.php');
}
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
$instance['num_courses'] = strip_tags($new_instance['num_courses']);
return $instance;
}
function form( $instance ) {
$title = esc_attr($instance['title']);
$num_courses = esc_attr($instance['num_courses']);
require( 'inc/widget-fields.php' );
require( 'inc/widget-front-end.php' );
}
}
function my_plugin_register_widgets() {
register_widget( 'My_Plugin_Widget' );
}
add_action( 'widgets_init', 'my_plugin_register_widgets' );
?>
I got error:
Bummer! Make sure to save the $instance['num_courses'] value into the num_courses variable.
please tell me.
farhanasalman
Front End Web Development Techdegree Student 2,830 Points1 Answer
Dustin Matlock
33,856 PointsYour code won't pass because you have require( 'inc/widget-front-end.php' );
duplicated under the form
function.
farhanasalman
Front End Web Development Techdegree Student 2,830 PointsThank you ! I removed the duplicate require under the form function. :)
Ron McCranie
7,837 PointsRon McCranie
7,837 PointsCould you let us know what code challenge this is from. A link would be great.