Use the profile image from eMember WordPress membership plugin

I have used the eMember WordPress Membership Plugin on a project before.  It’s a nice “premium” plugin and has grown with a bit of features as it’s been updated.  However, one feature has yet to be implemented, and that’s the usage of the eMember’s member profile avatar or uploaded image in comments.  Here’s a solution I came up with:

eMember allows you to save random information like the person’s country or any other custom field (besides images of course).  It saves the members uploaded avatars by the member id.  This is an easy fix if your WP and emember profiles are exactly synced up, but often they won’t be.  Here’s a fix.

In your theme’s function.php file add this function:

[code]
function mcp_get_emember_image($commenter) {

$poster_id  = get_userdata($commenter);
$profile = dbAccess::find(WP_EMEMBER_MEMBERS_TABLE_NAME, ' user_name=\'' . $poster_id->user_login . '\'');
$profile = (array)$profile;
$profile_id = $profile['member_id'];
$profile['user_name'] = $wp_user_data->user_login;

$profileimg = $profile['user_name'];

global $auth;

$image_url   = null;
$upload_dir  = wp_upload_dir();
$upload_url  = $upload_dir['baseurl'];
$upload_path = $upload_dir['basedir'];
$upload_url  .= '/emember/';
$upload_path .= '/emember/';
$upload_url  .= $profile_id;
$upload_path .= $profile_id;
if(file_exists($upload_path . '.jpg'))
{
$image_url = $upload_url . '.jpg';
}
else if(file_exists($upload_path . '.jpeg'))
{
$image_url = $upload_url . '.jpeg';
}
else if(file_exists($upload_path . '.gif'))
{
$image_url = $upload_url . '.gif';
}
else if(file_exists($upload_path . '.png'))
{
$image_url = $upload_url . '.png';
}
else
{
// echo $upload_url;
// echo $profile_id;
$image_url = WP_EMEMBER_URL . '/images/default_image.gif';
}

echo '<img src="' . $image_url . '" alt="User Photo"  width="99px" height="99px"/>';

};
[/code]

Make sure to add the above code between the opening and closing php tags (<?php and ?>)

Then, inside your comment template or within your own custom comment function, add the function wherever you want the avatar of the poster.
[code]

<?php mcp_get_emember_image($comment->user_id); ?>

[/code]

They key here in the called function is the $comment-user_id which will get the WORDPRESS id of the commenter.  Then it passes it to the function, which is then used in the $poster_id = get_userdata($commenter).

It then references the database with the wp user login name of the $poster_id, then grabs the member_id (of eMember) from the row associated with

Posted in Uncategorized | Leave a comment

Hello world!

Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!

Posted in Uncategorized | 1 Comment