Created
May 18, 2020 13:30
-
-
Save champsupertramp/5f9a1bc051d2e1f87fb2639e70ef61cb to your computer and use it in GitHub Desktop.
Ultimate Member Groups - Notify a user when someone created a group
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Author: Champ | |
* Site: www.champ.ninja | |
*/ | |
/** | |
* 1. Set the recipient email with the variable $member_address | |
* 2. Ensure that this new email template is turned on in WP Admin > Ultimate Member > Settings > Emails | |
*/ | |
function um_custom_groups_email_notifications( $notifications ){ | |
$notifications['groups_new_group_created'] = array( | |
'key' => 'groups_new_group_created', | |
'title' => __( 'Groups - New group created','um-groups' ), | |
'subject' => '{site_name} - Someone created a new group "{group_name}"', | |
'body' => 'Hi,<br /><br />'. | |
'Someone has created a new group "{group_name}" on your site.<br /><br />'. | |
'To view group, please click the following link: {group_url}', | |
'description' => __('Whether to send the user an email when someone created a group.','ultimate-member'), | |
'recipient' => 'user', | |
'default_active' => true | |
); | |
return $notifications; | |
} | |
add_filter( 'um_email_notifications', 'um_custom_groups_email_notifications', 10, 1 ); | |
function um_custom_groups_notify_admin( $post_id, $postObject, $is_update ){ | |
if( $is_update ) return; // don't send email when someone updates a group | |
$member_address = "[email protected]"; // Recipient | |
$group_name = get_the_title( $post_id ); | |
$group_url = get_the_permalink( $post_id ); | |
UM()->mail()->send( $member_address, 'groups_new_group_created', array( | |
'plain_text' => 1, | |
'tags' => array( | |
'{group_name}', | |
'{group_url}', | |
), | |
'tags_replace' => array( | |
$group_name, | |
$group_url, | |
) | |
) ); | |
} | |
add_action( 'save_post_um_groups','um_custom_groups_notify_admin', 10, 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For Multiple recipients: