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 WordPress Widgets Code Challenges

Adding the $args array extract function inside the widget function (wordpress plugin course)

I have no idea what im doing wrong here, the code I have used is the same as what I followed along with but I must be missing something....

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




    }

    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' );
    }


    }



?>

My Bummer message was this "Bummer! The first thing inside the widget method, use the extract function to make $args into local variables."

Thanks Craig

2 Answers

Sean T. Unwin
Sean T. Unwin
28,690 Points

You are missing the second part of the request.

"[...] apply the widget_title filter to get the title of the instance. Assign it to a variable named title."

Edit: Also remove the comment. For some reason the Challenge will only accept the extract() call as the first line within the widget() function.

Hi Sean,

The complete answer regarding that function I have been using is this:

<?php

    function widget( $args, $instance ) {
        // Widget output

        extract( $args );
        $title = apply_filters( 'widget_title', $instance['title'] );


    }

?>

Am I looking over something in the question still :S
Sean T. Unwin
Sean T. Unwin
28,690 Points

Please see my edit above. A comment is not allowed to be the first statement within the widget() function in this challenge request.

Sean you are a life saver :) It didn't even cross my mind to try that even knowing how picky the challenges can be at time! :)

Much Appreciated!

Ken Stone
Ken Stone
29,703 Points

They should fix this challenge.