Skip to content

Commit

Permalink
Add support for WP Better Emails.
Browse files Browse the repository at this point in the history
Note - Requires my forked version of WP Better Emails at the moment until
my changes to WP Better Emails are added to the official plugin:
https://github.com/r-a-y/WP-Better-Emails/tree/changes

WP Better Emails wraps the original plain-text email content around a HTML
template; this interferes with the positioning of RBE's marker and how RBE
parses the reply.

This commit repositions the RBE marker in HTML emails created by WP Better
Emails so the RBE marker is at the beginning of the HTML body.
  • Loading branch information
r-a-y committed Mar 5, 2013
1 parent edd1f15 commit 5b245b4
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions bp-rbe-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ private function hooks() {

// Filter wp_mail(); use our listener object for component checks
add_filter( 'wp_mail', array( &$this, 'wp_mail_filter' ) );

// WP Better Emails support
add_filter( 'wpbe_html_body', array( &$this, 'move_rbe_marker' ) );
}

/**
Expand Down Expand Up @@ -399,6 +402,42 @@ public function set_group_id( $retval ) {

return $retval;
}

/**
* WP Better Emails Support.
*
* WP Better Emails gives admins the ability to wrap the plain-text content
* around a HTML template.
*
* This interferes with the positioning of RBE's marker and how RBE parses the
* reply. So what we do in this method is to reposition the RBE marker to the
* beginning of the HTML body.
*
* This allows RBE to parse replies the way it was intended.
*
* @param str $html The full HTML email content from WPBE
* @return str Modified HTML content
*/
public function move_rbe_marker( $html ) {
$reply_line = __( '--- Reply ABOVE THIS LINE to add a comment ---', 'bp-rbe' );

// if our RBE marker isn't in this email, then this isn't a RBE email!
// so stop!
if ( strpos( $html, $reply_line ) === false ) {
return $html;
}

// remove the marker temporarily
$html = str_replace( $reply_line . '<br />
<br />', '', $html );

// add some CSS styling
// 3rd party devs can filter this
$style = apply_filters( 'bp_rbe_reply_marker_css', "color:#333; font-size:12px; font-family:arial,san-serif;" );

// add back the marker at the top of the HTML email and centered
return str_replace( '<body>', '<body><center><span style="' . esc_attr( $style ) . '">' . $reply_line . '</span></center><br />', $html );
}
}

?>

0 comments on commit 5b245b4

Please sign in to comment.