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 trialZane Jones
3,645 PointsQuestion #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
Treehouse Guest TeacherIt's looking for the general term that includes if statements. Begins with a 'c'
Imon Dela Rosa
7,383 Pointsconditional statement
Felipe Genuino
Java Web Development Techdegree Student 8,628 Pointsuse "conditional"
Matthew Meo
2,341 PointsHi 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
3,645 PointsThanks 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!
Zane Jones
3,645 PointsZane Jones
3,645 PointsAh, of course! Thanks for clearing that up.