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 trialMatt Van Dyck
2,033 PointsIf user role is, then change logo
Hi there.
I want to write a quick snippet for wordpress that essentially says if the user role is equal to a certain role, then to change the logo on the website to a different logo. Are there any functions/variables you guys can recommend that I should use for this?
Thanks for your time.
6 Answers
Arthur Verschaeve
20,816 PointsIn this forum post on the official wordpress site they fixed it: http://wordpress.org/support/topic/fatal-error-call-to-undefined-function-wp_get_current_user-4
Arthur Verschaeve
20,816 PointsThink this is helpfull:
<?php
if ( current_user_can( 'manage_options' ) ) {
/* some logo */
} else {
/* other logo */
}
This article may be helpfull too: http://codex.wordpress.org/Function_Reference/current_user_can
Matt Van Dyck
2,033 PointsHi there,
Thanks for your response. I'm adding this custom code in a plugin on my wordpress site and I get this error?
Fatal error: Call to undefined function wp_get_current_user() in /wp-includes/capabilities.php on line 1329
Do I need to include code above it saying to reference that particular file to get the function?
J Andrew Scott
30,626 PointsWordPress stores user roles as capabilities in the user meta table. You can format your page templates like so:
<?php if (current_user_can('administrator')) : ?>
<img src="admin_logo.png">
<?php elseif (current_user_can('editor')) : ?>
<img src="editor_logo.png">
<?php else : ?>
<img src="logo.png">
<?php endif; ?>
Matt Van Dyck
2,033 PointsHi there,
Thanks for your response. I'm adding this custom code in a plugin on my wordpress site and I get this error?
Fatal error: Call to undefined function wp_get_current_user() in /wp-includes/capabilities.php on line 1329
Do I need to include code above it saying to reference that particular file to get the function?
Matt Van Dyck
2,033 PointsHi there,
Thanks for your response. I'm adding this custom code in a plugin on my wordpress site and I get this error?
Fatal error: Call to undefined function wp_get_current_user() in /wp-includes/capabilities.php on line 1329
Do I need to include code above it saying to reference that particular file to get the function?
Arthur Verschaeve
20,816 PointsMaybe it is good to know: wp_get_current_user has been in core since 2.0.1. What version are you using?
Matt Van Dyck
2,033 Points3.9.1 :(
Matt Van Dyck
2,033 PointsEDITED
Matt Van Dyck
2,033 PointsNevermind, figured it out. Switched up the ending image /> tag
Matt Van Dyck
2,033 PointsMatt Van Dyck
2,033 PointsAh thank you! Adding require_once(βpluggable.phpβ); to the top of the capabilities.php file made it work. Thanks for your help Arthur and Andrew!