Skip to:
Content
Pages
Categories
Search
Top
Bottom

Change Message Email Subject

  • @lolotrgeek

    Participant

    I am sending a user a message with the following function:

    		$msg = array(
    			'recipients' => $recipients, 
    			'subject' => $subject, 
    			'content' => $content
    		);
    
    		messages_new_message ($msg);

    I want the email subject that sends to the user when the message is sent to match the subject of the message.

    I’d imagine I could do this with a filter like:

    function messages_notification_new_message_subject($subject, $email_subject) {
    	$email_subject = $subject;
    }
    add_filter( 'messages_notification_new_message', 'messages_notification_new_message_subject', 10, 7 );

    But I have no idea which functions/variables to use to make a filter like this to work. Any suggestions?

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • @shanebp

    Moderator

    There is no such filter hook as messages_notification_new_message.

    There is an email_subject filter hook:
    $email_subject = apply_filters( 'messages_notification_new_message_subject', $email_subject, $sender_name, $ud );
    But as you can see, the variables passed do not include the message subject.

    So, I don’t see a way to do what you want.

    There is an enhancement ticket in the works
    https://buddypress.trac.wordpress.org/ticket/6460
    It might expose the fields you need.

    You aren’t alone in asking for a different filtering system:
    https://buddypress.trac.wordpress.org/ticket/6460

    @lolotrgeek

    Participant

    Thanks shanebp! Sorry for the late reply, your post may have indavertently helped me. I’ll edit this with my solution shortly.

    @lolotrgeek

    Participant

    Oops hit reply not edit! well…

    Here’s the solution I arrived at:

    function filter_change_email_subject ( $email_subject, $sender_name, $ud ) {
    	$email_subject = sprintf( __('%1$s wants to say hello', 'buddypress' ), $sender_name);
    	return $email_subject;
    }
    add_filter( 'messages_notification_new_message_subject', 'filter_change_email_subject' , 10, 7 );

    This works for what I’m doing, for someone else that wants to pass a dynamic subject you may need to nest this function.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Change Message Email Subject’ is closed to new replies.
Skip to toolbar