Change Username to User’s Display Name in rtMedia Activity

By default rtMedia uses user’s nice name in activity. The following screen shows the username in activity feed.

username-activity-update

You can change it as per your requirement using below filters. You can put below sample code in your theme’sfunctions.php file.

Filter name : rtmedia_buddypress_action_text_fitler & rtmedia_buddypress_action_text_fitler_multiple_media

Description : This filters will change action name before creating the activity. This will update database for future reference.

Use the following sample code to upload a single media from the media tab.

function change_rtmedia_activity_username_single_media( $action, $username, $count, $user_nicename, $media_type ) {
    $user_id  = get_current_user_id();
    $user     = get_userdata( $user_id );
    $username = '<a href="' . get_rtmedia_user_link ( $user_id ) . '">' . $user->display_name . '</a>';
    $media_type_label = $count > 1 ? constant( 'RTMEDIA_' . strtoupper( $media_type ) .  '_PLURAL_LABEL' ) : constant( 'RTMEDIA_' . strtoupper( $media_type ) .  '_LABEL' );
    $action   = sprintf( __( '%s added %d %s', 'buddypress-media' ), $username, $count, $media_type_label );
    return $action;
}
add_filter('rtmedia_buddypress_action_text_fitler', 'change_rtmedia_activity_username_single_media', 10, 5);

Use the following sample code to change action when user upload multiple media from the media tab.

function change_rtmedia_activity_username_multiple_media( $action, $username, $count, $user_nicename ) {
    $user_id  = get_current_user_id();
    $user     = get_userdata( $user_id );
    $username = '<a href="' . get_rtmedia_user_link ( $user_id ) . '">' . $user->display_name . '</a>';
    $action   = sprintf( __( '%s added %d %s', 'buddypress-media' ), $username, $count, RTMEDIA_MEDIA_SLUG );
    return $action;
}
add_filter('rtmedia_buddypress_action_text_fitler_multiple_media', 'change_rtmedia_activity_username_multiple_media', 10, 4);

Filter name : rtmedia_bp_activity_action_text

Description : This filter won’t change anything into database but used to update activity action text while viewing the activity feed. Below example is to change username to it’s diaplay name.

function change_rtmedia_activity_username( $action, $username, $count, $user, $media_type, $activity_id ) {
    $username = '<a href="' . get_rtmedia_user_link ( $user->ID ) . '">' . $user->display_name . '</a>';
    $media_type_label = $count > 1 ? constant( 'RTMEDIA_' . strtoupper( $media_type ) .  '_PLURAL_LABEL' ) : constant( 'RTMEDIA_' . strtoupper( $media_type ) .  '_LABEL' );
    $action   = sprintf( __( '%s added %d %s', 'buddypress-media' ), $username, $count, $media_type_label );
    return $action;
}
add_filter('rtmedia_bp_activity_action_text', 'change_rtmedia_activity_username', 10, 6);

user-display-name-activity-update