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 Customizing the WordPress Admin Area Controlling Admin Navigation in WordPress How to Customize the Admin Menu in WordPress Quiz

Zane Jones
Zane Jones
3,361 Points

Question #4 - Removing Menu Items Based on User/Role

"If you were using the functions.php file to remove links for just a certain user group or specific user, you would have to use a _____ statement."

I've tried variations of remove_menu_page() and current_user_can() [which appears in the WP codex page for remove_menu_page()] and I'm just getting nothing. I've tried reviewing the videos, and I'm still stumped on this question, and I'm not sure the videos ever address it. (Unless I'm missing something.)

It seems to me the videos say you -can- do it, and then gloss over how you could do it with a plugin, but I'm drawing a blank with the phrasing of this particular question.

Help would be appreciated!

4 Answers

Zac Gordon
STAFF
Zac Gordon
Treehouse Guest Teacher

It's looking for the general term that includes if statements. Begins with a 'c'

Zane Jones
Zane Jones
3,361 Points

Ah, of course! Thanks for clearing that up.

use "conditional"

Matthew Meo
Matthew Meo
2,341 Points

Hi Zane,

I'm not sure if this is the answer you are looking for, but maybe the answer is simply an "if" or "if else" statement. Perhaps wordpress is different with plugins (haven't worked with it yet), but I've done simple work with php in the past that essentially said if($user = "this") and then grant them some permission (like different menu options showing). Based on the solutions you've tried, I'd guess that my answer isn't the answer to the question. But thought I'd try and help anyway.

Zane Jones
Zane Jones
3,361 Points

Thanks for the attempt, Matthew!

To remove menu items based on user/role, I would expect something like:

 if ( !current_user_can('moderate_comments') ) {

   function hide_comments () {
      remove_menu_page( 'edit-comments.php' );
   }

   add_action( 'admin_menu', 'hide_comments');
}

None of those are a very obvious candidate for the blank in the question, however. I tried simply putting in 'if', but that wasn't any good.

It's not a super-difficult theory, but I would like to figure out the quiz answer, hah!