the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
// Exit if accessed directly.
defined('ABSPATH') || exit;
$settings = bp_email_get_appearance_settings();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta charset="<?php 
echo esc_attr(get_bloginfo('charset'));
?>
">
	<meta name="viewport" content="width=device-width"> <!-- Forcing initial-scale shouldn't be necessary -->
	<meta http-equiv="X-UA-Compatible" content="IE=edge"> <!-- Use the latest (edge) version of IE rendering engine -->

	<!-- CSS Reset -->
	<style type="text/css">
		/* What it does: Remove spaces around the email design added by some email clients. */
		/* Beware: It can remove the padding / margin and add a background color to the compose a reply window. */
/**
 * Get Customizer settings for emails.
 *
 * @since 2.5.0
 *
 * @return array
 */
function bp_email_get_customizer_settings()
{
    $defaults = bp_email_get_appearance_settings();
    /**
     * Filter Customizer settings for emails.
     *
     * @since 2.5.0
     *
     * @param array $settings Email Customizer settings to add.
     */
    return apply_filters('bp_email_get_customizer_settings', array('bp_email_options[email_bg]' => array('capability' => 'bp_moderate', 'default' => $defaults['email_bg'], 'sanitize_callback' => 'sanitize_hex_color', 'transport' => 'postMessage', 'type' => 'option'), 'bp_email_options[header_bg]' => array('capability' => 'bp_moderate', 'default' => $defaults['header_bg'], 'sanitize_callback' => 'sanitize_hex_color', 'transport' => 'postMessage', 'type' => 'option'), 'bp_email_options[header_text_size]' => array('capability' => 'bp_moderate', 'default' => $defaults['header_text_size'], 'sanitize_callback' => 'intval', 'transport' => 'postMessage', 'type' => 'option'), 'bp_email_options[header_text_color]' => array('capability' => 'bp_moderate', 'default' => $defaults['header_text_color'], 'sanitize_callback' => 'sanitize_hex_color', 'transport' => 'postMessage', 'type' => 'option'), 'bp_email_options[highlight_color]' => array('capability' => 'bp_moderate', 'default' => $defaults['highlight_color'], 'sanitize_callback' => 'sanitize_hex_color', 'transport' => 'postMessage', 'type' => 'option'), 'bp_email_options[body_bg]' => array('capability' => 'bp_moderate', 'default' => $defaults['body_bg'], 'sanitize_callback' => 'sanitize_hex_color', 'transport' => 'postMessage', 'type' => 'option'), 'bp_email_options[body_text_size]' => array('capability' => 'bp_moderate', 'default' => $defaults['body_text_size'], 'sanitize_callback' => 'intval', 'transport' => 'postMessage', 'type' => 'option'), 'bp_email_options[body_text_color]' => array('capability' => 'bp_moderate', 'default' => $defaults['body_text_color'], 'sanitize_callback' => 'sanitize_hex_color', 'transport' => 'postMessage', 'type' => 'option'), 'bp_email_options[footer_text]' => array('capability' => 'bp_moderate', 'default' => $defaults['footer_text'], 'sanitize_callback' => 'wp_filter_post_kses', 'transport' => 'postMessage', 'type' => 'option'), 'bp_email_options[footer_bg]' => array('capability' => 'bp_moderate', 'default' => $defaults['footer_bg'], 'sanitize_callback' => 'sanitize_hex_color', 'transport' => 'postMessage', 'type' => 'option'), 'bp_email_options[footer_text_size]' => array('capability' => 'bp_moderate', 'default' => $defaults['footer_text_size'], 'sanitize_callback' => 'intval', 'transport' => 'postMessage', 'type' => 'option'), 'bp_email_options[footer_text_color]' => array('capability' => 'bp_moderate', 'default' => $defaults['footer_text_color'], 'sanitize_callback' => 'sanitize_hex_color', 'transport' => 'postMessage', 'type' => 'option')));
}
/**
 * Find and render the template for Email posts (the Customizer and admin previews).
 *
 * Misuses the `template_include` filter which expects a string, but as we need to replace
 * the `{{{content}}}` token with the post's content, we use object buffering to load the
 * template, replace the token, and render it.
 *
 * The function returns an empty string to prevent WordPress rendering another template.
 *
 * @since 2.5.0
 *
 * @param string $template Path to template (probably single.php).
 * @return string
 */
function bp_core_render_email_template($template)
{
    if (get_post_type() !== bp_get_email_post_type() || !is_single()) {
        return $template;
    }
    /**
     * Filter template used to display Email posts.
     *
     * @since 2.5.0
     *
     * @param string $template Path to current template (probably single.php).
     */
    $email_template = apply_filters('bp_core_render_email_template', bp_locate_template(bp_email_get_template(get_queried_object()), false), $template);
    if (!$email_template) {
        return $template;
    }
    ob_start();
    include $email_template;
    $template = ob_get_contents();
    ob_end_clean();
    // Make sure we add a <title> tag so WP Customizer picks it up.
    $template = str_replace('<head>', '<head><title>' . esc_html_x('BuddyPress Emails', 'screen heading', 'buddypress') . '</title>', $template);
    echo str_replace('{{{content}}}', nl2br(get_post()->post_content), $template);
    /*
     * Link colours are applied directly in the email template before sending, so we
     * need to add an extra style here to set the colour for the Customizer or preview.
     */
    $settings = bp_email_get_appearance_settings();
    printf('<style>a { color: %s; }</style>', esc_attr($settings['highlight_color']));
    return '';
}
Пример #4
0
 public function test_emails_should_have_correct_link_color()
 {
     $appearance = bp_email_get_appearance_settings();
     $content = '<a href="http://example.com">example</a>';
     $link_color = 'style="color: ' . esc_attr($appearance['highlight_color']) . ';';
     $result = bp_email_add_link_color_to_template($content, 'template', 'add-content');
     $this->assertContains($link_color, $result);
     $content = '<a href="http://example.com" style="display: block">example</a>';
     $link_color .= 'display: block';
     $result = bp_email_add_link_color_to_template($content, 'template', 'add-content');
     $this->assertContains($link_color, $result);
 }