Created
December 18, 2024 13:23
-
-
Save dwanjuki/b57a979bb265fbfc5df8ba1befee304b to your computer and use it in GitHub Desktop.
Send email to user when removed from a group account via the Manage Group page
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 | |
| /** | |
| * Send email to user when removed from a group account via the Manage Group page | |
| * | |
| * You can add this recipe to your site by creating a custom plugin | |
| * or using the Code Snippets plugin available for free in the WordPress repository. | |
| * Read this companion article for step-by-step directions on either method. | |
| * https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
| */ | |
| function my_pmpro_group_account_removal_notification( $level_id, $user_id, $cancel_level_id ) { | |
| if ( ! empty( $_REQUEST['pmprogroupacct_remove_group_members'] ) ) { | |
| $site_title = get_bloginfo( 'name' ); | |
| $cancel_level = pmpro_getLevel( $cancel_level_id ); | |
| $user = get_user_by( 'id', $user_id ); | |
| $to = $user->user_email; | |
| $subject = 'Group membership on ' . $site_title . ' ended'; | |
| $message = 'Hi ' .$user->display_name . ',<br><br>Your ' . $cancel_level->name . ' group membership has been removed.'; | |
| wp_mail( $to, $subject, $message); | |
| } | |
| } | |
| add_action( 'pmpro_after_change_membership_level', 'my_pmpro_group_account_removal_notification', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment