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 Adding CSS to a Plugin Settings Page

Jeremy Hogan
Jeremy Hogan
15,451 Points

This example challenge seems different than the video.

In the example video, the function name and first parameter passed are the same

function wptreehouse_badges_styles() {
wp_enqueue_style('wptreehouse_badges_styles', plugins_url('wptreehouse-badges/wptreehouse-badges.css'));
}

However, to get the quiz correct, I have to use two different elements

function my_plugin_styles() {
wp_enqueue_style('my_plugin_css', plugins_url('my-plugin/my-plugin.css));
}

Did I miss something or is one of these incorrect? Thanks

7 Answers

Zac Gordon
STAFF
Zac Gordon
Treehouse Guest Teacher

Howdy! Sorry, what did you mean by two different elements?

Jeremy Hogan
Jeremy Hogan
15,451 Points

I posted my response below a couple of days ago, but now I'm realizing, I should have done it as a comment. (user error) :)

Here it is: "Sorry, two different "names" is probably a better way to say. In the video example we were told to use "wptreehouse_badges_styles" as the function name and the first thing passed to wp_enqueue_style. In the quiz, I needed to use "my_plugin_styles" for the function name and "my_plugin_css" for the first thing passed to wp_enqueue_style."

Jeremy Hogan
Jeremy Hogan
15,451 Points

Sorry, two different "names" is probably a better way to say. In the video example we were told to use "wptreehouse_badges_styles" as the function name and the first thing passed to wp_enqueue_style. In the quiz, I needed to use "my_plugin_styles" for the function name and "my_plugin_css" for the first thing passed to wp_enqueue_style.

Zac Gordon
STAFF
Zac Gordon
Treehouse Guest Teacher

Hi, if I'm understanding you correctly this is correct. The idea is to have slightly different names in the code challenges compared to what we code in the example project. The goal is to let you see what naming conventions change when you look at different code samples doing the same thing.

Is that what you were curious about? Why the code challenge functions and project file functions did not have the same name?

Jeremy Hogan
Jeremy Hogan
15,451 Points

No, sorry I'm not being clear. I've linked to an image to help explain. The first example function in my image is from the video and the second function in my image is from the challenge. Does the function name have to be the same as the first parameter (variable?) passed to the wp_enqueue_style? http://i.imgur.com/uzkDSf1.png

Thanks for your help!

Darryn Smith
Darryn Smith
32,043 Points

Multi-Post edit #2... sorry...

Darryn Smith
Darryn Smith
32,043 Points

I am also looking for more information on this. I believe I do understand Mr. Hogan's concern.

The issue is not that variable and function names change in challenges with respect to the lessons. The issue that I find confusing, and I think the OP does as well, is this:

In the lesson, when the code is written for the wptreehouse_badges_styles() function:

function wptreehouse_badges_styles() {

    wp_enqueue_style( 'wptreehouse_badges_styles', plugins_url( 'wptreehouse-badges/wptreehouse-badges.css' ) );

You can see that the name of the function is the same as the name passed as the first argument (the handle) in the wp_enqueue_style function within. In short, the name of the custom function and the name of the handle passed within it to wp_enqueue_style are the same.

However, in the code challenge, the function being written is named 'my_plugin_styles' and the handle being passed to wp_enqueue_style is 'my_plugin_css'... obviously not the same name as the containing function:

// Handle: my_plugin_css
// Plugin folder: my-plugin
// CSS file: my-plugin.css

function my_plugin_styles() {
wp_enqueue_style( 'my_plugin_css', plugins_url('my-plugin/my-plugin.css'));

}

As I'm new to much of this, I could only refer to the preceding lesson and try to use the information there to make an attempt at the code challenge. Naturally, my first go at it looked something like this:

function my_plugin_styles() {
wp_enqueue_style( 'my_plugin_styles', plugins_url('my-plugin/my-plugin.css'));
}

I tried various guesses at the proper formatting and whatnot and was unable to arrive at the correct code until I found this thread (which in my book, means I had to cheat to get it.)

But classroom ethics aside, I'd like to try and understand all of this. The truth is, it's the naming logic in the code challenge that makes more sense to me than in the lesson. How is it that we can pass a function's name to another function within itself? Doesn't that cause an infinitely regressing loop?

Obviously, it doesn't since the live plugin, at this stage in the course, is working. But if you can help me understand how this self-referencing matter works (or doesn't), I'd greatly appreciate it.

Zac Gordon
STAFF
Zac Gordon
Treehouse Guest Teacher

Hi,

The first parameter for the wp_enqueue_style is a unique handle and can be whatever you set. It is not dependent or connected to the name of the function in which is resides.

The only place we pass the function name is to the add_action hook that will eventually come after the function.

Hope this clears things up a bit?