Skip to content

Commit

Permalink
Merge branch 'release/1.2.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Damian Logghe committed Dec 21, 2017
2 parents f39a571 + acafcf0 commit 85f8f2f
Show file tree
Hide file tree
Showing 11 changed files with 129 additions and 274 deletions.
29 changes: 26 additions & 3 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Contributors: timersys
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=K4T6L69EV9G2Q
Tags: email templates, email template, html email, email template, template, better emails, wp better emails, wp email templates, html emails, wpmandrill, postman, wp smtp, woocommerce, easy digital downloads
Requires at least: 4.0
Tested up to: 4.5
Stable tag: 1.1.4
Tested up to: 4.9.1
Stable tag: 1.2.1
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand All @@ -15,7 +15,7 @@ Send beautiful emails with the WordPress Email Templates plugin. Choose your tem

Email Template plugin uses Customizer to make it easier. Preview your changes or send a test email with just a few clicks. **Requires WordPress 4.0.0**

Compatible with : [wpMandrill](https://wordpress.org/plugins/wpmandrill/), [Postman SMTP Mailer](https://wordpress.org/support/plugin/postman-smtp), [WP SMTP](https://wordpress.org/plugins/wp-smtp/), [Easy WP SMTP](https://wordpress.org/plugins/easy-wp-smtp/), [Easy SMTP Mail](https://wordpress.org/plugins/webriti-smtp-mail/)
Compatible with : [wpMandrill](https://wordpress.org/plugins/wpmandrill/), [Post SMTP](https://wordpress.org/plugins/post-smtp/), [WP SMTP](https://wordpress.org/plugins/wp-smtp/), [Easy WP SMTP](https://wordpress.org/plugins/easy-wp-smtp/), [Easy SMTP Mail](https://wordpress.org/plugins/webriti-smtp-mail/), [Mailgun](https://wordpress.org/plugins/mailgun/), [Sengrid](https://wordpress.org/plugins/sendgrid-email-delivery-simplified/)

= Help with translations =

Expand All @@ -29,6 +29,8 @@ Send your translations to [Transifex](https://www.transifex.com/projects/p/wp-em
* Portuguese
* Dutch
* Persian
* Russian
* German

= Collaborate in Github = - [https://github.com/timersys/wordpress-email-templates](https://github.com/timersys/wordpress-email-templates)

Expand All @@ -42,6 +44,16 @@ Thanks to @eliorivero for sharing some customizer tips for plugins :)
2. Activate the plugin through the 'Plugins' menu in WordPress
3. Click on Appearance -> "Email Templates" to start editing

== Frequently Asked Questions ==

= How to add a custom template? =

Copy the templates folder into your theme , then in functions.php add the following:

`add_filter(‘mailtpl/customizer_template’, function(){
return get_stylesheet_directory() . “/admin/templates/default.php”;
});`

== Screenshots ==

1. Editing a template
Expand All @@ -50,6 +62,17 @@ Thanks to @eliorivero for sharing some customizer tips for plugins :)

== Changelog ==

= 1.2.1 =
* Added shortcode support in header/footer
* Header text now it's used for alt image when using images
* Fixed bug where image was not responsive on mobile devices

= 1.2 =
* Added custom css support on template section
* Added link color in body section
* Updated templates with changes above
* Mailgun / sengrid integration

= 1.1.4 =

* Added body size to template section
Expand Down
21 changes: 17 additions & 4 deletions admin/js/mailtpl-public.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
$( '#template_container' ).css( 'width', newval + 'px' );
} );
} );
wp.customize( 'mailtpl_opts[custom_css]', function( value ) {
value.bind( function( newval ) {
if( newval.length )
$( '#custom-css' ).html( newval );
} );
} );
wp.customize( 'mailtpl_opts[header_logo]', function( value ) {
value.bind( function( newval ) {
if( newval.length ) {
Expand All @@ -25,8 +31,10 @@
} );
wp.customize( 'mailtpl_opts[header_logo_text]', function( value ) {
value.bind( function( newval ) {
if( newval.length )
if( newval.length && ! $('#logo img').length )
$( '#logo a' ).text( newval );
if( newval.length && $('#logo img').length )
$( '#logo img' ).prop('alt', newval );
} );
} );
wp.customize( 'mailtpl_opts[header_aligment]', function( value ) {
Expand All @@ -43,14 +51,14 @@
} );
wp.customize( 'mailtpl_opts[header_text_size]', function( value ) {
value.bind( function( newval ) {
if( newval.length )
if( newval.length )
$( '#logo' ).css( 'font-size', newval +'px' );
} );
} );
wp.customize( 'mailtpl_opts[header_text_color]', function( value ) {
value.bind( function( newval ) {
if( newval.length )
$( '#logo' ).css( 'color', newval );
$( '#logo a' ).css( 'color', newval );
} );
} );

Expand All @@ -72,7 +80,12 @@
$( '#mailtpl_body' ).css( 'color', newval );
} );
} );

wp.customize( 'mailtpl_opts[body_href_color]', function( value ) {
value.bind( function( newval ) {
if( newval.length )
$( '#template_body a' ).css( 'color', newval );
} );
} );
wp.customize( 'mailtpl_opts[footer_aligment]', function( value ) {
value.bind( function( newval ) {
if( newval.length )
Expand Down
2 changes: 1 addition & 1 deletion admin/templates/partials/footer.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<tr>
<td colspan="2" valign="middle" id="credit" style="<?php echo $credit; ?>">

<?php echo apply_filters( 'mailtpl/templates/footer_text', $settings['footer_text'] ); ?>
<?php echo apply_filters( 'mailtpl/templates/footer_text', do_shortcode($settings['footer_text'] )); ?>
</td>
</tr>
</table>
Expand Down
15 changes: 11 additions & 4 deletions admin/templates/partials/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,18 @@
text-decoration: none;
";
?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo get_bloginfo('charset');?>" />
<title><?php echo get_bloginfo('name'); ?></title>
<style type="text/css">
#template_body a{
color: <?= $settings['body_href_color'];?>;
}
</style>
<style type="text/css" id="custom-css">
<?= $settings['custom_css'];?>
</style>
</head>
<body leftmargin="0" marginwidth="0" topmargin="0" marginheight="0" offset="0">
<div id="body" style="<?php echo $wrapper; ?>">
Expand All @@ -84,11 +91,11 @@
<tr>
<td>
<h1 style="<?php echo $header_content_h1; ?>" id="logo">
<a style="<?php echo $header_content_h1_a;?>" href="<?php echo apply_filters( 'mailtpl/templates/header_logo_url', home_url());?>" title="<?php echo apply_filters( 'mailtpl/templates/header_logo_url_title', get_bloginfo('name') );?>"><?php
<a style="<?php echo $header_content_h1_a;?>" href="<?php echo apply_filters( 'mailtpl/templates/header_logo_url', home_url());?>" title="<?php echo apply_filters( 'mailtpl/templates/header_logo_url_title', !empty($settings['header_logo_text']) ? do_shortcode( $settings['header_logo_text'] ) : get_bloginfo('name') );?>"><?php
if( !empty($settings['header_logo']) ) {
echo '<img src="'.apply_filters( 'mailtpl/templates/header_logo', $settings['header_logo'] ).'" alt="'. apply_filters( 'mailtpl/templates/header_logo_alt', get_bloginfo( 'description' ) ) .'"/>';
echo '<img style="max-width:100%;" src="'.apply_filters( 'mailtpl/templates/header_logo', $settings['header_logo'] ).'" alt="'. apply_filters( 'mailtpl/templates/header_logo_alt', !empty($settings['header_logo_text']) ? do_shortcode( $settings['header_logo_text'] ) : get_bloginfo( 'description' ) ) .'"/>';
} elseif ( !empty( $settings['header_logo_text'] ) ) {
echo $settings['header_logo_text'];
echo do_shortcode($settings['header_logo_text']);
} else {
echo get_bloginfo('name');
} ?>
Expand Down
37 changes: 36 additions & 1 deletion includes/class-mailtpl-customizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,24 @@ private function template_section($wp_customize) {
'description' => __( 'Choose email background color', $this->plugin_name )
)
) );
// custom css
$wp_customize->add_setting( 'mailtpl_opts[custom_css]', array(
'type' => 'option',
'default' => $this->defaults['custom_css'],
'transport' => 'refresh',
'capability' => 'edit_theme_options',
'sanitize_callback' => 'wp_filter_nohtml_kses',
'sanitize_js_callback' => 'wp_filter_nohtml_kses',
) );
$wp_customize->add_control( new WP_Customize_Control( $wp_customize,
'mailtpl_custom_css', array(
'label' => __( 'Custom css', $this->plugin_name ),
'type' => 'textarea',
'section' => 'section_mailtpl_template',
'settings' => 'mailtpl_opts[custom_css]',
'description' => __('Add custom css. Be aware that this may not work on all email clients.', $this->plugin_name )
)
) );
do_action('mailtpl/sections/template/after_content', $wp_customize);
}

Expand Down Expand Up @@ -332,7 +350,7 @@ private function header_section( $wp_customize ) {
'type' => 'textarea',
'section' => 'section_mailtpl_header',
'settings' => 'mailtpl_opts[header_logo_text]',
'description' => __( 'Add text to your mail header', $this->plugin_name )
'description' => __( 'Add text to your mail header. Used for alt text when Image it\'s used', $this->plugin_name )
)
) );
// header alignment
Expand Down Expand Up @@ -477,6 +495,23 @@ private function body_section( $wp_customize ) {
'description' => __( 'Choose body text color', $this->plugin_name )
)
) );
// Links color
$wp_customize->add_setting( 'mailtpl_opts[body_href_color]', array(
'type' => 'option',
'default' => $this->defaults['body_href_color'],
'transport' => 'postMessage',
'capability' => 'edit_theme_options',
'sanitize_callback' => 'sanitize_hex_color',
'sanitize_js_callback' => '',
) );
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize,
'mailtpl_body_href_color', array(
'label' => __( 'Links Color', $this->plugin_name ),
'section' => 'section_mailtpl_body',
'settings' => 'mailtpl_opts[body_href_color]',
'description' => __( 'Choose links color', $this->plugin_name )
)
) );
do_action('mailtpl/sections/body/after_content', $wp_customize);
}

Expand Down
34 changes: 26 additions & 8 deletions includes/class-mailtpl-mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,34 @@ function send_email( &$phpmailer ) {
do_action( 'mailtpl/send_email', $phpmailer, $this );
$message = $this->add_template( apply_filters( 'mailtpl/email_content', $phpmailer->Body ) );
$phpmailer->AltBody = $this->replace_placeholders( strip_tags($phpmailer->Body) );
$phpmailer->Body = $this->replace_placeholders( $message );
$phpmailer->Body = $this->replace_placeholders( $message, $phpmailer );

}

/**
* Mandrill Compatibility
* Generic Compatibility functions used for Mandrill,Mailgun, etc
* @param $message Array
*
* @return Array
*/
public function send_email_mandrill( $message ) {
do_action( 'mailtpl/send_email_mandrill', $message, $this );
public function send_email_generic( $message ) {
do_action( 'mailtpl/send_email_generic', $message, $this );
$temp_message = $this->add_template( apply_filters( 'mailtpl/email_content', $message['html'] ) );
$message['html'] = $this->replace_placeholders( $temp_message );
$message['html'] = $this->replace_placeholders( $temp_message, $message );
return $message;
}

/**
* Generic Compatibility functions used for Mandrill,Mailgun, etc
* @param $message Array
*
* @return Array
*/
public function send_email_sendgrid( $message ) {
do_action( 'mailtpl/send_email_sendgrid', $message, $this );
$temp_message = $this->add_template( apply_filters( 'mailtpl/email_content', $message ) );
$message = $this->replace_placeholders( $temp_message, $message );
error_log("debug-log:".print_r($message,1));
return $message;
}

Expand All @@ -100,7 +114,7 @@ public function send_email_postman( $args ) {
return $args;
do_action( 'mailtpl/send_email_postman', $args, $this );
$temp_message = $this->add_template( apply_filters( 'mailtpl/email_content', $args['message'] ) );
$args['message'] = $this->replace_placeholders( $temp_message );
$args['message'] = $this->replace_placeholders( $temp_message, $args );
return $args;
}

Expand Down Expand Up @@ -142,11 +156,15 @@ private function add_template( $email ) {

/**
* Replace placeholders
*
* @param $email string Mail to be send
*
* @param $message array Could be plugin email arguments array or phpmailer instance.
* Passed to the filters in case users needs something
*
* @return string
*/
private function replace_placeholders( $email ) {
private function replace_placeholders( $email, $message = array() ) {

$to_replace = apply_filters( 'emailtpl/placeholders', array(
'%%BLOG_URL%%' => get_option( 'siteurl' ),
Expand All @@ -156,7 +174,7 @@ private function replace_placeholders( $email ) {
'%%ADMIN_EMAIL%%' => get_option( 'admin_email' ),
'%%DATE%%' => date_i18n( get_option( 'date_format' ) ),
'%%TIME%%' => date_i18n( get_option( 'time_format' ) )
));
), $message);

foreach ( $to_replace as $placeholder => $var ) {
$email = str_replace( $placeholder , $var, $email );
Expand Down
18 changes: 10 additions & 8 deletions includes/class-mailtpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,25 +181,25 @@ private function define_hooks() {
$this->loader->add_action( 'edd_email_send_before', $this->admin, 'edd_get_template' );
$this->loader->add_action( 'woocommerce_email', $this->admin, 'woocommerce_integration' );
$this->loader->add_filter( 'woocommerce_email_settings', $this->admin, 'woocommerce_preview_link' );
// only show in customizer if being acceded by our menu link

// only show in customizer if being acceded by our menu link
if( defined( 'DOING_AJAX' ) || ( isset( $_GET['mailtpl_display'] ) && 'true' == $_GET['mailtpl_display'] ) ) {
$this->loader->add_action( 'customize_register', $this->customizer, 'register_customize_sections' );
$this->loader->add_action( 'customize_section_active', $this->customizer, 'remove_other_sections', 10, 2 );
$this->loader->add_action( 'customize_panel_active', $this->customizer, 'remove_other_panels', 10, 2 );
$this->loader->add_action( 'template_include', $this->customizer, 'capture_customizer_page' );
}

$this->loader->add_action( 'phpmailer_init', $this->mailer, 'send_email' );
$this->loader->add_filter( 'mandrill_payload', $this->mailer, 'send_email_mandrill' );

$this->loader->add_action( 'phpmailer_init', $this->mailer, 'send_email', 50 );
$this->loader->add_filter( 'mandrill_payload', $this->mailer, 'send_email_generic' );
$this->loader->add_filter( 'mg_mutate_message_body', $this->mailer, 'send_email_generic' );
$this->loader->add_filter( 'sendgrid_mail_html', $this->mailer, 'send_email_sendgrid' );
$this->loader->add_filter( 'wp_mail', $this->mailer, 'send_email_postman' );

$this->loader->add_action( 'mandrill_payload', $this->mailer, 'send_email_mandrill' );
$this->loader->add_action( 'wp_ajax_mailtpl_send_email', $this->mailer, 'send_test_email' );
$this->loader->add_action( 'wp_mail_content_type', $this->mailer, 'set_content_type', 100 );
$this->loader->add_action( 'wp_mail_from_name', $this->mailer, 'set_from_name' );
$this->loader->add_action( 'wp_mail_from', $this->mailer, 'set_from_email' );
$this->loader->add_action( 'wp_mail_from', $this->mailer, 'set_from_email');

$this->loader->add_filter( 'mailtpl/email_content', $this->mailer, 'clean_retrieve_password' );

Expand All @@ -211,7 +211,7 @@ private function define_hooks() {
$this->loader->add_action( 'customize_controls_enqueue_scripts', $this->customizer, 'enqueue_scripts' );
$this->loader->add_action( 'customize_preview_init', $this->customizer, 'enqueue_template_scripts', 99 );

$this->loader->add_action( 'init', $this->admin, 'remove_all_actions', 99 );
$this->loader->add_action( 'init', $this->admin, 'remove_all_actions', 999 );
}
}

Expand Down Expand Up @@ -289,6 +289,8 @@ public static function defaults() {
'email_body_bg' => '#fafafa',
'body_text_size' => '14',
'body_text_color' => '#888',
'body_href_color' => '#4ca6cf',
'custom_css' => '',
));
}
}
Binary file modified languages/mailtpl-de_DE.mo
Binary file not shown.
File renamed without changes.
Loading

0 comments on commit 85f8f2f

Please sign in to comment.