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 a WordPress Plugin Settings Page CRUD with the WordPress Options Table

liktid
liktid
6,387 Points

Too much "We can" and not enough "Why we do this" in this video

Well this is not a question per se, its more feedback related. Until this video i was completly able to follow all of his steps, but in the middle of the CRUD-topic the author is jumping into a boat full of "we can's". It would be more helpful to explain why we - for example - write the following statement:

if( $options != '' ) {

        $wptreehouse_username = $options['wptreehouse_username'];

    }

1 Answer

Tarik Hamilton
Tarik Hamilton
6,799 Points

What this says is,

if options (an array) is not empty, assign this variable ($wptreehouse_username) to one of the options's values.

Why? Well, it looks like an example code snippet that is taken out of context. I can't tell you the exact reason why, but one reason for passing an array key's value is that it is shorter and simpler. It also allows the options array can be changed or modified. Maybe we want to be able to say last username's name. We wouldn't be able to, if we kept the only instance of that data inside of the options array.