Skip to main content

Push Community profile photo to user profile picture?

Is there a way to ensure that if someone changes their community profile photo, the new photo is pushed to the WordPress user profile picture when they're in the Edit Profile section?

+1 (Would really love to see this feature or know how to manually implement)

just created a feature request:

feel free to upvote:

https://community.wpmanageninja.com/fluentcommunity-roadmp/#/idea/1050/

Curtis Bingham

David BernhardtΒ Nice! Upvoted.

Stuart McKelvie

While this doesn't push the image to the WordPress user table, I'm using this code snippet to display the FluentCommunity profile photo as the author photo across my WordPress pages

/**
 * Replace WordPress avatar with FluentCommunity profile picture
 */
add_filter('get_avatar_url', 'use_fluentcommunity_avatar', 10, 3);

function use_fluentcommunity_avatar($url, $id_or_email, $args) {
    global $wpdb;

    // Get user ID from various input types
    $user_id = null;
    if (is_numeric($id_or_email)) {
        $user_id = (int) $id_or_email;
    } elseif (is_object($id_or_email) && isset($id_or_email->user_id)) {
        $user_id = (int) $id_or_email->user_id;
    } elseif (is_string($id_or_email)) {
        $user = get_user_by('email', $id_or_email);
        if ($user) {
            $user_id = $user->ID;
        }
    }

    // If we couldn't get a user ID, return the original URL
    if (!$user_id) {
        return $url;
    }

    // Query the FluentCommunity database table
    $table_name = $wpdb->prefix . 'fcom_xprofile';
    $avatar = $wpdb->get_var($wpdb->prepare(
        "SELECT avatar FROM $table_name WHERE user_id = %d",
        $user_id
    ));

    // If FluentCommunity avatar exists and is not empty, use it
    if ($avatar && !empty($avatar)) {
        return $avatar;
    }

    // Otherwise, return the original WordPress avatar
    return $url;
}

Curtis Bingham

Stuart McKelvieΒ that's an awesome workaround!

Drive Zone

Snippet above did not work for me, I find own solution:

function drivezone_get_fluent_avatar($user_id) {
global $wpdb;
if (empty($user_id) || !is_numeric($user_id)) return false;

// HlavnΓ­ tabulka s avatary
$avatar = $wpdb->get_var($wpdb->prepare(
    "SELECT avatar FROM {$wpdb->prefix}fcom_xprofile WHERE user_id = %d LIMIT 1",
    $user_id
));
if (!empty($avatar)) return esc_url($avatar);

// Fallback: poslednΓ­ aktivnΓ­ zΓ‘znam z media_archive
$media = $wpdb->get_var($wpdb->prepare(
    "SELECT media_url FROM {$wpdb->prefix}fcom_media_archive WHERE user_id = %d AND is_active = 1 ORDER BY id DESC LIMIT 1",
    $user_id
));
if (!empty($media)) return esc_url($media);

return false;

}

/**

  • VracΓ­ Fluent avatar URL (nahrazuje Gravatar)
    */
    add_filter('get_avatar_url', function($url, $id_or_email, $args) {
    $user_id = 0;

    if (is_numeric($id_or_email)) {
    $user_id = (int)$id_or_email;
    } elseif (is_object($id_or_email)) {
    if (!empty($id_or_email->user_id)) $user_id = (int)$id_or_email->user_id;
    elseif (!empty($id_or_email->comment_author_email)) {
    $u = get_user_by('email', $id_or_email->comment_author_email);
    if ($u) $user_id = $u->ID;
    }
    } elseif (is_string($id_or_email) && strpos($id_or_email, '@') !== false) {
    $u = get_user_by('email', $id_or_email);
    if ($u) $user_id = $u->ID;
    }

    if (!$user_id) return $url;

    $furl = drivezone_get_fluent_avatar($user_id);
    return $furl ?: $url;
    }, 5, 3);

/**

  • VracΓ­ kompletnΓ­ HTML (napΕ™. v komentΓ‘Ε™Γ­ch)
    */
    add_filter('get_avatar', function($html, $id_or_email, $size, $default, $alt, $args) {
    $user_id = 0;

    if (is_numeric($id_or_email)) {
    $user_id = (int)$id_or_email;
    } elseif (is_object($id_or_email)) {
    if (!empty($id_or_email->user_id)) $user_id = (int)$id_or_email->user_id;
    elseif (!empty($id_or_email->comment_author_email)) {
    $u = get_user_by('email', $id_or_email->comment_author_email);
    if ($u) $user_id = $u->ID;
    }
    } elseif (is_string($id_or_email) && strpos($id_or_email, '@') !== false) {
    $u = get_user_by('email', $id_or_email);
    if ($u) $user_id = $u->ID;
    }

    $furl = $user_id ? drivezone_get_fluent_avatar($user_id) : false;
    if (!$furl) return $html;

    $classes = !empty($args['class']) ? esc_attr($args['class']) : 'avatar avatar-' . intval($size) . ' photo';
    $alt_attr = esc_attr($alt ?: get_the_author_meta('display_name', $user_id));
    $size_attr = $size ? ' width="' . intval($size) . '" height="' . intval($size) . '"' : '';

    return sprintf('\<img alt="%s" src="%s" class="%s"%s />', $alt_attr, esc_url($furl), $classes, $size_attr);
    }, 5, 6);