-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunction.php
45 lines (34 loc) · 1.4 KB
/
function.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
/* ajout du formulaire de contact */
add_action('wp_ajax_contact', '_ajax_contact');
add_action('wp_ajax_nopriv_contact', '_ajax_contact');
function _ajax_contact()
{
/* on verifie le nonce de sécurité */
check_ajax_referer('ajax_contact_nonce', 'security');
/* protection des variables */
$subject = wp_strip_all_tags($_POST['subject']); // sujet du message
$name = wp_strip_all_tags($_POST['name']); // nom de l'expediteur
$sender = sanitize_email($_POST['email']); // email propre de l'expediteur
$message = nl2br(stripslashes(wp_kses($_POST['message'], $GLOBALS['allowedtags']))); //on transforme les saut de ligne ,puis suppression des antislash ajouté par wordpress, puis suppression d'eventuel php
/* gestion des headers */
$headers = [];
$headers[] = 'FROM :'.$name.' <'.$sender.'>'."\r\n";
/* gestion du message */
ob_start(); // mise en tampon
include TEMPLATEPATH.'/template/contact.php';
$mail = ob_get_contents();
ob_end_clean();
/* Envoi du mail */
// support d'un contenu Html dans l'email
add_filter('wp_mail_content_type', create_function('', 'return "text/html";'));
/* pour voir le html dans un mail */
$adminMail = get_option('admin_email');
if (wp_mail($adminMail, $subject, $mail, $headers)) {
// le mail est envoyer
wp_send_json('success');
} else {
// le mail n'as pas été envoyer
wp_send_json('error');
}
}