Skip to content

Instantly share code, notes, and snippets.

@claudiosanches
Forked from vmassuchetto/post_mail.php
Created November 27, 2013 14:43
Show Gist options
  • Save claudiosanches/7676798 to your computer and use it in GitHub Desktop.
Save claudiosanches/7676798 to your computer and use it in GitHub Desktop.
<?php
/**
* Wraps a message $content in a responsive e-mail template.
*
* Reference: http://zurb.com/playground/projects/responsive-email-templates/basic.html
*/
function post_mail_content( $content ) {
ob_start(); ?><html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta content="width=device-width" name="viewport">
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<title><?php echo get_bloginfo( 'name' ) . ' -- ' . __( 'New post' ); ?></title>
<link href="<?php echo get_stylesheet_directory_uri(); ?>/css/email.css" type="text/css" rel="stylesheet">
</head>
<body bgcolor="#FFFFFF">
<table class="body-wrap">
<tbody><tr>
<td></td>
<td bgcolor="#FFFFFF" class="container">
<div class="content">
<table>
<tbody><tr><td>
<?php echo $content; ?>
</td></tr></tbody>
</table>
</div>
</td>
<td></td>
</tr></tbody>
</table></body></html><?php
$html = ob_get_clean();
return $html;
}
add_action( 'new_to_pending', 'grupo_post_mail' );
add_action( 'draft_to_pending', 'grupo_post_mail' );
add_action( 'pending_to_pending', 'grupo_post_mail' );
/**
* Sends a message to site admins when posts are published or pending
* for approval.
*
* If it's in debug mode it will just create the e-mail as a file in
* the temporary directory from the operational system (e.g. `/tmp`).
*/
function post_mail( $post ) {
if ( !in_array( $post->post_type, array( 'post', 'lugar' ) ) )
return false;
global $wpdb;
$to = array();
$users = get_users( array( 'role' => 'administrator' ) );
$author = get_user_by( 'ID', $post->post_author );
foreach( $users as $user ) {
$to[] = $user->display_name . '<' . $user->user_email . '>';
}
$subject = '[' . get_bloginfo( 'name' ) . '] ' . __( 'New post' ) . ' - ' . trim( $post->post_title );
$headers = array(
"From: {$author->display_name} <{$author->user_email}>",
"Bcc: " . implode( ',', $to )
);
ob_start();
?>
<p><?php sprintf( __( 'A new %s was created:' ), '<i>' . $post->post_type . '</i>' ); ?>:</p>
<h3><?php echo edit_post_link( $post->post_title, '', '', $post->ID ); ?></h3>
<p class="callout">
<?php _e( 'Categories' ); ?>: <?php get_the_category( $post->ID ); ?><br/>
<?php _e( 'Tags' ); ?>: <?php get_the_tags( $post->ID ); ?>
</p>
<table width="100%" class="social">
<tbody><tr><td>
<table align="left" class="column"><tbody><tr><td>
<h5 class=""><?php _e( 'Author' ); ?>:</h5>
<p>
<a href="<?php echo admin_url( 'user-edit.php' ); ?>?user_id=<?php echo $user->ID; ?>"><?php echo $user->display_name; ?></a>&nbsp; (<?php echo $user->user_login; ?>)<br/>
<a href="mailto:<?php echo $user->user_email; ?>"><?php echo $user->user_email; ?></a>
</p>
</td></tr></tbody></table>
</td></tr></tbody>
</table>
<?php
$content = ob_get_clean();
$content = post_mail_content( $content );
wp_mail( $to, $subject, $content, $headers );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment