I want to add a label side the user name who posted a post on groups or activity the label will be admin or moderator if A admin post it will show admin label or if the moderator post it will show the moderator label i successfully added those label but it dissappear the group title from the activity header feed. here is my c[enter imageenter image description here description here](https://i.stack.imgur.com/8v5mC.jpg)
function custom_activity_action_string( $action, $activity ) {
// Get the author role
$author_role = bbp_get_user_display_role($activity->user_id);
// Set the label based on user role
if ( $author_role == 'Keymaster' ) {
$label = '<span class="group-admin-label">Admin</span>';
} elseif ( $author_role == 'Participant' ) {
$label = '<span class="group-moderator-label">Moderator</span>';
} else {
$label = '';
}
// Check if activity is in group activity page or main activity page
if ( $activity->component == 'groups' && $activity->type == 'activity_update' ) {
$group_label = __( 'posted an update in the group', 'text-domain' );
} else {
$group_label = __( 'posted an update', 'text-domain' );
}
// Get user data
$user_link = bp_core_get_userlink( $activity->user_id );
$user_name = bp_core_get_user_displayname( $activity->user_id );
// Get the activity ID
$activity_id = bp_get_activity_id();
// Get the group ID
$group_id = bp_activity_get_meta( $activity_id, 'item_id', true );
// Get the group title
$group_title = bp_get_group_name( $group_id );
// Get group data if activity is in group activity page
if ( $activity->component == 'groups' ) {
$group_link = bp_get_group_permalink( $activity->item_id );
$group_avatar = bp_get_group_avatar_url( $activity->item_id, array( 'type' => 'full' ) ); // Replace this line with bp_get_group_logo_url to show the group logo
$group_name = bp_get_group_name( $activity->item_id );
$group_post_title = bp_activity_get_meta( $activity->id, 'bp_activity_title', true ); // Get the title of the post within the group
// Set label based on group type
$group_type = bp_get_group_type( $activity->item_id );
if ( $group_type == 'hidden' ) {
$group_label = __( 'posted an update in the private group', 'text-domain' );
}
}
// Build activity action string
$action = sprintf(
__( '%1$s %2$s %3$s %4$s %5$s %6$s', 'text-domain' ),
$user_link,
$label,
$group_label,
$group_title,
isset( $group_avatar ) ? '<img src="' . $group_avatar . '" alt="' . $group_name . '"/>' : '',
isset( $group_post_title ) ? $group_post_title : ''
);
// Add group name and link if activity is in group activity page
if ( $activity->component == 'groups' ) {
$action .= sprintf(
__( ' %1$s', 'text-domain' ),
'<a class ="grp-ttl" href="' . $group_link . '">group name' . $group_name . $group_title . '</a>',
);
}
return $action;
}
add_filter( 'bp_get_activity_action_pre_meta', 'custom_activity_action_string', 10, 2 );
Here is the code full code