events actions and email for profs are now well supported, without repeatitions
This commit is contained in:
@@ -21,8 +21,8 @@ function replace_words($matches, $user_id = null) {
|
||||
$current_user = get_user_by('id', $user_id);
|
||||
}
|
||||
else if (is_user_logged_in()) {
|
||||
$current_user = wp_get_current_user();
|
||||
$user_id = get_current_user_id();
|
||||
$current_user = wp_get_current_user();
|
||||
}
|
||||
else {
|
||||
return "";
|
||||
@@ -90,16 +90,24 @@ function filter_email_wp($args) {
|
||||
// pattern : anything surrounded by '$$', ex : $$value$$
|
||||
$pattern = '/\$\$(.*?)\$\$/';
|
||||
|
||||
$user_id = \CUSTER\find_user_id_from_headers($args);
|
||||
|
||||
$old_to = $args['to'];
|
||||
$new_to = preg_replace_callback($pattern, __NAMESPACE__.'\replace_words', $old_to);
|
||||
$new_to = preg_replace_callback($pattern, function($matches) use ($user_id) {
|
||||
return \CUSTER\replace_words($matches, $user_id);
|
||||
}, $old_to);
|
||||
$args['to'] = $new_to;
|
||||
|
||||
$old_subject = $args['subject'];
|
||||
$new_subject = preg_replace_callback($pattern, __NAMESPACE__.'\replace_words', $old_subject);
|
||||
$new_subject = preg_replace_callback($pattern, function($matches) use ($user_id) {
|
||||
return \CUSTER\replace_words($matches, $user_id);
|
||||
}, $old_subject);
|
||||
$args['subject'] = $new_subject;
|
||||
|
||||
$old_message = $args['message'];
|
||||
$new_message = preg_replace_callback($pattern, __NAMESPACE__.'\replace_words', $old_message);
|
||||
$new_message = preg_replace_callback($pattern, function($matches) use ($user_id) {
|
||||
return \CUSTER\replace_words($matches, $user_id);
|
||||
}, $old_message);
|
||||
$args['message'] = $new_message;
|
||||
|
||||
return $args;
|
||||
@@ -127,4 +135,32 @@ add_filter('wp_new_user_notification_email', __NAMESPACE__.'\filter_regitration_
|
||||
|
||||
|
||||
|
||||
|
||||
function find_user_id_from_headers(&$args) {
|
||||
if (empty($args)) {
|
||||
return null;
|
||||
}
|
||||
if (!isset($args['headers'])) {
|
||||
return null;
|
||||
}
|
||||
$user_id = null;
|
||||
$headers = $args['headers'];
|
||||
foreach ($headers as $key => $header) {
|
||||
$explode_header = explode(':', $header);
|
||||
$explode_header = array_map('trim', $explode_header);
|
||||
if ($explode_header[0] === 'User_id') {
|
||||
$user_id = $explode_header[1];
|
||||
unset($headers[$key]);
|
||||
$headers = array_values($headers);
|
||||
}
|
||||
}
|
||||
$args['headers'] = $headers;
|
||||
return $user_id;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user