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

If 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

In 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

Ah 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!

Think 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

Hi 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?

WordPress 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; ?>

Hi 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?

Hi 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?

Maybe it is good to know: wp_get_current_user has been in core since 2.0.1. What version are you using?

3.9.1 :(

EDITED

Nevermind, figured it out. Switched up the ending image /> tag