Is there a simple function/script to get the avatar/url of a message recipient?

For instance, let's say user A sends a private message to user B.

In user A's message list, it now displays user A's avatar + message excerpt, enabling user A to click on the excerpt to view the message that he sent.

When user A goes inside to view the message thread he started, user A is able to see his own information (metadata such as date sent, message content, his own avatar), however is not able to see the avatar/info of who he sent the message to.

Essentially the basic message template currently looks like this:

  • User A Avatar - User A Nicename/url
  • Date Sent

  • Message Contents

However I'm trying to get it like this:

  • User A Avatar - User A Nicename/url
  • Date Sent
  • User B Avatar- User B Nicename/url (the message recipient)

  • Message Contents

I know how to get the avatar/url for the message author however I can't figure out how to get the avatar/url for the message recipient

Does anyone have any suggestions for how to do this?

  • Private messaging is not a WordPress core feature - thus how you access the relevant information of either party is dependent on the implementation. Typically, I'd imagine that the private message would be stored in the database along with the user IDs for both the sender and the recipient (if a private message is a CPT, then the recipient ID would probably be stored as post meta-data). Knowing the relevant ID, user information can then be retrieved with the get_userdata() function. – bosco Oct 13 '16 at 0:09
  • Thanks for taking time to answer @bosco! I did find the meta_key I needed in post metadata section of my database as you suggested. Wasn't able to use get_userdata function for this particular situation due to the implementation but finding the relevant metakey in the database got me a step further. Thank you. – kosmicbird Oct 18 '16 at 3:57
  • No problem! Let us know if you run into any more roadblocks =] – bosco Oct 19 '16 at 0:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.