Hi there, please put code in backticks. Ive edited your post and added them.
So what is the problem with this?
Hello! Thank you! I would want that the role of user to be shown on the cover of the page.
or you want to say that it does and my theme does not interpret it? Can i put this in the header.php?
No yu’d put this either in your child-themes functions.php or in wp-content/plugins/bp-custom.php, looking at the code it should work.
Hi Venutio! I modified this
function devb_show_role_on_profile()
{ global $wp_roles;
$user_id = bp_displayed_user_id();
$user = get_userdata($user_id);
$roles = $user->roles;
if (!$roles) return;
if (!isset($wp_roles)) $wp_roles = new WP_Roles();
$named_roles = array();
foreach ($roles as $role) {
$named_roles [] = $wp_roles->role_names[$role]; }
if ($named_roles) return '<span class="user-role activity">' . join(', ', $named_roles) . '</span>';
}
add_filter('eo_title_content_html_below_title', 'devb_show_role_on_profile');
This works and show it in the cover page of the profile.
the problem is in the other pages like group or other page out of my profile (when i open it) this error appear in the cover page:
NOTICE: TRYING TO GET PROPERTY ‘ROLES’ OF NON-OBJECT IN
I tried with !null but it didnt work.
Any suggest?
Thanks!!
I used very similar code but add_filter('bp_before_member_header_meta', 'devb_show_role_on_profile');
Do you want it to display on other pages?
The problem is that you are trying to run this on every page when it will only work on the user profile pages as bp_displayed_user_id() will only work on a user profile page. so you would need to add something like:
if ( ! bp_is_user_profile() ) {
return;
}
Hi! i tried both options..but it didnt work.
This is the last version with your suggest, any idea?Thanks!!!!
function devb_show_role_on_profile()
{ global $wp_roles;
$user_id = bp_displayed_user_id();
$user = get_userdata($user_id);
$roles = $user->roles;
$profilebuddy = bp_is_user_profile() ;
if ( !$profilebuddy )
return '';
if (!$roles ) return '';
if (!isset($wp_roles))
$wp_roles = new WP_Roles();
$named_roles = array();
foreach ($roles as $role) {
$named_roles [] = $wp_roles->role_names[$role]; }
if ($named_roles)
return '<span class="user-role_activity">' . join(', ', $named_roles) . '</span>';
}
add_filter('eo_title_content_html_below_title', 'devb_show_role_on_profile');
Try deleting this:
$profilebuddy = bp_is_user_profile() ;
if ( !$profilebuddy )
return '';
And doing this:
function devb_show_role_on_profile() {
global $wp_roles;
if ( ! bp_is_user() ) {
return '';
}
// etc
You are using this custom filter hook: eo_title_content_html_below_title
But you do not indicate what that hook is actually filtering.
IOW: return '';
does not make sense without some context.
What is the full line for the hook? apply_filters( // something
Great @shanebp this works!! =)
these is a custom shortcode from my theme.