BuddyDev

Search

[Resolved] Is it possible to add sender username to beginning of BP message subject?

Tagged: 

  • Participant
    Level: Enlightened
    Posts: 21
    Mwale on #12915

    I would really be thankful for help on this, I want when users type a message subject, it should include their username at the beginning or end. The Subject should be like this: “Username: Are you coming tomorrow?”
    I was reading this useful article: https://samelh.com/blog/2016/01/22/buddypress-how-to-add-custom-content-after-message-text-content/

    Thanks in advance!

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2487
    Ravi on #12925

    Hello Mwale,

    Thank you for posting. Please try the following code and let me know if it works or not

    
    function buddydev_modify_message_subject( $message_subject ) {
    
    	global $messages_template;
    
    	if ( 'sentbox' != bp_current_action() ) {
    		$current_message = current( $messages_template->thread->messages );
    	} else {
    		$current_message = end( $messages_template->thread->messages );
    	}
    
    	$new_subject = bp_core_get_user_displayname( $current_message->sender_id ) . ': ' . $message_subject;
    
    	return $new_subject;
    }
    
    add_filter( 'bp_get_message_thread_subject', 'buddydev_modify_message_subject' );
    

    Thank you
    Ravi

  • Participant
    Level: Enlightened
    Posts: 21
    Mwale on #12927

    ABBSOLUTELLY AMAZING!! Thanks Ravi, this code works perfectly inside buddypress sent box, but the issue is when using inside an app from apppresser.com. When messages are sent, still only subject is shown, like in this screenshot: https://screenshots.firefox.com/q0dKfDmB3I3HUGUr/drive.google.com . Is there way to make this code work outside sentbox?

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2487
    Ravi on #12978

    Hello Mwale,

    I am not much familiar with the app you are saying. So couldn’t provide help with that ask their support team for the help. Just try the following code it might help

    
    function buddydev_modify_single_thread_subject( $subject ) {
    
    	
    	global $thread_template;
    
    	$current_message = current( $thread_template->thread->messages );
    
    	if ( false !== strpos( $subject, 'Re:' ) ) {
    		$subject = str_replace( 'Re:', '', $subject );
    	}
    
    	$new_subject = bp_core_get_user_displayname( $current_message->sender_id ) . ': ' . $subject;
    
    	return $new_subject;
    }
    add_filter( 'bp_get_the_thread_subject', 'buddydev_modify_single_thread_subject' );
    

    Thank you
    Ravi

  • Participant
    Level: Enlightened
    Posts: 21
    Mwale on #13349

    Hi @ravisharma , I really appreciate your help on this! I didn’t manage to get it to work but I am very grateful for the code. Thanks again!!

  • Participant
    Level: Yogi
    Posts: 1000
    calu on #19574

    ‘I have requested @ravisharma to check the code and assist you on this today. Regards Brajesh’

    https://buddydev.com/support/forums/topic/resolved-remove-the-subject-line-requirement-in-messages/page/2/

    Hi Ravisharma, I am contacting you because I an having a lot of trouble getting this jQuery to work.

    These are the js files in my GeneratePress theme:

    https://imgur.com/a/otAzBf0

    Could you please advise me, in which js file I should copy the code to, and how it should be wrapped?

    jQuery(‘#send_message_form’).submit( function() {
    jQuery(‘#subject’).val(“Some message subject”);
    });

    regards
    carsten

  • Keymaster
    (BuddyDev Team)
    Posts: 22172
    Brajesh Singh on #19580

    Hi,
    The jQuery code above will not work with the current BP Nouveau theme. If you are using legacy, please do let me know.

    Regards
    Brajesh

  • Participant
    Level: Yogi
    Posts: 1000
    calu on #19586

    Hi Brajesh, thanks, though not the answer I was hoping for, but finally I’ve got an explanation, why this code doesn’t work with BP Nouveau.

    I have found another topic on the subject, which is not using js, but that does not work either…

    https://buddypress.org/support/topic/subject-field-in-private-messages/

    I guess I have to wait to see your message component. When do you expect it to launch?

    I have asked this before, but just to clarify, will this extension only work with your theme, or can it be integrated with other themes with some customization?

    Regards
    Carsten

  • Keymaster
    (BuddyDev Team)
    Posts: 22172
    Brajesh Singh on #19606

    Hi Carsten,
    That code suffesr from the same issue. Nouveau has a different structure and the old code (specially css/js) may not work.

    For the time being, all our plans remove around our upcoming theme. With the theme, we are in control of the whole appearance and behaviour and it gives us huge advantage.

    I will share the details once we release it. It should be available latest by the 1st week of new year.

    Regards
    Brajesh

You must be logged in to reply to this topic.

This topic is: resolved