Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Add User Roles to Email Notification */
- add_filter('outofthebox_notification', 'user_role_notification', 10, 1);
- function user_role_notification($notification) {
- $additional_recipients = array();
- foreach ($notification['recipients'] as $key => $recipient) {
- /* Skip placeholders and emailaddresses */
- if (strpos($recipient, '%') !== false || strpos($recipient, '@') !== false) {
- continue;
- }
- /* Check if recipient is an User Role */
- if (is_a(get_role($recipient), 'WP_Role')) {
- $users = get_users('role=' . $recipient);
- /* Add all emailaddresses for User Role */
- foreach ($users as $user) {
- $additional_recipients[] = $user->user_email;
- }
- unset($notification['recipients'][$key]);
- }
- }
- /* Make sure that there aren't any duplicates in the list of recipients */
- $notification['recipients'] = array_merge($notification['recipients'], $additional_recipients);
- $notification['recipients'] = array_unique(array_map('trim', $notification['recipients']));
- return $notification;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement