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 trial

WordPress How to Build a WordPress Plugin Building WordPress Widgets, and Shortcodes Adding Settings to a WordPress Widget

Brad Griffin
Brad Griffin
7,003 Points

num_courses was not copied over?

http://screencast-o-matic.com/watch/cohYo7fQ8G

I'm not seeing where / how to update the update function with the correct code. I've looked in the forums, rewatched the video, and still there's something off. I've attached a quick screencast as well. Any assistance would be appreciated. I'm looking for the correct code, and why / what makes that code the right answer. Thanks a bunch!

plugin.php
<?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'] );



        }

        function update( $new_instance, $old_instance ) {
            $instance = $old_instance;
            $instance['title'] = strip_tags($new_instance['title']);
      $instance['num_badges'] = strip_tags($new_instance['num_badges']);
      $num_badges = $instance['num_badges'];

            return $instance;
        }

        function form( $instance ) {
      $num_courses = esc_attr($instance['num_courses']);
            $title = esc_attr($instance['title']);


            require( 'inc/widget-fields.php' );
        }

    }

    function my_plugin_register_widgets() {
        register_widget( 'My_Plugin_Widget' );
    }

    add_action( 'widgets_init', 'my_plugin_register_widgets' );

?>

2 Answers

Ryan Field
PLUS
Ryan Field
Courses Plus Student 21,242 Points

Hi, Brad. I'm not sure why you have num_badges when the challenge is asking you to use num_courses. I did the challenge myself and there wasn't anything about badges. Maybe a previous challenge had you using num_badges and tripped you up? :)

Brad Griffin
Brad Griffin
7,003 Points

i am not a moron i am not a moron i am not a moron i am not a moron {inhale} i am not a moron i am not a moron i am not a moron i am not a moron

Ryan Field
Ryan Field
Courses Plus Student 21,242 Points

Hehe, no worries at all! I've done this exact thing so many times! All part of the learning process! :)