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

Chris Kwong
Chris Kwong
10,266 Points

Stuck on Task 4 of 6 quiz

The quiz hinted " The first thing inside the widget method, use the extract function to make $args into local variables."

But I have already used the extract($args) function like in the video. What's wrong?

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);
        $title = apply_filters('widget_title', $instance['title']);

        require('inc/front-end.php');
    }

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


    }



?>

1 Answer

Hi Chris, You actually have two problems. One is a problem that seems like an anomaly. That is that for some reason the comment is causing an error. If you delete the comment, you'll get rid of your error message about the extract function. However, then you will have another error. You've included a statement:

 require('inc/front-end.php');

which is not called for in the instructions. If you delete that line too, all should work. Good luck! Richard