Last active
September 23, 2015 09:50
-
-
Save christianwach/c7a77ffd52f9ec2b21d9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php /* | |
-------------------------------------------------------------------------------- | |
Plugin Name: BPGEN WPBE Compatibility | |
Plugin URI: https://gist.github.com/christianwach/c7a77ffd52f9ec2b21d9 | |
Description: Ensures that BP Group Email Notifications digests are sent using WP Better Emails template. | |
Author: Christian Wach | |
Version: 0.1 | |
Author URI: http://haystack.co.uk | |
-------------------------------------------------------------------------------- | |
*/ | |
class BPGEN_WPBE_Compat { | |
/** | |
* Initialises this object. | |
* | |
* @return object | |
*/ | |
public function __construct() { | |
// cause BP Group Email Notifications digests to be filtered by WP Better Emails | |
add_filter( 'wp_mail_content_type', array( $this, 'set_content_type' ), 99 ); | |
add_filter( 'ass_digest_message_html', array( $this, 'strip_digest_message_html' ), 20, 2 ); | |
// --< | |
return $this; | |
} | |
/** | |
* Set content type to plain text so that WP Better Emails sends as HTML. | |
* | |
* @param string $content_type The existing content type | |
* @return string $content_type The modified content type | |
*/ | |
public function set_content_type( $content_type ) { | |
// is is HTML? | |
if ( $content_type = 'text/html' ) { | |
$content_type = 'text/plain'; | |
} | |
// --< | |
return $content_type; | |
} | |
/** | |
* Unwrap the HTML message that BuddyPress Group Email Subscription wraps in | |
* <html><body> tags. Also strip newline characters so it displays correctly. | |
* | |
* @param string $wrapped The existing wrapped content | |
* @param string $message The existing un-wrapped content | |
* @return string $message The un-wrapped content | |
*/ | |
public function strip_digest_message_html( $wrapped, $message ) { | |
// strip newlines | |
return str_replace( "\n", '', $message ); | |
} | |
} // class ends | |
// init plugin | |
global $bpgen_wpbe_compat; | |
$bpgen_wpbe_compat = new BPGEN_WPBE_Compat; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment