0

I want to display a unique message on the post (single.php) page outside the loop on author box. I want the message to be different depending on the author's capabilities. So for instance, if the author can manage_options then echo this is admin, else if the author can edit_others_posts then echo this is editor and finally else this is contributor.

2 Answers 2

1

Use global $authordata:

Testing for roles:

global $authordata;    

if ( in_array( 'administrator', $authordata->roles ) )
{
   echo 'Hello Admin!';
}
elseif ( in_array( 'editor', $authordata->roles ) )
{
    // echo something else
}

Or testing for capabilities:

if ( ! empty ( $authordata->allcaps['manage_options'] ) )
{
   echo 'The author can manage options';
}
elseif ( ! empty ( $authordata->allcaps['edit_others_posts'] ) )
{
    // echo something else
}
3
  • thanks but I don't want 'current user', I want it to be post author.
    – jack
    Commented Apr 26, 2013 at 15:44
  • if you please read my question again, it is for an author bio box outside the loop on post page.
    – jack
    Commented Apr 26, 2013 at 15:49
  • @jack See my update.
    – fuxia
    Commented Apr 26, 2013 at 15:55
0

After the loop in single.php

<?php endwhile; // end of the loop. ?>

place this:

<?php
if ( current_user_can( 'editor' ) )
{
echo 'This is the editor';
}
elseif ( current_user_can( 'contributer' ) )
{
echo 'This is contributor';
} ?>

Now under the post, it will say 'This is the editor' or 'this is the contributor' based on the capability of the user.

1
  • 2
    First, please explain your code instead of providing a code-only answer. Second, this is not an answer to what was asked.
    – tfrommen
    Commented Apr 26, 2013 at 16:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.