Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

WordPress How to Build a WordPress Plugin Building a WordPress Plugin Settings Page CRUD with the WordPress Options Table

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.