Hi,
What do you recommend me if you don’t want to use WordPress’ own avatars via Gravatar, how I can best implement this using icon or image elements with Bricks Builder, if I don’t want to use any other plugins for this, but via an ACF field in the user profile.
Is it already planned to offer a user avatar element where you can set an icon and select the user profile field?
Kind regards
Matze202
I wrote the following 2 snippets, so far they work quite well.
Does anyone have any suggestions for improvement?
This snippet filters the corresponding image from the ACF field of the logged-in user profile and transfers it as a thumbnail with HTML code or the selected icon if no profile image is stored.
<?php
function eh_cupb(){
if(is_user_logged_in()){
$user_id = get_current_user_id();
$display_name = wp_get_current_user()->display_name;
if(!empty($user_id)){
$profilbild = get_field('profilbild', 'user_' . $user_id);
return '<img src="' . $profilbild['sizes']['thumbnail'] . '" class="eh_profilbild" alt="' . $display_name . '" title="' . $display_name . '">';
}
}else{
return '<i class="fas fa-user" style="font-size: 38px;"></i>';
}
}
add_filter('hook', 'eh_cupb');
The following snippet packs the transferred image or icon into the corresponding link to the dashboard or login page.
<?php
function eh_cupbl(){
if(is_user_logged_in()){
$user_id = get_current_user_id();
if(!empty($user_id)){
$profilbild = get_field('profilbild', 'user_' . $user_id);
return '<a href="/dashboard/" title="Dashboard">' . eh_cupb() . '</a>';
}
}else{
return '<a href="/login/" title="Login">' . eh_cupb() . '</a>';
}
}
add_filter('hook', 'eh_cupbl');
So I only needed to insert the following code into the code element and the placement works.
<?php
echo eh_cupbl();
?>
I would be happy if, in the future, authorizations could also be added for individual elements or at least for containers, and if images, a fallback image for dynamic content, and changing links could also be included, so that something like this could also be built with elements.
Kind regards
Matze202
1 Like