Voici une fonction permettant d’envoyer un e-mail à chaque nouvel article publié:
function set_contenttype($content_type){
return 'text/html';
}
function email_members($post_ID) {
$notifyTo = 'mail@example.org';//comma separated
$optionName = "email_members_notifications";
$var = get_option($optionName , null );
$emailMembersNotifications= array();
if($var != null){
$emailMembersNotifications = explode(';',$var);
}
if(!in_array($post_ID,$emailMembersNotifications)){
add_filter('wp_mail_content_type','set_contenttype');
$post = get_post($post_ID);
$message = '<html lang="fr">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body>
Bonjour,<br/>
Un nouvel article a été publié sur le site <a href="'.get_bloginfo('url').'">'.get_bloginfo('url').'</a>.<br/>
Pour le consulter, merci de cliquer sur le lien suivant:<br/>
<a href="'.$post->guid.'">'.get_the_title($post_ID).'</a>
</body>
</html>';
if(wp_mail(
$notifyTo,
'[MON-BLOG] Nouvel article: '.html_entity_decode(get_the_title($post_ID), ENT_COMPAT, 'UTF-8'),
$message)){
$emailMembersNotifications[] = $post_ID;
}
if(!empty($emailMembersNotifications)){
if(!get_option($optionName)){
add_option( $optionName, implode(';',$emailMembersNotifications) );
} else {
update_option( $optionName, implode(';',$emailMembersNotifications) );
}
}
}
return $post_ID;
}
add_action('publish_post', 'email_members');
Cette fonction est à placer dans le fichier functions.php de votre thème (wp-content/themes/[VOTRE-THEME]/functions.php)
Ping : Configurer et utiliser EGit, une extension Git pour Eclipse | www.php-geek.fr