Jump to content

Trying to display admin if is admin


DanMat

Recommended Posts

So. I am using a plugin called "simple user rank" which counts the number of comments and displays a different rank. All good. But I don't want my admins/moderators to be displayed as newbies/rookies or any other rank just because they don't comment that much. 

This is how the plugin works and displays the rank

if( !function_exists('get_user_rank') ) {
function get_user_rank() 
{
if( !$ranks = get_option('_user_rank_comments_fields') ) return false;
$count = get_transient( 'user_rank_comments_' . substr(md5( strtolower(get_comment_author_email( $comment_id )) ),0, );
if ( false === $count ) {

global $wpdb;
$count = $wpdb->get_var( $wpdb->prepare( 'SELECT COUNT(comment_ID) 
 FROM ' . $wpdb->comments. ' 
 WHERE comment_author_email = %s
  AND comment_approved = 1'
  , 
  get_comment_author_email()
 ) 
);
set_transient( 'user_rank_comments_' . substr(md5( strtolower(get_comment_author_email( $comment_id )) ),0,, $count );
} 
foreach( $ranks as $row ) {
if( $count >= (int)$row['count'] )
$rank = $row['name'];
else break;
}
return $rank;

 

 

 

 

I want to override the rank displayed for admin and/or moderator like this:

 


if (current_user_can( 'manage_options' )) {
echo 'admin'
}
elseif (current_user_can( 'moderate_comments' )) {
echo 'moderator'
}
endif return $rank 

Any help is appreciated! Thanks!

Link to comment
https://forums.phpfreaks.com/topic/278066-trying-to-display-admin-if-is-admin/
Share on other sites

Yes that's it.
I've tried it like this 

<?php 
if (current_user_can( 'manage_options' )) { echo 'admin' }
elseif (current_user_can( 'moderate_comments' )) { echo 'moderator' }
else ( function_exists('get_user_rank') ) echo get_user_rank(); 
?>

but no luck so far. 

If you say no luck one more time I'm leaving.

 

It doesn't sound like what you're doing is even the right way to do it. current_user means the user who is logged in, the user viewing the page. So if you are not logged in you will always see the ranks. If you are logged in as admin, everyone will have the name admin. That's what you want?

If you arent logged in you can't view the website. Its a private community. and I know exactly what current_user means i think its pretty straight forward. About what I am trying to do : 

You have a status of "guru" yeS ? If you were also an admin I would want to display that your status of admin. To all users. If you'd have a moderator status I want to display Moderator for all user not just for the user in cause.

If you dont understand what I mean please don't bother to post just to add more posts to the count and get a status of guru.

 

And I can say whatever I want so stop it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.