You can change the content type of WordPress emails using the wp_mail_content_type
filter:
add_filter( 'wp_mail_content_type', function( $content_type ) {
$content_type = 'text/html';
return $content_type;
} );
Thanks for your help.
I add this filter but i have also to change bp_send_email function in file /buddypress/bp-core/bp-core-functions.php. then it works.
Before:
$must_use_wpmail = apply_filters( 'bp_email_use_wp_mail', $wp_html_emails || ! $is_default_wpmail );
if ( $must_use_wpmail ) {
$to = $email->get( 'to' );
return wp_mail(
array_shift( $to )->get_address(),
$email->get( 'subject', 'replace-tokens' ),
$email->get( 'content_plaintext', 'replace-tokens' )
);
}
After:
$must_use_wpmail = apply_filters( 'bp_email_use_wp_mail', $wp_html_emails || ! $is_default_wpmail );
if ( $must_use_wpmail ) {
$to = $email->get( 'to' );
return wp_mail(
array_shift( $to )->get_address(),
$email->get( 'subject', 'replace-tokens' ),
$email->get_template( 'add-content' )
);
}
Is there any way to hook/override this “$email->get_template( ‘add-content’ )” keeping the plugin core unchanged?
Can you instead use the wp_mail
filter to change the message?
add_filter( 'wp_mail', function( $array ) {
// Set conditions here.
$array['message'] = 'Change this';
return $array;
} );
I got it working for me only using @henrywright solution with the filter for html emails. But my bp_email_use_wp_mail function i have set to return false. Thank you!
thank you. works perfectly.
I just had to put all three together
add_filter(‘bp_email_use_wp_mail’, ‘__return_true’);
add_filter( ‘wp_mail_content_type’, function( $content_type ) {
$content_type = ‘text/html’;
return $content_type;
} );
$must_use_wpmail = apply_filters( ‘bp_email_use_wp_mail’, $wp_html_emails || ! $is_default_wpmail );
if ( $must_use_wpmail ) {
$to = $email->get( ‘to’ );
return wp_mail(
array_shift( $to )->get_address(),
$email->get( ‘subject’, ‘replace-tokens’ ),
$email->get_template( ‘add-content’ )
);
}
add_filter( ‘wp_mail’, function( $array ) {
// Set conditions here.
$array[‘message’] = ‘Change this’;
return $array;
} );
DELETE THE FOLLOWING:
$must_use_wpmail = apply_filters( ‘bp_email_use_wp_mail’, $wp_html_emails || ! $is_default_wpmail );
if ( $must_use_wpmail ) {
$to = $email->get( ‘to’ );
return wp_mail(
array_shift( $to )->get_address(),
$email->get( ‘subject’, ‘replace-tokens’ ),
$email->get( ‘content_plaintext’, ‘replace-tokens’ )
);
}
LovePlove
do I add this to bp-custom.php?