Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 49 additions & 28 deletions admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,20 +121,20 @@ function email_add_menu_page_callback() {
$send_options = get_option( 'email_settings' );

// variables for the field and option names
$email_action = 'email_action';
$email_type = 'email_type';
$email_from = 'email_from';
$email_from_name= 'email_from_name';
$email_to = 'email_to';
$email_to_role = 'email_to_role';
$email_cc = 'email_cc';
$email_cc_role = 'email_cc_role';
$email_bcc = 'email_bcc';
$email_bcc_role = 'email_bcc_role';
$email_subject = 'email_subject';
$email_message = 'email_message';
$email_hidden = 'email_hidden';

$email_action = 'email_action';
$email_type = 'email_type';
$email_from = 'email_from';
$email_from_name = 'email_from_name';
$email_to = 'email_to';
$email_to_role = 'email_to_role';
$email_cc = 'email_cc';
$email_cc_role = 'email_cc_role';
$email_bcc = 'email_bcc';
$email_bcc_role = 'email_bcc_role';
$email_subject = 'email_subject';
$email_message = 'email_message';
$email_hidden = 'email_hidden';
$email_html_formatted = 'email_html_formatted';
?>

<div class="wrap">
Expand Down Expand Up @@ -235,6 +235,13 @@ function email_add_menu_page_callback() {
</td>
</tr>

<tr valign="top">
<th scope="row"><label for="<?php echo $email_html_formatted; ?>">HTML Formatted Email?</label></th>
<td>
<input type="checkbox" name="<?php echo $email_html_formatted; ?>" value="false">
</td>
</tr>

<tr valign="top">
<th scope="row"></th>
<td>
Expand Down Expand Up @@ -327,6 +334,12 @@ function email_add_menu_page_callback() {
<dt><code>[post_modified_date]</code></dt>
<dd>The date the post was modified. This is the timestamp of current action.</dd>

<dt><code>[post_title]</code></dt>
<dd>The title of the post.</dd>

<dt><code>[post_content]</code></dt>
<dd>The content of the post. This will likely be in HTML format, so make sure to set your format accordingly.</dd>

</dl>

</div>
Expand All @@ -338,19 +351,20 @@ function email_add_menu_page_callback() {
function email_insert_post() {

// variables for the field and option names
$email_action = (isset($_POST['email_action']) ? $_POST['email_action'] : '');
$email_type = (isset($_POST['email_type']) ? $_POST['email_type'] : '');
$email_from = (isset($_POST['email_from']) ? $_POST['email_from'] : '');
$email_from_name = (isset($_POST['email_from_name']) ? $_POST['email_from_name'] : '');
$email_to = (isset($_POST['email_to']) ? $_POST['email_to'] : '');
$email_to_role = (isset($_POST['email_to_role']) ? $_POST['email_to_role'] : '');
$email_cc = (isset($_POST['email_cc']) ? $_POST['email_cc'] : '');
$email_cc_role = (isset($_POST['email_cc_role']) ? $_POST['email_cc_role'] : '');
$email_bcc = (isset($_POST['email_bcc']) ? $_POST['email_bcc'] : '');
$email_bcc_role = (isset($_POST['email_bcc_role']) ? $_POST['email_bcc_role'] : '');
$email_subject = (isset($_POST['email_subject']) ? $_POST['email_subject'] : '');
$email_message = (isset($_POST['email_message']) ? $_POST['email_message'] : '');
$email_hidden = (isset($_POST['email_hidden']) ? $_POST['email_hidden'] : '');
$email_action = (isset($_POST['email_action']) ? $_POST['email_action'] : '');
$email_type = (isset($_POST['email_type']) ? $_POST['email_type'] : '');
$email_from = (isset($_POST['email_from']) ? $_POST['email_from'] : '');
$email_from_name = (isset($_POST['email_from_name']) ? $_POST['email_from_name'] : '');
$email_to = (isset($_POST['email_to']) ? $_POST['email_to'] : '');
$email_to_role = (isset($_POST['email_to_role']) ? $_POST['email_to_role'] : '');
$email_cc = (isset($_POST['email_cc']) ? $_POST['email_cc'] : '');
$email_cc_role = (isset($_POST['email_cc_role']) ? $_POST['email_cc_role'] : '');
$email_bcc = (isset($_POST['email_bcc']) ? $_POST['email_bcc'] : '');
$email_bcc_role = (isset($_POST['email_bcc_role']) ? $_POST['email_bcc_role'] : '');
$email_subject = (isset($_POST['email_subject']) ? $_POST['email_subject'] : '');
$email_message = (isset($_POST['email_message']) ? $_POST['email_message'] : '');
$email_hidden = (isset($_POST['email_hidden']) ? $_POST['email_hidden'] : '');
$email_html_formatted = (isset($_POST['email_html_formatted']) ? $_POST['email_html_formatted'] : '');

if( isset($email_hidden) && ( $email_hidden == 'Y' ) ) {

Expand Down Expand Up @@ -432,6 +446,10 @@ function email_insert_post() {
array(
'key' => 'email_message',
'value' => $email_message
),
array(
'key' => 'email_html_formatted',
'value' => $email_html_formatted
)
)
);
Expand Down Expand Up @@ -511,14 +529,17 @@ function email_insert_post() {
$success[] = $email_bcc;
}
if ( !empty( $email_bcc_role ) ) {
update_post_meta( $post_id, 'email_bcc_role',$email_bcc_role );
update_post_meta( $post_id, 'email_bcc_role', $email_bcc_role );
$success[] = $email_bcc_role;
}
if ( !empty( $email_subject ) ) {
update_post_meta( $post_id, 'email_subject', $email_subject );
$success[] = $email_subject;
}

update_post_meta( $post_id, 'email_html_formatted', $email_html_formatted );
$success[] = $email_html_formatted;

$success[] = 'Edit <a href="'. get_edit_post_link( $post_id ) .'">'. get_the_title( $post_id ) .'</a>';

if( !empty( $post_id ) ) {
Expand Down
2 changes: 2 additions & 0 deletions parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function email_parser( $post_id, $email_id, $old_status, $new_status, $string =
'[post_modified_date]',
'[post_modified_time]',
'[post_title]',
'[post_content]',
'[permalink]',
'[old_status]',
'[new_status]',
Expand Down Expand Up @@ -65,6 +66,7 @@ function email_parser( $post_id, $email_id, $old_status, $new_status, $string =
get_the_modified_date( '', $post_id ),
get_the_modified_time( '', $post_id ),
get_the_title( $post_id ),
get_post_field('post_content', $post_id ),
get_permalink( $post_id ),
$old_status,
$new_status,
Expand Down
39 changes: 26 additions & 13 deletions router.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,28 @@ function email_action_router( $new_status, $old_status, $post ) {
}
}

function set_html_content_type() {
return 'text/html';
}

function email_action( $action, $post_id, $email_id, $old_status, $new_status ) {

$post = get_post( $post_id );

$email_action = get_post_meta( $email_id, 'email_action', true );
$email_type = get_post_meta( $email_id, 'email_type', true );
$email_from = get_post_meta( $email_id, 'email_from', true );
$email_from_name = get_post_meta( $email_id, 'email_from_name', true );
$email_to = get_post_meta( $email_id, 'email_to', true );
$email_to_role = get_post_meta( $email_id, 'email_to_role', true );
$email_cc = get_post_meta( $email_id, 'email_cc', true );
$email_cc_role = get_post_meta( $email_id, 'email_cc_role', true );
$email_bcc = get_post_meta( $email_id, 'email_bcc', true );
$email_bcc_role = get_post_meta( $email_id, 'email_bcc_role', true );
$email_subject = get_post_meta( $email_id, 'email_subject', true );
$email_message = get_post_meta( $email_id, 'email_message', true );
$email_hidden = get_post_meta( $email_id, 'email_hidden', true );
$email_action = get_post_meta( $email_id, 'email_action', true );
$email_type = get_post_meta( $email_id, 'email_type', true );
$email_from = get_post_meta( $email_id, 'email_from', true );
$email_from_name = get_post_meta( $email_id, 'email_from_name', true );
$email_to = get_post_meta( $email_id, 'email_to', true );
$email_to_role = get_post_meta( $email_id, 'email_to_role', true );
$email_cc = get_post_meta( $email_id, 'email_cc', true );
$email_cc_role = get_post_meta( $email_id, 'email_cc_role', true );
$email_bcc = get_post_meta( $email_id, 'email_bcc', true );
$email_bcc_role = get_post_meta( $email_id, 'email_bcc_role', true );
$email_subject = get_post_meta( $email_id, 'email_subject', true );
$email_message = get_post_meta( $email_id, 'email_message', true );
$email_hidden = get_post_meta( $email_id, 'email_hidden', true );
$email_html_formatted = get_post_meta( $email_id, 'email_html_formatted', true ) === 'true'? true: false;

// Build the comma separated list of email address for the TO field
$users_to_list = '';
Expand Down Expand Up @@ -104,7 +109,15 @@ function email_action( $action, $post_id, $email_id, $old_status, $new_status )
$parsed_message = email_parser( $post_id, $email_id, $old_status, $new_status );
$parsed_subject = email_parser( $post_id, $email_id, $old_status, $new_status, $email_subject );

if ( $email_html_formatted )
add_filter( 'wp_mail_content_type', 'set_html_content_type' );

$mail = wp_mail( $users_to_list, $parsed_subject, $parsed_message, $headers );


if ( $email_html_formatted )
// Reset content-type to avoid conflicts -- http://core.trac.wordpress.org/ticket/23578
remove_filter( 'wp_mail_content_type', 'set_html_content_type' );

// Log successful email
if( $mail ) {
Expand Down